	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function ingenic_battery_set_scale
_ingenic_battery_set_scale:             ## @ingenic_battery_set_scale
	.cfi_startproc
## %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%rbx
	subq	$24, %rsp
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rdi, %r14
	movl	(%rdi), %edi
	leaq	-28(%rbp), %rsi
	callq	_iio_read_max_channel_raw
	testl	%eax, %eax
	je	LBB0_2
## %bb.1:
	movl	%eax, %ebx
	movl	4(%r14), %edi
	leaq	L_.str(%rip), %rsi
	callq	_dev_err
	jmp	LBB0_15
LBB0_2:
	movl	(%r14), %edi
	movq	_IIO_CHAN_INFO_SCALE@GOTPCREL(%rip), %r15
	movl	(%r15), %r8d
	leaq	-48(%rbp), %rsi
	leaq	-32(%rbp), %rdx
	leaq	-36(%rbp), %rcx
	callq	_iio_read_avail_channel_attribute
	movl	%eax, %ebx
	testl	%eax, %eax
	js	LBB0_3
## %bb.4:
	movq	_IIO_AVAIL_LIST@GOTPCREL(%rip), %rax
	cmpl	(%rax), %ebx
	jne	LBB0_6
## %bb.5:
	movl	-32(%rbp), %eax
	movq	_IIO_VAL_FRACTIONAL_LOG2@GOTPCREL(%rip), %rcx
	cmpl	(%rcx), %eax
	jne	LBB0_6
## %bb.7:
	movl	-36(%rbp), %r8d
	testl	%r8d, %r8d
	jle	LBB0_13
## %bb.8:
	movslq	8(%r14), %rax
	imulq	$274877907, %rax, %r10          ## imm = 0x10624DD3
	movq	%r10, %rax
	shrq	$63, %rax
	sarq	$38, %r10
	addl	%eax, %r10d
	movl	-28(%rbp), %r9d
	movl	$-1, %r11d
	movq	-48(%rbp), %rsi
	xorl	%eax, %eax
                                        ## implicit-def: $edi
	jmp	LBB0_9
	.p2align	4, 0x90
LBB0_11:                                ##   in Loop: Header=BB0_9 Depth=1
	addq	$2, %rax
	cmpq	%r8, %rax
	jae	LBB0_12
LBB0_9:                                 ## =>This Inner Loop Header: Depth=1
	movl	(%rsi,%rax,4), %edx
	imull	%r9d, %edx
	movzbl	4(%rsi,%rax,4), %ecx
	sarl	%cl, %edx
	cmpl	%r10d, %edx
	jl	LBB0_11
## %bb.10:                              ##   in Loop: Header=BB0_9 Depth=1
	testl	%r11d, %r11d
	setns	%cl
	cmpl	%edi, %edx
	setg	%bl
	testb	%bl, %cl
	cmovel	%edx, %edi
	cmovel	%eax, %r11d
	jmp	LBB0_11
LBB0_3:
	movl	4(%r14), %edi
	leaq	L_.str.1(%rip), %rsi
	callq	_dev_err
	jmp	LBB0_15
LBB0_12:
	testl	%r11d, %r11d
	js	LBB0_13
## %bb.14:
	movl	(%r14), %edi
	movq	-48(%rbp), %rax
	movl	%r11d, %ecx
	movl	(%rax,%rcx,4), %esi
	movl	4(%rax,%rcx,4), %edx
	movl	(%r15), %ecx
	callq	_iio_write_channel_attribute
	movl	%eax, %ebx
	jmp	LBB0_15
LBB0_13:
	movl	4(%r14), %edi
	leaq	L_.str.2(%rip), %rsi
	callq	_dev_err
LBB0_6:
	movq	_EINVAL@GOTPCREL(%rip), %rax
	xorl	%ebx, %ebx
	subl	(%rax), %ebx
LBB0_15:
	movl	%ebx, %eax
	addq	$24, %rsp
	popq	%rbx
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"Unable to read max raw channel value\n"

	.comm	_IIO_CHAN_INFO_SCALE,4,2        ## @IIO_CHAN_INFO_SCALE
L_.str.1:                               ## @.str.1
	.asciz	"Unable to read channel avail scale\n"

	.comm	_IIO_AVAIL_LIST,4,2             ## @IIO_AVAIL_LIST
	.comm	_IIO_VAL_FRACTIONAL_LOG2,4,2    ## @IIO_VAL_FRACTIONAL_LOG2
	.comm	_EINVAL,4,2                     ## @EINVAL
