	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function ingenic_nand_attach_chip
_ingenic_nand_attach_chip:              ## @ingenic_nand_attach_chip
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rdi, %rbx
	callq	_nand_to_mtd
	movq	%rax, %r14
	movl	32(%rbx), %edi
	callq	_to_ingenic_nfc
	movq	%rax, %r15
	cmpl	$4, 4(%rbx)
	jne	LBB0_2
## %bb.1:
	movl	$9, %r9d
	movl	$4, %ecx
	jmp	LBB0_3
LBB0_2:
	movl	12(%rbx), %eax
	leal	(%rax,%rax,8), %edi
	callq	_fls
	movl	4(%rbx), %ecx
	leal	7(%rcx), %r9d
	testl	%ecx, %ecx
	cmovnsl	%ecx, %r9d
	sarl	$3, %r9d
	imull	%eax, %r9d
LBB0_3:
	movl	%r9d, 8(%rbx)
	movl	16(%rbx), %edx
	cmpl	$130, %edx
	je	LBB0_7
## %bb.4:
	cmpl	$129, %edx
	je	LBB0_13
## %bb.5:
	cmpl	$128, %edx
	jne	LBB0_11
## %bb.6:
	cmpl	$0, 12(%r15)
	leaq	L_.str.3(%rip), %rax
	leaq	L_.str.2(%rip), %rdx
	cmoveq	%rax, %rdx
	jmp	LBB0_10
LBB0_7:
	cmpl	$0, 12(%r15)
	je	LBB0_8
## %bb.9:
	movq	_ingenic_nand_ecc_hwctl@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, 28(%rbx)
	movq	_ingenic_nand_ecc_calculate@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, 24(%rbx)
	movq	_ingenic_nand_ecc_correct@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, 20(%rbx)
	leaq	L_.str.2(%rip), %rdx
LBB0_10:
	movl	8(%r15), %edi
	movl	12(%rbx), %r8d
	leaq	L_.str.1(%rip), %rsi
                                        ## kill: def $ecx killed $ecx killed $rcx
	xorl	%eax, %eax
	callq	_dev_info
	jmp	LBB0_14
LBB0_13:
	movl	8(%r15), %edi
	leaq	L_.str.4(%rip), %rsi
	xorl	%eax, %eax
	callq	_dev_info
LBB0_14:
	xorl	%r12d, %r12d
	cmpl	$130, 16(%rbx)
	jne	LBB0_23
## %bb.15:
	movl	(%r14), %eax
	movl	4(%r14), %ecx
	cltd
	idivl	12(%rbx)
	imull	8(%rbx), %eax
	addl	$-2, %ecx
	cmpl	%ecx, %eax
	jle	LBB0_17
## %bb.16:
	movl	8(%r15), %edi
	leaq	L_.str.6(%rip), %rsi
	xorl	%r12d, %r12d
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	_dev_err
	jmp	LBB0_12
LBB0_11:
	movl	8(%r15), %edi
	leaq	L_.str.5(%rip), %rsi
	xorl	%r12d, %r12d
	xorl	%eax, %eax
	callq	_dev_err
LBB0_12:
	movq	_EINVAL@GOTPCREL(%rip), %rax
	subl	(%rax), %r12d
	jmp	LBB0_23
LBB0_17:
	movl	(%rbx), %eax
	movq	_NAND_BBT_USE_FLASH@GOTPCREL(%rip), %rcx
	testl	%eax, (%rcx)
	je	LBB0_19
## %bb.18:
	movq	_NAND_BBT_NO_OOB@GOTPCREL(%rip), %rcx
	orl	(%rcx), %eax
	movl	%eax, (%rbx)
LBB0_19:
	leaq	L_.str.7(%rip), %rdi
	callq	_of_machine_is_compatible
	testq	%rax, %rax
	je	LBB0_21
## %bb.20:
	movq	_qi_lb60_ooblayout_ops@GOTPCREL(%rip), %rsi
	jmp	LBB0_22
LBB0_8:
	movl	8(%r15), %edi
	leaq	L_.str(%rip), %rsi
	xorl	%r12d, %r12d
	xorl	%eax, %eax
	callq	_dev_err
	movq	_ENODEV@GOTPCREL(%rip), %rax
	subl	(%rax), %r12d
	jmp	LBB0_23
LBB0_21:
	movq	(%r15), %rax
	movq	(%rax), %rsi
LBB0_22:
	movq	%r14, %rdi
	callq	_mtd_set_ooblayout
LBB0_23:
	movl	%r12d, %eax
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"HW ECC selected, but ECC controller not found\n"

	.comm	_ENODEV,4,2                     ## @ENODEV
	.comm	_ingenic_nand_ecc_hwctl,4,2     ## @ingenic_nand_ecc_hwctl
	.comm	_ingenic_nand_ecc_calculate,4,2 ## @ingenic_nand_ecc_calculate
	.comm	_ingenic_nand_ecc_correct,4,2   ## @ingenic_nand_ecc_correct
L_.str.1:                               ## @.str.1
	.asciz	"using %s (strength %d, size %d, bytes %d)\n"

