	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function mtk_nfc_ecc_init
_mtk_nfc_ecc_init:                      ## @mtk_nfc_ecc_init
	.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	%r12
	pushq	%rbx
	subq	$16, %rsp
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %r12
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	_mtd_to_nand
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	_nand_get_controller_data
	movq	%rax, %r15
	movq	(%rbx), %rax
	movq	_NAND_ECC_HW@GOTPCREL(%rip), %rcx
	cmpq	(%rcx), %rax
	jne	LBB0_1
## %bb.2:
	cmpl	$0, 8(%rbx)
	je	LBB0_4
## %bb.3:
	cmpl	$0, 12(%rbx)
	jne	LBB0_15
LBB0_4:
	movl	16(%rbx), %eax
	movl	20(%rbx), %ecx
	movl	%eax, 12(%rbx)
	cmpl	$1023, %ecx                     ## imm = 0x3FF
	jg	LBB0_9
## %bb.5:
	cmpl	$513, (%r12)                    ## imm = 0x201
	jl	LBB0_8
## %bb.6:
	movq	8(%r15), %rcx
	cmpl	$513, (%rcx)                    ## imm = 0x201
	jl	LBB0_8
## %bb.7:
	movl	$1024, 8(%rbx)                  ## imm = 0x400
	addl	%eax, %eax
	movl	%eax, 12(%rbx)
	jmp	LBB0_10
LBB0_1:
	leaq	L_.str(%rip), %rsi
	movq	%r14, %rdi
	callq	_dev_err
	movq	_EINVAL@GOTPCREL(%rip), %rcx
	xorl	%eax, %eax
	subl	(%rcx), %eax
	jmp	LBB0_16
LBB0_9:
	movl	$1024, 8(%rbx)                  ## imm = 0x400
	jmp	LBB0_10
LBB0_8:
	movl	$512, 8(%rbx)                   ## imm = 0x200
LBB0_10:
	leaq	-36(%rbp), %rdi
	movq	%r12, %rsi
	callq	_mtk_nfc_set_spare_per_sector
	testl	%eax, %eax
	jne	LBB0_16
## %bb.11:
	movl	12(%rbx), %r12d
	movl	(%r15), %edi
	callq	_mtk_ecc_get_parity_bits
	imull	%r12d, %eax
	addl	$7, %eax
	sarl	$3, %eax
	movl	-36(%rbp), %r12d
	movl	%r12d, %ecx
	subl	%eax, %ecx
	movq	_NFI_FDM_MAX_SIZE@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	cmpl	%eax, %ecx
	jg	LBB0_14
## %bb.12:
	testl	%ecx, %ecx
	jns	LBB0_15
## %bb.13:
	movq	_NFI_FDM_MIN_SIZE@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
LBB0_14:
	subl	%eax, %r12d
	movl	%r12d, -36(%rbp)
	shll	$3, %r12d
	movl	(%r15), %edi
	callq	_mtk_ecc_get_parity_bits
	movl	%eax, %ecx
	movl	%r12d, %eax
	cltd
	idivl	%ecx
	movl	%eax, 12(%rbx)
LBB0_15:
	movl	(%r15), %edi
	movq	%rbx, %rsi
	addq	$12, %rsi
	callq	_mtk_ecc_adjust_strength
	movl	8(%rbx), %edx
	movl	12(%rbx), %ecx
	leaq	L_.str.1(%rip), %rsi
	movq	%r14, %rdi
	callq	_dev_info
	xorl	%eax, %eax
LBB0_16:
	addq	$16, %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.comm	_NAND_ECC_HW,8,3                ## @NAND_ECC_HW
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"ecc.mode not supported\n"

	.comm	_EINVAL,4,2                     ## @EINVAL
	.comm	_NFI_FDM_MAX_SIZE,4,2           ## @NFI_FDM_MAX_SIZE
	.comm	_NFI_FDM_MIN_SIZE,8,3           ## @NFI_FDM_MIN_SIZE
