	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function r852_ecc_correct
_r852_ecc_correct:                      ## @r852_ecc_correct
	.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	$24, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %r14
	callq	_nand_to_mtd
	movl	%eax, %edi
	callq	_r852_get_dev
	xorl	%r15d, %r15d
	cmpq	$0, 16(%rax)
	jne	LBB0_11
## %bb.1:
	movq	%rax, %rbx
	cmpq	$0, 8(%rax)
	je	LBB0_3
## %bb.2:
	movq	$0, 8(%rbx)
	movq	_EIO@GOTPCREL(%rip), %rax
	xorl	%r15d, %r15d
	subl	(%rax), %r15d
	jmp	LBB0_11
LBB0_3:
	movq	_R852_CTL@GOTPCREL(%rip), %r15
	movl	(%r15), %esi
	movq	_R852_CTL_ECC_ACCESS@GOTPCREL(%rip), %rax
	movl	(%rax), %edx
	orl	(%rbx), %edx
	movq	%rbx, %rdi
	callq	_r852_write_reg
	movq	_R852_DATALINE@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	movq	%rbx, %rdi
	callq	_r852_read_reg_dword
	movl	%eax, %r12d
	movl	(%r15), %esi
	movl	(%rbx), %edx
	movq	%rbx, %rdi
	callq	_r852_write_reg
	movl	%r12d, %ecx
	movzbl	%ch, %edi
	movq	_R852_ECC_FAIL@GOTPCREL(%rip), %r13
	movl	(%r13), %eax
	xorl	%ebx, %ebx
	movl	$0, %esi
	testl	%edi, %eax
	jne	LBB0_4
## %bb.5:
	movq	_R852_ECC_CORRECTABLE@GOTPCREL(%rip), %rdx
	testl	%edi, (%rdx)
	je	LBB0_6
## %bb.7:
	movzbl	%cl, %edx
	movq	%rdx, -56(%rbp)                 ## 8-byte Spill
	movq	_R852_ECC_ERR_BIT_MSK@GOTPCREL(%rip), %r15
	movl	%ecx, -44(%rbp)                 ## 4-byte Spill
	movl	(%r15), %ecx
	andl	%edi, %ecx
	movl	%edi, %r12d
	leaq	L_.str.1(%rip), %rdi
	xorl	%esi, %esi
                                        ## kill: def $edx killed $edx killed $rdx
	xorl	%eax, %eax
	callq	_dbg
	movq	_R852_ECC_CORRECTABLE@GOTPCREL(%rip), %rdx
	andl	(%r15), %r12d
	movl	$1, %r15d
	movl	$1, %eax
	movl	%r12d, %ecx
	shll	%cl, %eax
	movl	-44(%rbp), %ecx                 ## 4-byte Reload
	movq	-56(%rbp), %rsi                 ## 8-byte Reload
	xorl	%eax, (%r14,%rsi,4)
	movl	(%r13), %eax
	jmp	LBB0_8
LBB0_6:
	xorl	%r15d, %r15d
LBB0_8:
	sarl	$16, %ecx
	movzbl	%ch, %edi
	movl	$1, %esi
	testl	%edi, %eax
	je	LBB0_9
LBB0_4:
	leaq	L_.str(%rip), %rdi
	xorl	%eax, %eax
	callq	_dbg
	movq	_EBADMSG@GOTPCREL(%rip), %rax
	subl	(%rax), %ebx
	movl	%ebx, %r15d
LBB0_11:
	movl	%r15d, %eax
	addq	$24, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_9:
	testl	%edi, (%rdx)
	je	LBB0_11
