	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function calc_resistor
_calc_resistor:                         ## @calc_resistor
	.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	%r13
	pushq	%r12
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rdi, %r12
	leaq	-44(%rbp), %rsi
	callq	_measure_current
	testl	%eax, %eax
	jne	LBB0_23
## %bb.1:
	cmpl	$0, -44(%rbp)
	js	LBB0_23
## %bb.2:
	movq	_OCV_MODE_ACTIVE@GOTPCREL(%rip), %r14
	movl	(%r14), %esi
	leaq	-44(%rbp), %rdx
	movq	%r12, %rdi
	callq	_measure_vbatt
	movl	%eax, -48(%rbp)
	testl	%eax, %eax
	je	LBB0_3
LBB0_23:
	movq	_EINVAL@GOTPCREL(%rip), %rax
	xorl	%ecx, %ecx
	subl	(%rax), %ecx
LBB0_24:
	movl	%ecx, %eax
	addq	$40, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_3:
	movl	-44(%rbp), %eax
	movq	_VBATT_RESISTOR_MIN@GOTPCREL(%rip), %rcx
	cmpl	(%rcx), %eax
	jl	LBB0_23
## %bb.4:
	movq	_VBATT_RESISTOR_MAX@GOTPCREL(%rip), %rcx
	cmpl	(%rcx), %eax
	jg	LBB0_23
## %bb.5:
	leaq	-64(%rbp), %rdx
	movq	%r12, %rdi
	movl	$500, %esi                      ## imm = 0x1F4
	callq	_set_charger_current
	testq	%rax, %rax
	jne	LBB0_23
## %bb.6:
	movl	$500, %edi                      ## imm = 0x1F4
	callq	_msleep
	movl	$0, -56(%rbp)                   ## 4-byte Folded Spill
	movl	$10, %r15d
	leaq	-44(%rbp), %r13
	movl	$0, -60(%rbp)                   ## 4-byte Folded Spill
	.p2align	4, 0x90
LBB0_7:                                 ## =>This Inner Loop Header: Depth=1
	movl	(%r14), %esi
	movq	%r12, %rdi
	movq	%r13, %rdx
	callq	_measure_vbatt
	movl	%eax, -48(%rbp)
	testl	%eax, %eax
	jne	LBB0_22
## %bb.8:                               ##   in Loop: Header=BB0_7 Depth=1
	movl	-44(%rbp), %r14d
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	_measure_current
	movl	%eax, -48(%rbp)
	testl	%eax, %eax
	jne	LBB0_22
## %bb.9:                               ##   in Loop: Header=BB0_7 Depth=1
	addl	%r14d, -60(%rbp)                ## 4-byte Folded Spill
	movl	-44(%rbp), %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovsl	%eax, %ecx
	addl	%ecx, -56(%rbp)                 ## 4-byte Folded Spill
	decl	%r15d
	movq	_OCV_MODE_ACTIVE@GOTPCREL(%rip), %r14
	jne	LBB0_7
## %bb.10:
	leaq	-48(%rbp), %rdx
	movq	%r12, %rdi
	movl	$100, %esi
	callq	_set_charger_current
	testq	%rax, %rax
	je	LBB0_11
LBB0_22:
	movl	-64(%rbp), %esi
	leaq	-48(%rbp), %rdx
	movq	%r12, %rdi
	callq	_set_charger_current
	jmp	LBB0_23
LBB0_11:
	movq	%r12, -72(%rbp)                 ## 8-byte Spill
	movl	$500, %edi                      ## imm = 0x1F4
	callq	_msleep
	xorl	%ebx, %ebx
	movl	$10, %r15d
	leaq	-44(%rbp), %r13
	movl	$0, -52(%rbp)                   ## 4-byte Folded Spill
	movq	-72(%rbp), %r12                 ## 8-byte Reload
LBB0_12:                                ## =>This Inner Loop Header: Depth=1
	movq	_OCV_MODE_ACTIVE@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	movq	%r12, %rdi
	movq	%r13, %rdx
	callq	_measure_vbatt
	movl	%eax, -48(%rbp)
	testl	%eax, %eax
	jne	LBB0_22
## %bb.13:                              ##   in Loop: Header=BB0_12 Depth=1
	movl	-44(%rbp), %r14d
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	_measure_current
	movl	%eax, -48(%rbp)
	testl	%eax, %eax
	jne	LBB0_22
## %bb.14:                              ##   in Loop: Header=BB0_12 Depth=1
	addl	%r14d, -52(%rbp)                ## 4-byte Folded Spill
	movl	-44(%rbp), %eax
	movl	%eax, %ecx
	negl	%ecx
	cmovsl	%eax, %ecx
	addl	%ecx, %ebx
	decl	%r15d
	jne	LBB0_12