L_.str.2:                               ## @.str.2
	.asciz	"Unable to find matching voltage scale\n"

	.no_dead_strip	_ingenic_battery_set_scale
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function ingenic_battery_set_scale
_ingenic_battery_set_scale:             ; @ingenic_battery_set_scale
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #80
	.cfi_def_cfa_offset 80
	stp	x22, x21, [sp, #32]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #48]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #64]             ; 16-byte Folded Spill
	add	x29, sp, #64
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
	.cfi_offset w19, -24
	.cfi_offset w20, -32
	.cfi_offset w21, -40
	.cfi_offset w22, -48
	mov	x19, x0
	ldr	w0, [x0]
	add	x1, sp, #12
	bl	_iio_read_max_channel_raw
	cbz	w0, LBB0_2
; %bb.1:
	mov	x20, x0
	ldr	w0, [x19, #4]
Lloh0:
	adrp	x1, l_.str@PAGE
Lloh1:
	add	x1, x1, l_.str@PAGEOFF
	bl	_dev_err
	b	LBB0_15
LBB0_2:
	ldr	w0, [x19]
Lloh2:
	adrp	x21, _IIO_CHAN_INFO_SCALE@GOTPAGE
Lloh3:
	ldr	x21, [x21, _IIO_CHAN_INFO_SCALE@GOTPAGEOFF]
	ldr	w4, [x21]
	add	x1, sp, #24
	add	x2, sp, #16
	add	x3, sp, #20
	bl	_iio_read_avail_channel_attribute
	mov	x20, x0
	tbnz	w0, #31, LBB0_10
; %bb.3:
Lloh4:
	adrp	x8, _IIO_AVAIL_LIST@GOTPAGE
Lloh5:
	ldr	x8, [x8, _IIO_AVAIL_LIST@GOTPAGEOFF]
Lloh6:
	ldr	w8, [x8]
	cmp	w20, w8
	b.ne	LBB0_14
; %bb.4:
	ldr	w8, [sp, #16]
Lloh7:
	adrp	x9, _IIO_VAL_FRACTIONAL_LOG2@GOTPAGE
Lloh8:
	ldr	x9, [x9, _IIO_VAL_FRACTIONAL_LOG2@GOTPAGEOFF]
Lloh9:
	ldr	w9, [x9]
	cmp	w8, w9
	b.ne	LBB0_14
; %bb.5:
	ldr	w8, [sp, #20]
	cmp	w8, #1
	b.lt	LBB0_13
; %bb.6:
	mov	x9, #0
	ldrsw	x10, [x19, #8]
	mov	w11, #19923
	movk	w11, #4194, lsl #16
	mul	x10, x10, x11
	lsr	x11, x10, #63
	asr	x10, x10, #38
	add	w11, w10, w11
	ldr	w12, [sp, #12]
	mov	w10, #-1
	ldr	x13, [sp, #24]
                                        ; implicit-def: $w14
	b	LBB0_8
LBB0_7:                                 ;   in Loop: Header=BB0_8 Depth=1
	add	x9, x9, #2
	cmp	x9, x8
	b.hs	LBB0_11
LBB0_8:                                 ; =>This Inner Loop Header: Depth=1
	add	x15, x13, x9, lsl #2
	ldp	w16, w15, [x15]
	mul	w16, w16, w12
	asr	w15, w16, w15
	cmp	w15, w11
	b.lt	LBB0_7
; %bb.9:                                ;   in Loop: Header=BB0_8 Depth=1
	cmp	w10, #0
	cset	w16, ge
	cmp	w15, w14
	cset	w17, gt
	tst	w16, w17
	csel	w14, w14, w15, ne
	csel	w10, w10, w9, ne
	b	LBB0_7
LBB0_10:
	ldr	w0, [x19, #4]
Lloh10:
	adrp	x1, l_.str.1@PAGE
Lloh11:
	add	x1, x1, l_.str.1@PAGEOFF
	bl	_dev_err
	b	LBB0_15
LBB0_11:
	tbnz	w10, #31, LBB0_13
; %bb.12:
	ldr	w0, [x19]
	ldr	x8, [sp, #24]
	ldr	w1, [x8, w10, uxtw #2]
	add	w9, w10, #1
	ldr	w2, [x8, w9, uxtw #2]
	ldr	w3, [x21]
	bl	_iio_write_channel_attribute
	mov	x20, x0
	b	LBB0_15
LBB0_13:
	ldr	w0, [x19, #4]
Lloh12:
	adrp	x1, l_.str.2@PAGE
Lloh13:
	add	x1, x1, l_.str.2@PAGEOFF
	bl	_dev_err
LBB0_14:
Lloh14:
	adrp	x8, _EINVAL@GOTPAGE
Lloh15:
	ldr	x8, [x8, _EINVAL@GOTPAGEOFF]
Lloh16:
	ldr	w8, [x8]
	neg	w20, w8
LBB0_15:
	mov	x0, x20
	ldp	x29, x30, [sp, #64]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #48]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #32]             ; 16-byte Folded Reload
	add	sp, sp, #80
	ret
	.loh AdrpAdd	Lloh0, Lloh1
	.loh AdrpLdrGot	Lloh2, Lloh3
	.loh AdrpLdrGotLdr	Lloh4, Lloh5, Lloh6
	.loh AdrpLdrGotLdr	Lloh7, Lloh8, Lloh9
	.loh AdrpAdd	Lloh10, Lloh11
	.loh AdrpAdd	Lloh12, Lloh13
	.loh AdrpLdrGotLdr	Lloh14, Lloh15, Lloh16
	.cfi_endproc
                                        ; -- End function
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"Unable to read max raw channel value\n"

	.comm	_IIO_CHAN_INFO_SCALE,4,2        ; @IIO_CHAN_INFO_SCALE
l_.str.1:                               ; @.str.1
	.asciz	"Unable to read channel avail scale\n"

	.comm	_IIO_AVAIL_LIST,4,2             ; @IIO_AVAIL_LIST
	.comm	_IIO_VAL_FRACTIONAL_LOG2,4,2    ; @IIO_VAL_FRACTIONAL_LOG2
	.comm	_EINVAL,4,2                     ; @EINVAL
l_.str.2:                               ; @.str.2
	.asciz	"Unable to find matching voltage scale\n"

	.no_dead_strip	_ingenic_battery_set_scale
.subsections_via_symbols