## %bb.10:
	movzbl	%cl, %r12d
	movq	_R852_ECC_ERR_BIT_MSK@GOTPCREL(%rip), %rax
	movl	(%rax), %ecx
	andl	%edi, %ecx
	movl	%edi, %r13d
	leaq	L_.str.1(%rip), %rdi
	movl	$1, %ebx
	movl	$1, %esi
	movl	%r12d, %edx
	xorl	%eax, %eax
	callq	_dbg
	movq	_R852_ECC_ERR_BIT_MSK@GOTPCREL(%rip), %rax
	andl	(%rax), %r13d
	movl	%r13d, %ecx
	shll	%cl, %ebx
	xorl	%ebx, 1024(%r14,%r12,4)
	incl	%r15d
	jmp	LBB0_11
	.cfi_endproc
                                        ## -- End function
	.comm	_EIO,4,2                        ## @EIO
	.comm	_R852_CTL,4,2                   ## @R852_CTL
	.comm	_R852_CTL_ECC_ACCESS,4,2        ## @R852_CTL_ECC_ACCESS
	.comm	_R852_DATALINE,4,2              ## @R852_DATALINE
	.comm	_R852_ECC_FAIL,4,2              ## @R852_ECC_FAIL
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"ecc: unrecoverable error, in half %d"

	.comm	_EBADMSG,4,2                    ## @EBADMSG
	.comm	_R852_ECC_CORRECTABLE,4,2       ## @R852_ECC_CORRECTABLE