L_.str.1:                               ## @.str.1
	.asciz	"eccsize %d eccstrength %d\n"

	.no_dead_strip	_mtk_nfc_ecc_init
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function mtk_nfc_ecc_init
_mtk_nfc_ecc_init:                      ; @mtk_nfc_ecc_init
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #64
	.cfi_def_cfa_offset 64
	stp	x22, x21, [sp, #16]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #32]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #48]             ; 16-byte Folded Spill
	add	x29, sp, #48
	.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	x22, x1
	mov	x19, x0
	mov	x0, x1
	bl	_mtd_to_nand
	mov	x20, x0
	bl	_nand_get_controller_data
	ldr	x8, [x20]
Lloh0:
	adrp	x9, _NAND_ECC_HW@GOTPAGE
Lloh1:
	ldr	x9, [x9, _NAND_ECC_HW@GOTPAGEOFF]
Lloh2:
	ldr	x9, [x9]
	cmp	x8, x9
	b.ne	LBB0_7
; %bb.1:
	mov	x21, x0
	ldr	w8, [x20, #8]
	cbz	w8, LBB0_3
; %bb.2:
	ldr	w8, [x20, #12]
	cbnz	w8, LBB0_16
LBB0_3:
	ldp	w8, w9, [x20, #16]
	str	w8, [x20, #12]
	cmp	w9, #1023
	b.gt	LBB0_8
; %bb.4:
	ldr	w9, [x22]
	cmp	w9, #513
	b.lt	LBB0_9
; %bb.5:
	ldr	x9, [x21, #8]
	ldr	w9, [x9]
	cmp	w9, #513
	b.lt	LBB0_9
; %bb.6:
	mov	w9, #1024
	lsl	w8, w8, #1
	stp	w9, w8, [x20, #8]
	b	LBB0_11
LBB0_7:
Lloh3:
	adrp	x1, l_.str@PAGE
Lloh4:
	add	x1, x1, l_.str@PAGEOFF
	mov	x0, x19
	bl	_dev_err
Lloh5:
	adrp	x8, _EINVAL@GOTPAGE
Lloh6:
	ldr	x8, [x8, _EINVAL@GOTPAGEOFF]
Lloh7:
	ldr	w8, [x8]
	neg	w0, w8
	b	LBB0_17
LBB0_8:
	mov	w8, #1024
	b	LBB0_10
LBB0_9:
	mov	w8, #512
LBB0_10:
	str	w8, [x20, #8]
LBB0_11:
	add	x0, sp, #12
	mov	x1, x22
	bl	_mtk_nfc_set_spare_per_sector
	cbnz	w0, LBB0_17
; %bb.12:
	ldr	w22, [x20, #12]
	ldr	w0, [x21]
	bl	_mtk_ecc_get_parity_bits
	orr	w8, wzr, #0x7
	madd	w9, w0, w22, w8
	ldr	w8, [sp, #12]
	sub	w10, w8, w9, asr #3
Lloh8:
	adrp	x9, _NFI_FDM_MAX_SIZE@GOTPAGE
Lloh9:
	ldr	x9, [x9, _NFI_FDM_MAX_SIZE@GOTPAGEOFF]
Lloh10:
	ldr	w9, [x9]
	cmp	w10, w9
	b.gt	LBB0_15
; %bb.13:
	tbz	w10, #31, LBB0_16
; %bb.14:
Lloh11:
	adrp	x9, _NFI_FDM_MIN_SIZE@GOTPAGE
Lloh12:
	ldr	x9, [x9, _NFI_FDM_MIN_SIZE@GOTPAGEOFF]
Lloh13:
	ldr	w9, [x9]
LBB0_15:
	sub	w8, w8, w9
	str	w8, [sp, #12]
	lsl	w22, w8, #3
	ldr	w0, [x21]
	bl	_mtk_ecc_get_parity_bits
	sdiv	w8, w22, w0
	str	w8, [x20, #12]
LBB0_16:
	ldr	w0, [x21]
	add	x1, x20, #12
	bl	_mtk_ecc_adjust_strength
	ldp	w2, w3, [x20, #8]
Lloh14:
	adrp	x1, l_.str.1@PAGE
Lloh15:
	add	x1, x1, l_.str.1@PAGEOFF
	mov	x0, x19
	bl	_dev_info
	mov	w0, #0
LBB0_17:
	ldp	x29, x30, [sp, #48]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #32]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #16]             ; 16-byte Folded Reload
	add	sp, sp, #64
	ret
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpLdrGotLdr	Lloh5, Lloh6, Lloh7
	.loh AdrpAdd	Lloh3, Lloh4
	.loh AdrpLdrGotLdr	Lloh8, Lloh9, Lloh10
	.loh AdrpLdrGotLdr	Lloh11, Lloh12, Lloh13
	.loh AdrpAdd	Lloh14, Lloh15
	.cfi_endproc
                                        ; -- End function
	.comm	_NAND_ECC_HW,8,3                ; @NAND_ECC_HW
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"ecc.mode not supported\n"

	.comm	_EINVAL,4,2                     ; @EINVAL
	.comm	_NFI_FDM_MAX_SIZE,4,2           ; @NFI_FDM_MAX_SIZE
	.comm	_NFI_FDM_MIN_SIZE,8,3           ; @NFI_FDM_MIN_SIZE
l_.str.1:                               ; @.str.1
	.asciz	"eccsize %d eccstrength %d\n"

	.no_dead_strip	_mtk_nfc_ecc_init
.subsections_via_symbols