## %bb.15:
	movl	-64(%rbp), %esi
	leaq	-48(%rbp), %rdx
	movq	-72(%rbp), %r12                 ## 8-byte Reload
	movq	%r12, %rdi
	callq	_set_charger_current
	testq	%rax, %rax
	jne	LBB0_22
## %bb.16:
	xorl	%ecx, %ecx
	movl	-60(%rbp), %eax                 ## 4-byte Reload
	subl	-52(%rbp), %eax                 ## 4-byte Folded Reload
	jle	LBB0_24
## %bb.17:
	movl	-56(%rbp), %r13d                ## 4-byte Reload
	subl	%ebx, %r13d
	jle	LBB0_24
## %bb.18:
	testl	%ebx, %ebx
	movq	-72(%rbp), %r9                  ## 8-byte Reload
	jle	LBB0_24
## %bb.19:
	imull	$1000, %eax, %eax               ## imm = 0x3E8
	cltd
	idivl	%r13d
	movl	(%r9), %edx
	movl	%eax, %esi
	subl	%edx, %esi
	setg	%dil
	cmpl	%edx, %esi
	setl	%sil
	testb	%sil, %dil
	cmovnel	%eax, %edx
	movl	%edx, %ebx
	subl	%eax, %ebx
	setg	%r8b
	cmpl	%eax, %ebx
	setl	%bl
	andb	%r8b, %bl
	testb	%sil, %dil
	jne	LBB0_21
## %bb.20:
	testb	%bl, %bl
	je	LBB0_24