L_.str.2:                               ## @.str.2
	.asciz	"hardware ECC"

L_.str.3:                               ## @.str.3
	.asciz	"software ECC"

L_.str.4:                               ## @.str.4
	.asciz	"not using ECC\n"

L_.str.5:                               ## @.str.5
	.asciz	"ECC mode %d not supported\n"

	.comm	_EINVAL,4,2                     ## @EINVAL
L_.str.6:                               ## @.str.6
	.asciz	"invalid ECC config: required %d ECC bytes, but only %d are available"

	.comm	_NAND_BBT_USE_FLASH,4,2         ## @NAND_BBT_USE_FLASH
	.comm	_NAND_BBT_NO_OOB,4,2            ## @NAND_BBT_NO_OOB
L_.str.7:                               ## @.str.7
	.asciz	"qi,lb60"

	.comm	_qi_lb60_ooblayout_ops,4,2      ## @qi_lb60_ooblayout_ops
	.no_dead_strip	_ingenic_nand_attach_chip
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function ingenic_nand_attach_chip
_ingenic_nand_attach_chip:              ; @ingenic_nand_attach_chip
	.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	x21, x0
	bl	_nand_to_mtd
	mov	x19, x0
	ldr	w0, [x21, #32]
	bl	_to_ingenic_nfc
	mov	x20, x0
	ldr	w8, [x21, #4]
	cmp	w8, #4
	b.ne	LBB0_2
; %bb.1:
	mov	w9, #9
	mov	w8, #4
	b	LBB0_3
LBB0_2:
	ldr	w8, [x21, #12]
	add	w0, w8, w8, lsl #3
	bl	_fls
	ldr	w8, [x21, #4]
	add	w9, w8, #7
	cmp	w8, #0
	csel	w9, w9, w8, lt
	asr	w9, w9, #3
	mul	w9, w9, w0
LBB0_3:
	str	w9, [x21, #8]
	ldr	w10, [x21, #16]
	cmp	w10, #130
	b.eq	LBB0_7
; %bb.4:
	cmp	w10, #129
	b.eq	LBB0_10
; %bb.5:
	cmp	w10, #128
	b.ne	LBB0_14
; %bb.6:
	ldr	w10, [x20, #12]
Lloh0:
	adrp	x11, l_.str.2@PAGE
Lloh1:
	add	x11, x11, l_.str.2@PAGEOFF
Lloh2:
	adrp	x12, l_.str.3@PAGE
Lloh3:
	add	x12, x12, l_.str.3@PAGEOFF
	cmp	w10, #0
	csel	x10, x12, x11, eq
	b	LBB0_9
LBB0_7:
	ldr	w10, [x20, #12]
	cbz	w10, LBB0_21
; %bb.8:
Lloh4:
	adrp	x10, _ingenic_nand_ecc_hwctl@GOTPAGE
Lloh5:
	ldr	x10, [x10, _ingenic_nand_ecc_hwctl@GOTPAGEOFF]
Lloh6:
	ldr	w10, [x10]
	str	w10, [x21, #28]
Lloh7:
	adrp	x10, _ingenic_nand_ecc_calculate@GOTPAGE
Lloh8:
	ldr	x10, [x10, _ingenic_nand_ecc_calculate@GOTPAGEOFF]
Lloh9:
	adrp	x11, _ingenic_nand_ecc_correct@GOTPAGE
Lloh10:
	ldr	x11, [x11, _ingenic_nand_ecc_correct@GOTPAGEOFF]
Lloh11:
	ldr	w10, [x10]
Lloh12:
	ldr	w11, [x11]
	stp	w11, w10, [x21, #20]
Lloh13:
	adrp	x10, l_.str.2@PAGE
Lloh14:
	add	x10, x10, l_.str.2@PAGEOFF
LBB0_9:
	ldr	w0, [x20, #8]
	ldr	w11, [x21, #12]
	stp	x11, x9, [sp, #16]
	stp	x10, x8, [sp]
Lloh15:
	adrp	x1, l_.str.1@PAGE
Lloh16:
	add	x1, x1, l_.str.1@PAGEOFF
	b	LBB0_11
LBB0_10:
	ldr	w0, [x20, #8]
Lloh17:
	adrp	x1, l_.str.4@PAGE
Lloh18:
	add	x1, x1, l_.str.4@PAGEOFF
LBB0_11:
	bl	_dev_info
	ldr	w8, [x21, #16]
	cmp	w8, #130
	b.ne	LBB0_24
; %bb.12:
	ldp	w9, w8, [x21, #8]
	ldp	w10, w11, [x19]
	sdiv	w8, w10, w8
	mul	w8, w9, w8
	sub	w9, w11, #2
	cmp	w8, w9
	b.le	LBB0_17
; %bb.13:
	ldr	w0, [x20, #8]
	stp	x8, x9, [sp]
Lloh19:
	adrp	x1, l_.str.6@PAGE
Lloh20:
	add	x1, x1, l_.str.6@PAGEOFF
	b	LBB0_15
LBB0_14:
	ldr	w0, [x20, #8]
	str	x10, [sp]
Lloh21:
	adrp	x1, l_.str.5@PAGE
Lloh22:
	add	x1, x1, l_.str.5@PAGEOFF
LBB0_15:
	bl	_dev_err
Lloh23:
	adrp	x8, _EINVAL@GOTPAGE
Lloh24:
	ldr	x8, [x8, _EINVAL@GOTPAGEOFF]
LBB0_16:
	ldr	w8, [x8]
	neg	w0, w8
	b	LBB0_25
LBB0_17:
	ldr	w8, [x21]
Lloh25:
	adrp	x9, _NAND_BBT_USE_FLASH@GOTPAGE
Lloh26:
	ldr	x9, [x9, _NAND_BBT_USE_FLASH@GOTPAGEOFF]
Lloh27:
	ldr	w9, [x9]
	tst	w9, w8
	b.eq	LBB0_19
; %bb.18:
Lloh28:
	adrp	x9, _NAND_BBT_NO_OOB@GOTPAGE
Lloh29:
	ldr	x9, [x9, _NAND_BBT_NO_OOB@GOTPAGEOFF]
Lloh30:
	ldr	w9, [x9]
	orr	w8, w9, w8
	str	w8, [x21]
LBB0_19:
Lloh31:
	adrp	x0, l_.str.7@PAGE
Lloh32:
	add	x0, x0, l_.str.7@PAGEOFF
	bl	_of_machine_is_compatible
	cbz	x0, LBB0_22
; %bb.20:
Lloh33:
	adrp	x1, _qi_lb60_ooblayout_ops@GOTPAGE
Lloh34:
	ldr	x1, [x1, _qi_lb60_ooblayout_ops@GOTPAGEOFF]
	b	LBB0_23
LBB0_21:
	ldr	w0, [x20, #8]
Lloh35:
	adrp	x1, l_.str@PAGE
Lloh36:
	add	x1, x1, l_.str@PAGEOFF
	bl	_dev_err
Lloh37:
	adrp	x8, _ENODEV@GOTPAGE
Lloh38:
	ldr	x8, [x8, _ENODEV@GOTPAGEOFF]
	b	LBB0_16
LBB0_22:
	ldr	x8, [x20]
	ldr	x1, [x8]
LBB0_23:
	mov	x0, x19
	bl	_mtd_set_ooblayout
LBB0_24:
	mov	w0, #0
LBB0_25:
	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	Lloh2, Lloh3
	.loh AdrpAdd	Lloh0, Lloh1
	.loh AdrpAdd	Lloh13, Lloh14
	.loh AdrpLdrGotLdr	Lloh9, Lloh10, Lloh12
	.loh AdrpLdrGotLdr	Lloh7, Lloh8, Lloh11
	.loh AdrpLdrGotLdr	Lloh4, Lloh5, Lloh6
	.loh AdrpAdd	Lloh15, Lloh16
	.loh AdrpAdd	Lloh17, Lloh18
	.loh AdrpAdd	Lloh19, Lloh20
	.loh AdrpAdd	Lloh21, Lloh22
	.loh AdrpLdrGot	Lloh23, Lloh24
	.loh AdrpLdrGotLdr	Lloh25, Lloh26, Lloh27
	.loh AdrpLdrGotLdr	Lloh28, Lloh29, Lloh30
	.loh AdrpAdd	Lloh31, Lloh32
	.loh AdrpLdrGot	Lloh33, Lloh34
	.loh AdrpLdrGot	Lloh37, Lloh38
	.loh AdrpAdd	Lloh35, Lloh36
	.cfi_endproc
                                        ; -- End function
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"HW ECC selected, but ECC controller not found\n"

	.comm	_ENODEV,4,2                     ; @ENODEV
	.comm	_ingenic_nand_ecc_hwctl,4,2     ; @ingenic_nand_ecc_hwctl
	.comm	_ingenic_nand_ecc_calculate,4,2 ; @ingenic_nand_ecc_calculate
	.comm	_ingenic_nand_ecc_correct,4,2   ; @ingenic_nand_ecc_correct
l_.str.1:                               ; @.str.1
	.asciz	"using %s (strength %d, size %d, bytes %d)\n"

l_.str.2:                               ; @.str.2
	.asciz	"hardware ECC"

l_.str.3:                               ; @.str.3
	.asciz	"software ECC"

l_.str.4:                               ; @.str.4
	.asciz	"not using ECC\n"

l_.str.5:                               ; @.str.5
	.asciz	"ECC mode %d not supported\n"

	.comm	_EINVAL,4,2                     ; @EINVAL
l_.str.6:                               ; @.str.6
	.asciz	"invalid ECC config: required %d ECC bytes, but only %d are available"

	.comm	_NAND_BBT_USE_FLASH,4,2         ; @NAND_BBT_USE_FLASH
	.comm	_NAND_BBT_NO_OOB,4,2            ; @NAND_BBT_NO_OOB
l_.str.7:                               ; @.str.7
	.asciz	"qi,lb60"

	.comm	_qi_lb60_ooblayout_ops,4,2      ; @qi_lb60_ooblayout_ops
	.no_dead_strip	_ingenic_nand_attach_chip
.subsections_via_symbols
