	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function mtk_nfc_set_spare_per_sector
_mtk_nfc_set_spare_per_sector:          ## @mtk_nfc_set_spare_per_sector
	.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
	pushq	%rax
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	_mtd_to_nand
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	_nand_get_controller_data
	movq	(%rax), %r8
	movq	(%r8), %rdi
	movl	(%rbx), %eax
	movl	4(%rbx), %ecx
	cltd
	idivl	(%r15)
	movl	%eax, %esi
	movl	%ecx, %eax
	cltd
	idivl	%esi
	movl	%eax, %ecx
	movl	%eax, (%r14)
	cmpl	$1024, (%r15)                   ## imm = 0x400
	jne	LBB0_2
## %bb.1:
	sarl	%ecx
	movl	%ecx, (%r14)
LBB0_2:
	movq	_MTK_NFC_MIN_SPARE@GOTPCREL(%rip), %rax
	cmpl	(%rax), %ecx
	jge	LBB0_3
## %bb.14:
	movq	_EINVAL@GOTPCREL(%rip), %rcx
	xorl	%eax, %eax
	subl	(%rcx), %eax
	jmp	LBB0_13
LBB0_3:
	movl	8(%r8), %r9d
	xorl	%eax, %eax
	movl	$0, %r8d
	testl	%r9d, %r9d
	jle	LBB0_11
## %bb.4:
	xorl	%esi, %esi
	xorl	%r8d, %r8d
	jmp	LBB0_5
	.p2align	4, 0x90
LBB0_9:                                 ##   in Loop: Header=BB0_5 Depth=1
	incq	%rsi
	cmpq	%rsi, %r9
	je	LBB0_11
LBB0_5:                                 ## =>This Inner Loop Header: Depth=1
	movl	(%rdi,%rsi,4), %ebx
	cmpl	%ebx, %ecx
	jl	LBB0_9
## %bb.6:                               ##   in Loop: Header=BB0_5 Depth=1
	movslq	%r8d, %rdx
	cmpl	(%rdi,%rdx,4), %ebx
	jl	LBB0_9
## %bb.7:                               ##   in Loop: Header=BB0_5 Depth=1
	cmpl	%ebx, %ecx
	je	LBB0_10
## %bb.8:                               ##   in Loop: Header=BB0_5 Depth=1
	movl	%esi, %r8d
	jmp	LBB0_9
LBB0_10:
	movl	%esi, %r8d
LBB0_11:
	movslq	%r8d, %rcx
	movl	(%rdi,%rcx,4), %ecx
	movl	%ecx, (%r14)
	cmpl	$1024, (%r15)                   ## imm = 0x400
	jne	LBB0_13
## %bb.12:
	addl	%ecx, %ecx
	movl	%ecx, (%r14)
LBB0_13:
	addq	$8, %rsp
	popq	%rbx
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.comm	_MTK_NFC_MIN_SPARE,4,2          ## @MTK_NFC_MIN_SPARE
	.comm	_EINVAL,4,2                     ## @EINVAL
	.no_dead_strip	_mtk_nfc_set_spare_per_sector
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function mtk_nfc_set_spare_per_sector
_mtk_nfc_set_spare_per_sector:          ; @mtk_nfc_set_spare_per_sector
	.cfi_startproc
; %bb.0:
	stp	x22, x21, [sp, #-48]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 48
	stp	x20, x19, [sp, #16]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #32]             ; 16-byte Folded Spill
	add	x29, sp, #32
	.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	x21, x1
	mov	x19, x0
	mov	x0, x1
	bl	_mtd_to_nand
	mov	x20, x0
	bl	_nand_get_controller_data
	ldr	x10, [x0]
	ldr	x8, [x10]
	ldr	w9, [x20]
	ldp	w11, w12, [x21]
	sdiv	w9, w11, w9
	sdiv	w9, w12, w9
	str	w9, [x19]
	ldr	w11, [x20]
	cmp	w11, #1024
	b.ne	LBB0_2
; %bb.1:
	asr	w9, w9, #1
	str	w9, [x19]
LBB0_2:
Lloh0:
	adrp	x11, _MTK_NFC_MIN_SPARE@GOTPAGE
Lloh1:
	ldr	x11, [x11, _MTK_NFC_MIN_SPARE@GOTPAGEOFF]
Lloh2:
	ldr	w11, [x11]
	cmp	w9, w11
	b.ge	LBB0_4
; %bb.3:
Lloh3:
	adrp	x8, _EINVAL@GOTPAGE
Lloh4:
	ldr	x8, [x8, _EINVAL@GOTPAGEOFF]
Lloh5:
	ldr	w8, [x8]
	neg	w0, w8
	b	LBB0_16
LBB0_4:
	ldr	w10, [x10, #8]
	cmp	w10, #1
	b.lt	LBB0_11
; %bb.5:
	mov	x11, #0
	mov	w12, #0
	b	LBB0_7
LBB0_6:                                 ;   in Loop: Header=BB0_7 Depth=1
	add	x11, x11, #1
	cmp	x10, x11
	b.eq	LBB0_13
LBB0_7:                                 ; =>This Inner Loop Header: Depth=1
	ldr	w13, [x8, x11, lsl #2]
	cmp	w9, w13
	b.lt	LBB0_6
; %bb.8:                                ;   in Loop: Header=BB0_7 Depth=1
	ldr	w14, [x8, w12, sxtw #2]
	cmp	w13, w14
	b.lt	LBB0_6
; %bb.9:                                ;   in Loop: Header=BB0_7 Depth=1
	cmp	w9, w13
	b.eq	LBB0_12
; %bb.10:                               ;   in Loop: Header=BB0_7 Depth=1
	mov	x12, x11
	b	LBB0_6
LBB0_11:
	mov	w12, #0
	b	LBB0_13
LBB0_12:
	mov	x12, x11
LBB0_13:
	ldr	w8, [x8, w12, sxtw #2]
	str	w8, [x19]
	ldr	w9, [x20]
	cmp	w9, #1024
	b.ne	LBB0_15
; %bb.14:
	mov	w0, #0
	lsl	w8, w8, #1
	str	w8, [x19]
	b	LBB0_16
LBB0_15:
	mov	w0, #0
LBB0_16:
	ldp	x29, x30, [sp, #32]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #16]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp], #48             ; 16-byte Folded Reload
	ret
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpLdrGotLdr	Lloh3, Lloh4, Lloh5
	.cfi_endproc
                                        ; -- End function
	.comm	_MTK_NFC_MIN_SPARE,4,2          ; @MTK_NFC_MIN_SPARE
	.comm	_EINVAL,4,2                     ; @EINVAL
	.no_dead_strip	_mtk_nfc_set_spare_per_sector
.subsections_via_symbols