L_.str.1:                               ## @.str.1
	.asciz	"ecc: recoverable error, in half %d, byte %d, bit %d"

	.comm	_R852_ECC_ERR_BIT_MSK,4,2       ## @R852_ECC_ERR_BIT_MSK
	.no_dead_strip	_r852_ecc_correct
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function r852_ecc_correct
_r852_ecc_correct:                      ; @r852_ecc_correct
	.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, x1
	bl	_nand_to_mtd
	bl	_r852_get_dev
	ldr	x8, [x0, #16]
	cbz	x8, LBB0_2
; %bb.1:
	mov	w21, #0
	b	LBB0_13
LBB0_2:
	mov	x21, x0
	ldr	x8, [x0, #8]
	cbz	x8, LBB0_4
; %bb.3:
	str	xzr, [x21, #8]
Lloh0:
	adrp	x8, _EIO@GOTPAGE
Lloh1:
	ldr	x8, [x8, _EIO@GOTPAGEOFF]
	b	LBB0_12
LBB0_4:
Lloh2:
	adrp	x22, _R852_CTL@GOTPAGE
Lloh3:
	ldr	x22, [x22, _R852_CTL@GOTPAGEOFF]
	ldr	w1, [x22]
	ldr	w8, [x21]
Lloh4:
	adrp	x9, _R852_CTL_ECC_ACCESS@GOTPAGE
Lloh5:
	ldr	x9, [x9, _R852_CTL_ECC_ACCESS@GOTPAGEOFF]
Lloh6:
	ldr	w9, [x9]
	orr	w2, w9, w8
	mov	x0, x21
	bl	_r852_write_reg
Lloh7:
	adrp	x8, _R852_DATALINE@GOTPAGE
Lloh8:
	ldr	x8, [x8, _R852_DATALINE@GOTPAGEOFF]
Lloh9:
	ldr	w1, [x8]
	mov	x0, x21
	bl	_r852_read_reg_dword
	mov	x20, x0
	ldr	w1, [x22]
	ldr	w2, [x21]
	mov	x0, x21
	bl	_r852_write_reg
	ubfx	w21, w20, #8, #8
Lloh10:
	adrp	x23, _R852_ECC_FAIL@GOTPAGE
Lloh11:
	ldr	x23, [x23, _R852_ECC_FAIL@GOTPAGEOFF]
	ldr	w8, [x23]
	tst	w8, w21
	b.eq	LBB0_6
; %bb.5:
	mov	w1, #0
	b	LBB0_11
LBB0_6:
Lloh12:
	adrp	x22, _R852_ECC_CORRECTABLE@GOTPAGE
Lloh13:
	ldr	x22, [x22, _R852_ECC_CORRECTABLE@GOTPAGEOFF]
	ldr	w9, [x22]
	tst	w9, w21
	b.eq	LBB0_8
; %bb.7:
	and	w24, w20, #0xff
Lloh14:
	adrp	x25, _R852_ECC_ERR_BIT_MSK@GOTPAGE
Lloh15:
	ldr	x25, [x25, _R852_ECC_ERR_BIT_MSK@GOTPAGEOFF]
	ldr	w8, [x25]
	and	w8, w8, w21
	mov	x9, x24
	stp	x9, x8, [sp]
Lloh16:
	adrp	x0, l_.str.1@PAGE
Lloh17:
	add	x0, x0, l_.str.1@PAGEOFF
	mov	w1, #0
	bl	_dbg
	ldr	w8, [x25]
	and	w8, w8, w21
	mov	w21, #1
	lsl	w8, w21, w8
	lsl	x9, x24, #2
	ldr	w10, [x19, x9]
	eor	w8, w8, w10
	str	w8, [x19, x9]
	ldr	w8, [x23]
	b	LBB0_9
LBB0_8:
	mov	w21, #0
LBB0_9:
	lsr	w23, w20, #24
	tst	w8, w23
	b.eq	LBB0_14
; %bb.10:
	mov	w1, #1
LBB0_11:
Lloh18:
	adrp	x0, l_.str@PAGE
Lloh19:
	add	x0, x0, l_.str@PAGEOFF
	bl	_dbg
Lloh20:
	adrp	x8, _EBADMSG@GOTPAGE
Lloh21:
	ldr	x8, [x8, _EBADMSG@GOTPAGEOFF]
LBB0_12:
	ldr	w8, [x8]
	neg	w21, w8
LBB0_13:
	mov	x0, x21
	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_14:
	ldr	w8, [x22]
	tst	w8, w23
	b.eq	LBB0_13
; %bb.15:
	add	x19, x19, #1024
	ubfx	w20, w20, #16, #8
Lloh22:
	adrp	x22, _R852_ECC_ERR_BIT_MSK@GOTPAGE
Lloh23:
	ldr	x22, [x22, _R852_ECC_ERR_BIT_MSK@GOTPAGEOFF]
	ldr	w8, [x22]
	and	w8, w8, w23
	mov	x9, x20
	stp	x9, x8, [sp]
Lloh24:
	adrp	x0, l_.str.1@PAGE
Lloh25:
	add	x0, x0, l_.str.1@PAGEOFF
	mov	w24, #1
	mov	w1, #1
	bl	_dbg
	ldr	w8, [x22]
	and	w8, w8, w23
	lsl	w8, w24, w8
	lsl	x9, x20, #2
	ldr	w10, [x19, x9]
	eor	w8, w8, w10
	str	w8, [x19, x9]
	add	w21, w21, #1
	b	LBB0_13
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpLdrGot	Lloh10, Lloh11
	.loh AdrpLdrGotLdr	Lloh7, Lloh8, Lloh9
	.loh AdrpLdrGotLdr	Lloh4, Lloh5, Lloh6
	.loh AdrpLdrGot	Lloh2, Lloh3
	.loh AdrpLdrGot	Lloh12, Lloh13
	.loh AdrpAdd	Lloh16, Lloh17
	.loh AdrpLdrGot	Lloh14, Lloh15
	.loh AdrpLdrGot	Lloh20, Lloh21
	.loh AdrpAdd	Lloh18, Lloh19
	.loh AdrpAdd	Lloh24, Lloh25
	.loh AdrpLdrGot	Lloh22, Lloh23
	.cfi_endproc
                                        ; -- End function
	.comm	_EIO,4,2                        ; @EIO
	.comm	_R852_CTL,4,2                   ; @R852_CTL
	.comm	_R852_CTL_ECC_ACCESS,4,2        ; @R852_CTL_ECC_ACCESS
	.comm	_R852_DATALINE,4,2              ; @R852_DATALINE
	.comm	_R852_ECC_FAIL,4,2              ; @R852_ECC_FAIL
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"ecc: unrecoverable error, in half %d"

	.comm	_EBADMSG,4,2                    ; @EBADMSG
	.comm	_R852_ECC_CORRECTABLE,4,2       ; @R852_ECC_CORRECTABLE
l_.str.1:                               ; @.str.1
	.asciz	"ecc: recoverable error, in half %d, byte %d, bit %d"

	.comm	_R852_ECC_ERR_BIT_MSK,4,2       ; @R852_ECC_ERR_BIT_MSK
	.no_dead_strip	_r852_ecc_correct
.subsections_via_symbols