LBB0_21:
	testb	%bl, %bl
	cmovnel	%eax, %edx
	movl	%edx, (%r9)
	jmp	LBB0_24
	.cfi_endproc
                                        ## -- End function
	.comm	_OCV_MODE_ACTIVE,4,2            ## @OCV_MODE_ACTIVE
	.comm	_VBATT_RESISTOR_MIN,4,2         ## @VBATT_RESISTOR_MIN
	.comm	_VBATT_RESISTOR_MAX,4,2         ## @VBATT_RESISTOR_MAX
	.comm	_EINVAL,4,2                     ## @EINVAL
	.no_dead_strip	_calc_resistor
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function calc_resistor
_calc_resistor:                         ; @calc_resistor
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #96
	.cfi_def_cfa_offset 96
	stp	x26, x25, [sp, #16]             ; 16-byte Folded Spill
	stp	x24, x23, [sp, #32]             ; 16-byte Folded Spill
	stp	x22, x21, [sp, #48]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #64]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #80]             ; 16-byte Folded Spill
	add	x29, sp, #80
	.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
	.cfi_offset w23, -56
	.cfi_offset w24, -64
	.cfi_offset w25, -72
	.cfi_offset w26, -80
	mov	x19, x0
	add	x1, sp, #8
	bl	_measure_current
	cbnz	w0, LBB0_11
; %bb.1:
	ldr	w8, [sp, #8]
	tbnz	w8, #31, LBB0_11
; %bb.2:
Lloh0:
	adrp	x20, _OCV_MODE_ACTIVE@GOTPAGE
Lloh1:
	ldr	x20, [x20, _OCV_MODE_ACTIVE@GOTPAGEOFF]
	ldr	w1, [x20]
	add	x2, sp, #8
	mov	x0, x19
	bl	_measure_vbatt
	str	w0, [sp, #4]
	cbnz	w0, LBB0_11
; %bb.3:
	ldr	w8, [sp, #8]
Lloh2:
	adrp	x9, _VBATT_RESISTOR_MIN@GOTPAGE
Lloh3:
	ldr	x9, [x9, _VBATT_RESISTOR_MIN@GOTPAGEOFF]
Lloh4:
	ldr	w9, [x9]
Lloh5:
	adrp	x10, _VBATT_RESISTOR_MAX@GOTPAGE
Lloh6:
	ldr	x10, [x10, _VBATT_RESISTOR_MAX@GOTPAGEOFF]
Lloh7:
	ldr	w10, [x10]
	cmp	w8, w9
	ccmp	w8, w10, #0, ge
	b.gt	LBB0_11
; %bb.4:
	add	x2, sp, #12
	mov	x0, x19
	mov	w1, #500
	bl	_set_charger_current
	cbnz	x0, LBB0_11
; %bb.5:
	mov	w0, #500
	bl	_msleep
	mov	w21, #0
	mov	w22, #0
	mov	w23, #10
LBB0_6:                                 ; =>This Inner Loop Header: Depth=1
	ldr	w1, [x20]
	add	x2, sp, #8
	mov	x0, x19
	bl	_measure_vbatt
	str	w0, [sp, #4]
	cbnz	w0, LBB0_10
; %bb.7:                                ;   in Loop: Header=BB0_6 Depth=1
	ldr	w24, [sp, #8]
	add	x1, sp, #8
	mov	x0, x19
	bl	_measure_current
	str	w0, [sp, #4]
	cbnz	w0, LBB0_10
; %bb.8:                                ;   in Loop: Header=BB0_6 Depth=1
	add	w22, w24, w22
	ldr	w8, [sp, #8]
	cmp	w8, #0
	cneg	w8, w8, mi
	add	w21, w8, w21
	subs	w23, w23, #1
	b.ne	LBB0_6
; %bb.9:
	add	x2, sp, #4
	mov	x0, x19
	mov	w1, #100
	bl	_set_charger_current
	cbz	x0, LBB0_13
LBB0_10:
	ldr	w1, [sp, #12]
	add	x2, sp, #4
	mov	x0, x19
	bl	_set_charger_current
LBB0_11:
Lloh8:
	adrp	x8, _EINVAL@GOTPAGE
Lloh9:
	ldr	x8, [x8, _EINVAL@GOTPAGEOFF]
Lloh10:
	ldr	w8, [x8]
	neg	w0, w8
LBB0_12:
	ldp	x29, x30, [sp, #80]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #64]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #48]             ; 16-byte Folded Reload
	ldp	x24, x23, [sp, #32]             ; 16-byte Folded Reload
	ldp	x26, x25, [sp, #16]             ; 16-byte Folded Reload
	add	sp, sp, #96
	ret
LBB0_13:
	mov	w0, #500
	bl	_msleep
	mov	w23, #0
	mov	w24, #0
	mov	w25, #10
LBB0_14:                                ; =>This Inner Loop Header: Depth=1
	ldr	w1, [x20]
	add	x2, sp, #8
	mov	x0, x19
	bl	_measure_vbatt
	str	w0, [sp, #4]
	cbnz	w0, LBB0_10
; %bb.15:                               ;   in Loop: Header=BB0_14 Depth=1
	ldr	w26, [sp, #8]
	add	x1, sp, #8
	mov	x0, x19
	bl	_measure_current
	str	w0, [sp, #4]
	cbnz	w0, LBB0_10
; %bb.16:                               ;   in Loop: Header=BB0_14 Depth=1
	add	w24, w26, w24
	ldr	w8, [sp, #8]
	cmp	w8, #0
	cneg	w8, w8, mi
	add	w23, w8, w23
	subs	w25, w25, #1
	b.ne	LBB0_14
; %bb.17:
	ldr	w1, [sp, #12]
	add	x2, sp, #4
	mov	x0, x19
	bl	_set_charger_current
	cbnz	x0, LBB0_10
; %bb.18:
	mov	w0, #0
	subs	w8, w22, w24
	b.le	LBB0_12
; %bb.19:
	subs	w9, w21, w23
	b.le	LBB0_12
; %bb.20:
	cmp	w23, #1
	b.lt	LBB0_12
; %bb.21:
	mov	w10, #1000
	mul	w8, w8, w10
	sdiv	w8, w8, w9
	ldr	w9, [x19]
	sub	w10, w8, w9
	cmp	w10, #0
	cset	w11, gt
	cmp	w10, w9
	cset	w10, lt
	ands	w11, w11, w10
	csel	w9, w8, w9, ne
	sub	w10, w9, w8
	cmp	w10, #0
	ccmp	w10, w8, #0, gt
	cset	w10, lt
	tbnz	w11, #0, LBB0_24
; %bb.22:
	tbnz	w10, #0, LBB0_24
; %bb.23:
	mov	w0, #0
	b	LBB0_12
LBB0_24:
	mov	w0, #0
	cmp	w10, #0
	csel	w8, w8, w9, ne
	str	w8, [x19]
	b	LBB0_12
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpLdrGotLdr	Lloh5, Lloh6, Lloh7
	.loh AdrpLdrGotLdr	Lloh2, Lloh3, Lloh4
	.loh AdrpLdrGotLdr	Lloh8, Lloh9, Lloh10
	.cfi_endproc
                                        ; -- End function
	.comm	_OCV_MODE_ACTIVE,4,2            ; @OCV_MODE_ACTIVE
	.comm	_VBATT_RESISTOR_MIN,4,2         ; @VBATT_RESISTOR_MIN
	.comm	_VBATT_RESISTOR_MAX,4,2         ; @VBATT_RESISTOR_MAX
	.comm	_EINVAL,4,2                     ; @EINVAL
	.no_dead_strip	_calc_resistor
.subsections_via_symbols
