	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_mtd_fixwrg                     ## -- Begin function mtd_fixwrg
	.p2align	4, 0x90
_mtd_fixwrg:                            ## @mtd_fixwrg
	.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	%rdx, -56(%rbp)                 ## 8-byte Spill
	movq	%rsi, %r13
	movq	%rdi, %r15
	movq	_quiet@GOTPCREL(%rip), %rax
	cmpl	$1, (%rax)
	jg	LBB0_2
## %bb.1:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	leaq	L_.str(%rip), %rsi
	movq	%r15, %rdx
	movq	%r13, %rcx
	xorl	%eax, %eax
	callq	_fprintf
LBB0_2:
	movq	_erasesize@GOTPCREL(%rip), %r12
	xorl	%ebx, %ebx
	subl	(%r12), %ebx
	movq	%r15, %rdi
	callq	_mtd_check_open
	testl	%eax, %eax
	js	LBB0_3
## %bb.4:
	movl	%eax, %r14d
	movslq	%ebx, %r15
	andq	%r13, %r15
	movslq	(%r12), %rdi
	leaq	(%r15,%rdi), %rax
	movq	_mtdsize@GOTPCREL(%rip), %rcx
	movq	(%rcx), %rdx
	cmpq	%rdx, %rax
	ja	LBB0_5
## %bb.7:
                                        ## kill: def $edi killed $edi killed $rdi
	callq	_malloc
	testq	%rax, %rax
	je	LBB0_8
## %bb.10:
	movq	%rax, %rbx
	movl	(%r12), %edx
	movl	%r14d, %edi
	movq	%rax, %rsi
	movq	%r15, %rcx
	callq	_pread
	cmpl	(%r12), %eax
	jne	LBB0_11
## %bb.12:
	movq	%rbx, %rax
	movl	%r14d, %ebx
	subq	%r15, %r13
	movq	%rax, %r12
	addq	%r13, %r12
	movq	%rax, -48(%rbp)                 ## 8-byte Spill
	movl	4(%rax,%r13), %edi
	callq	_le32_to_cpu
	movq	_WRG_MAGIC@GOTPCREL(%rip), %r14
	movslq	(%r14), %rcx
	cmpq	%rcx, %rax
	jne	LBB0_25
## %bb.13:
	movl	(%r12), %edi
	callq	_le32_to_cpu
	testq	%rax, %rax
	je	LBB0_26
## %bb.14:
	addq	$8, %r13
	movq	_mtdsize@GOTPCREL(%rip), %rax
	movq	(%rax), %r14
	subq	%r13, %r14
	movq	-56(%rbp), %rax                 ## 8-byte Reload
	testq	%rax, %rax
	cmovneq	%rax, %r14
	movl	(%r12), %edi
	callq	_le32_to_cpu
	cmpq	%rax, %r14
	jbe	LBB0_16
## %bb.15:
	movl	(%r12), %edi
	callq	_le32_to_cpu
	movq	%rax, %r14
LBB0_16:
	movq	%r12, %rdi
	movl	%ebx, %esi
	movq	%r13, %rdx
	movq	%r14, %rcx
	callq	_wrg_fix_md5
	testq	%rax, %rax
	jne	LBB0_24
## %bb.17:
	movl	%ebx, %edi
	movq	%r15, %rsi
	callq	_mtd_erase_block
	testq	%rax, %rax
	jne	LBB0_27
## %bb.18:
	movq	_quiet@GOTPCREL(%rip), %r14
	cmpl	$1, (%r14)
	movq	_erasesize@GOTPCREL(%rip), %r12
	jg	LBB0_20
## %bb.19:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	leaq	L_.str.8(%rip), %rsi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	_fprintf
LBB0_20:
	movl	(%r12), %edx
	movl	%ebx, %edi
	movq	-48(%rbp), %rsi                 ## 8-byte Reload
	movq	%r15, %rcx
	callq	_pwrite
	cmpl	(%r12), %eax
	jne	LBB0_21
## %bb.22:
	cmpl	$1, (%r14)
	jg	LBB0_24
## %bb.23:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	leaq	L_.str.10(%rip), %rsi
	xorl	%eax, %eax
	callq	_fprintf
LBB0_24:
	movl	%ebx, %edi
	callq	_close
	xorl	%eax, %eax
	callq	_sync
LBB0_9:
	xorl	%eax, %eax
	addq	$24, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_8:
	callq	_mtd_fixwrg.cold.1
	jmp	LBB0_9
LBB0_11:
	callq	_mtd_fixwrg.cold.2
	jmp	LBB0_9
LBB0_3:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	leaq	L_.str.1(%rip), %rsi
	movq	%r15, %rdx
	jmp	LBB0_6
LBB0_5:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	leaq	L_.str.2(%rip), %rsi
	jmp	LBB0_6
LBB0_25:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %ebx
	movl	4(%r12), %edi
	callq	_le32_to_cpu
	movl	(%r14), %ecx
	leaq	L_.str.5(%rip), %rsi
	movl	%ebx, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	_fprintf
	movl	$1, %edi
	callq	_exit
LBB0_26:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	leaq	L_.str.6(%rip), %rsi
	xorl	%eax, %eax
	callq	_fprintf
	movl	$1, %edi
	callq	_exit
LBB0_27:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %ebx
	movq	_errno@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	callq	_strerror
	leaq	L_.str.7(%rip), %rsi
	movl	%ebx, %edi
	movq	%r15, %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	callq	_fprintf
	movl	$1, %edi
	callq	_exit
LBB0_21:
	movq	_stderr@GOTPCREL(%rip), %rax
	movl	(%rax), %ebx
	movq	_errno@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	callq	_strerror
	leaq	L_.str.9(%rip), %rsi
	movl	%ebx, %edi
	movq	%rax, %rdx
LBB0_6:
	xorl	%eax, %eax
	callq	_fprintf
	movl	$1, %edi
	callq	_exit
	.cfi_endproc
                                        ## -- End function
	.p2align	4, 0x90                         ## -- Begin function mtd_fixwrg.cold.1
_mtd_fixwrg.cold.1:                     ## @mtd_fixwrg.cold.1
	.cfi_startproc
## %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	leaq	L_.str.3(%rip), %rdi
	callq	_perror
	pushq	$1
	popq	%rdi
	callq	_exit
	.cfi_endproc
                                        ## -- End function
	.p2align	4, 0x90                         ## -- Begin function mtd_fixwrg.cold.2
_mtd_fixwrg.cold.2:                     ## @mtd_fixwrg.cold.2
	.cfi_startproc
## %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	leaq	L_.str.4(%rip), %rdi
	callq	_perror
	pushq	$1
	popq	%rdi
	callq	_exit
	.cfi_endproc
                                        ## -- End function
	.comm	_quiet,4,2                      ## @quiet
	.comm	_stderr,4,2                     ## @stderr
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"Trying to fix WRG header in %s at 0x%x...\n"

	.comm	_erasesize,4,2                  ## @erasesize
L_.str.1:                               ## @.str.1
	.asciz	"Could not open mtd device: %s\n"

	.comm	_mtdsize,8,3                    ## @mtdsize
L_.str.2:                               ## @.str.2
	.asciz	"Offset too large, device size 0x%x\n"

L_.str.3:                               ## @.str.3
	.asciz	"malloc"

L_.str.4:                               ## @.str.4
	.asciz	"pread"

	.comm	_WRG_MAGIC,4,2                  ## @WRG_MAGIC
L_.str.5:                               ## @.str.5
	.asciz	"No WRG header found (%08x != %08x)\n"

L_.str.6:                               ## @.str.6
	.asciz	"WRG entity with empty image\n"

L_.str.7:                               ## @.str.7
	.asciz	"Can't erease block at 0x%x (%s)\n"

	.comm	_errno,4,2                      ## @errno
L_.str.8:                               ## @.str.8
	.asciz	"Rewriting block at 0x%x\n"

L_.str.9:                               ## @.str.9
	.asciz	"Error writing block (%s)\n"

L_.str.10:                              ## @.str.10
	.asciz	"Done.\n"

.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_mtd_fixwrg                     ; -- Begin function mtd_fixwrg
	.p2align	2
_mtd_fixwrg:                            ; @mtd_fixwrg
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #112
	.cfi_def_cfa_offset 112
	stp	x28, x27, [sp, #16]             ; 16-byte Folded Spill
	stp	x26, x25, [sp, #32]             ; 16-byte Folded Spill
	stp	x24, x23, [sp, #48]             ; 16-byte Folded Spill
	stp	x22, x21, [sp, #64]             ; 16-byte Folded Spill
	stp	x20, x19, [sp, #80]             ; 16-byte Folded Spill
	stp	x29, x30, [sp, #96]             ; 16-byte Folded Spill
	add	x29, sp, #96
	.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
	.cfi_offset w27, -88
	.cfi_offset w28, -96
	mov	x22, x2
	mov	x23, x1
	mov	x20, x0
Lloh0:
	adrp	x25, _quiet@GOTPAGE
Lloh1:
	ldr	x25, [x25, _quiet@GOTPAGEOFF]
	ldr	w8, [x25]
	cmp	w8, #1
	b.gt	LBB0_2
; %bb.1:
Lloh2:
	adrp	x8, _stderr@GOTPAGE
Lloh3:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh4:
	ldr	w0, [x8]
	stp	x20, x23, [sp]
Lloh5:
	adrp	x1, l_.str@PAGE
Lloh6:
	add	x1, x1, l_.str@PAGEOFF
	bl	_fprintf
LBB0_2:
Lloh7:
	adrp	x26, _erasesize@GOTPAGE
Lloh8:
	ldr	x26, [x26, _erasesize@GOTPAGEOFF]
	ldr	w21, [x26]
	mov	x0, x20
	bl	_mtd_check_open
	tbnz	w0, #31, LBB0_18
; %bb.3:
	mov	x19, x0
	neg	w8, w21
	sxtw	x8, w8
	and	x20, x8, x23
	ldrsw	x0, [x26]
Lloh9:
	adrp	x27, _mtdsize@GOTPAGE
Lloh10:
	ldr	x27, [x27, _mtdsize@GOTPAGEOFF]
	ldr	x8, [x27]
	add	x9, x20, x0
	cmp	x9, x8
	b.hi	LBB0_19
; %bb.4:
                                        ; kill: def $w0 killed $w0 killed $x0
	bl	_malloc
	cbz	x0, LBB0_20
; %bb.5:
	mov	x21, x0
	ldr	w2, [x26]
	mov	x0, x19
	mov	x1, x21
	mov	x3, x20
	bl	_pread
	ldr	w8, [x26]
	cmp	w0, w8
	b.ne	LBB0_21
; %bb.6:
	sub	x24, x23, x20
	add	x23, x21, x24
	ldr	w0, [x23, #4]
	bl	_le32_to_cpu
Lloh11:
	adrp	x8, _WRG_MAGIC@GOTPAGE
Lloh12:
	ldr	x8, [x8, _WRG_MAGIC@GOTPAGEOFF]
	ldrsw	x9, [x8]
	cmp	x0, x9
	b.ne	LBB0_22
; %bb.7:
	ldr	w0, [x23]
	bl	_le32_to_cpu
	cbz	x0, LBB0_23
; %bb.8:
	add	x24, x24, #8
	ldr	x8, [x27]
	sub	x8, x8, x24
	cmp	x22, #0
	csel	x22, x8, x22, eq
	ldr	w0, [x23]
	bl	_le32_to_cpu
	cmp	x22, x0
	b.ls	LBB0_10
; %bb.9:
	ldr	w0, [x23]
	bl	_le32_to_cpu
	mov	x22, x0
LBB0_10:
	mov	x0, x23
	mov	x1, x19
	mov	x2, x24
	mov	x3, x22
	bl	_wrg_fix_md5
	cbnz	x0, LBB0_17
; %bb.11:
	mov	x0, x19
	mov	x1, x20
	bl	_mtd_erase_block
	cbnz	x0, LBB0_24
; %bb.12:
	ldr	w8, [x25]
	cmp	w8, #1
	b.gt	LBB0_14
; %bb.13:
Lloh13:
	adrp	x8, _stderr@GOTPAGE
Lloh14:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh15:
	ldr	w0, [x8]
	str	x20, [sp]
Lloh16:
	adrp	x1, l_.str.8@PAGE
Lloh17:
	add	x1, x1, l_.str.8@PAGEOFF
	bl	_fprintf
LBB0_14:
	ldr	w2, [x26]
	mov	x0, x19
	mov	x1, x21
	mov	x3, x20
	bl	_pwrite
	ldr	w8, [x26]
	cmp	w0, w8
	b.ne	LBB0_25
; %bb.15:
	ldr	w8, [x25]
	cmp	w8, #1
	b.gt	LBB0_17
; %bb.16:
Lloh18:
	adrp	x8, _stderr@GOTPAGE
Lloh19:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh20:
	ldr	w0, [x8]
Lloh21:
	adrp	x1, l_.str.10@PAGE
Lloh22:
	add	x1, x1, l_.str.10@PAGEOFF
	bl	_fprintf
LBB0_17:
	mov	x0, x19
	bl	_close
	bl	_sync
	mov	w0, #0
	ldp	x29, x30, [sp, #96]             ; 16-byte Folded Reload
	ldp	x20, x19, [sp, #80]             ; 16-byte Folded Reload
	ldp	x22, x21, [sp, #64]             ; 16-byte Folded Reload
	ldp	x24, x23, [sp, #48]             ; 16-byte Folded Reload
	ldp	x26, x25, [sp, #32]             ; 16-byte Folded Reload
	ldp	x28, x27, [sp, #16]             ; 16-byte Folded Reload
	add	sp, sp, #112
	ret
LBB0_18:
Lloh23:
	adrp	x8, _stderr@GOTPAGE
Lloh24:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh25:
	ldr	w0, [x8]
	str	x20, [sp]
Lloh26:
	adrp	x1, l_.str.1@PAGE
Lloh27:
	add	x1, x1, l_.str.1@PAGEOFF
	b	LBB0_27
LBB0_19:
Lloh28:
	adrp	x9, _stderr@GOTPAGE
Lloh29:
	ldr	x9, [x9, _stderr@GOTPAGEOFF]
Lloh30:
	ldr	w0, [x9]
	str	x8, [sp]
Lloh31:
	adrp	x1, l_.str.2@PAGE
Lloh32:
	add	x1, x1, l_.str.2@PAGEOFF
	b	LBB0_27
LBB0_20:
	bl	_mtd_fixwrg.cold.1
LBB0_21:
	bl	_mtd_fixwrg.cold.2
LBB0_22:
Lloh33:
	adrp	x9, _stderr@GOTPAGE
Lloh34:
	ldr	x9, [x9, _stderr@GOTPAGEOFF]
Lloh35:
	ldr	w19, [x9]
	ldr	w0, [x23, #4]
	mov	x20, x8
	bl	_le32_to_cpu
	ldr	w8, [x20]
	stp	x0, x8, [sp]
Lloh36:
	adrp	x1, l_.str.5@PAGE
Lloh37:
	add	x1, x1, l_.str.5@PAGEOFF
	b	LBB0_26
LBB0_23:
Lloh38:
	adrp	x8, _stderr@GOTPAGE
Lloh39:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh40:
	ldr	w0, [x8]
Lloh41:
	adrp	x1, l_.str.6@PAGE
Lloh42:
	add	x1, x1, l_.str.6@PAGEOFF
	b	LBB0_27
LBB0_24:
Lloh43:
	adrp	x8, _stderr@GOTPAGE
Lloh44:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh45:
	ldr	w19, [x8]
Lloh46:
	adrp	x8, _errno@GOTPAGE
Lloh47:
	ldr	x8, [x8, _errno@GOTPAGEOFF]
Lloh48:
	ldr	w0, [x8]
	bl	_strerror
	stp	x20, x0, [sp]
Lloh49:
	adrp	x1, l_.str.7@PAGE
Lloh50:
	add	x1, x1, l_.str.7@PAGEOFF
	b	LBB0_26
LBB0_25:
Lloh51:
	adrp	x8, _stderr@GOTPAGE
Lloh52:
	ldr	x8, [x8, _stderr@GOTPAGEOFF]
Lloh53:
	ldr	w19, [x8]
Lloh54:
	adrp	x8, _errno@GOTPAGE
Lloh55:
	ldr	x8, [x8, _errno@GOTPAGEOFF]
Lloh56:
	ldr	w0, [x8]
	bl	_strerror
	str	x0, [sp]
Lloh57:
	adrp	x1, l_.str.9@PAGE
Lloh58:
	add	x1, x1, l_.str.9@PAGEOFF
LBB0_26:
	mov	x0, x19
LBB0_27:
	bl	_fprintf
	mov	w0, #1
	bl	_exit
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpAdd	Lloh5, Lloh6
	.loh AdrpLdrGotLdr	Lloh2, Lloh3, Lloh4
	.loh AdrpLdrGot	Lloh7, Lloh8
	.loh AdrpLdrGot	Lloh9, Lloh10
	.loh AdrpLdrGot	Lloh11, Lloh12
	.loh AdrpAdd	Lloh16, Lloh17
	.loh AdrpLdrGotLdr	Lloh13, Lloh14, Lloh15
	.loh AdrpAdd	Lloh21, Lloh22
	.loh AdrpLdrGotLdr	Lloh18, Lloh19, Lloh20
	.loh AdrpAdd	Lloh26, Lloh27
	.loh AdrpLdrGotLdr	Lloh23, Lloh24, Lloh25
	.loh AdrpAdd	Lloh31, Lloh32
	.loh AdrpLdrGotLdr	Lloh28, Lloh29, Lloh30
	.loh AdrpAdd	Lloh36, Lloh37
	.loh AdrpLdrGotLdr	Lloh33, Lloh34, Lloh35
	.loh AdrpAdd	Lloh41, Lloh42
	.loh AdrpLdrGotLdr	Lloh38, Lloh39, Lloh40
	.loh AdrpAdd	Lloh49, Lloh50
	.loh AdrpLdrGotLdr	Lloh46, Lloh47, Lloh48
	.loh AdrpLdrGotLdr	Lloh43, Lloh44, Lloh45
	.loh AdrpAdd	Lloh57, Lloh58
	.loh AdrpLdrGotLdr	Lloh54, Lloh55, Lloh56
	.loh AdrpLdrGotLdr	Lloh51, Lloh52, Lloh53
	.cfi_endproc
                                        ; -- End function
	.p2align	2                               ; -- Begin function mtd_fixwrg.cold.1
_mtd_fixwrg.cold.1:                     ; @mtd_fixwrg.cold.1
	.cfi_startproc
; %bb.0:
	stp	x29, x30, [sp, #-16]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 16
	mov	x29, sp
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
Lloh59:
	adrp	x0, l_.str.3@PAGE
Lloh60:
	add	x0, x0, l_.str.3@PAGEOFF
	bl	_perror
	mov	w0, #1
	bl	_exit
	.loh AdrpAdd	Lloh59, Lloh60
	.cfi_endproc
                                        ; -- End function
	.p2align	2                               ; -- Begin function mtd_fixwrg.cold.2
_mtd_fixwrg.cold.2:                     ; @mtd_fixwrg.cold.2
	.cfi_startproc
; %bb.0:
	stp	x29, x30, [sp, #-16]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 16
	mov	x29, sp
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
Lloh61:
	adrp	x0, l_.str.4@PAGE
Lloh62:
	add	x0, x0, l_.str.4@PAGEOFF
	bl	_perror
	mov	w0, #1
	bl	_exit
	.loh AdrpAdd	Lloh61, Lloh62
	.cfi_endproc
                                        ; -- End function
	.comm	_quiet,4,2                      ; @quiet
	.comm	_stderr,4,2                     ; @stderr
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"Trying to fix WRG header in %s at 0x%x...\n"

	.comm	_erasesize,4,2                  ; @erasesize
l_.str.1:                               ; @.str.1
	.asciz	"Could not open mtd device: %s\n"

	.comm	_mtdsize,8,3                    ; @mtdsize
l_.str.2:                               ; @.str.2
	.asciz	"Offset too large, device size 0x%x\n"

l_.str.3:                               ; @.str.3
	.asciz	"malloc"

l_.str.4:                               ; @.str.4
	.asciz	"pread"

	.comm	_WRG_MAGIC,4,2                  ; @WRG_MAGIC
l_.str.5:                               ; @.str.5
	.asciz	"No WRG header found (%08x != %08x)\n"

l_.str.6:                               ; @.str.6
	.asciz	"WRG entity with empty image\n"

l_.str.7:                               ; @.str.7
	.asciz	"Can't erease block at 0x%x (%s)\n"

	.comm	_errno,4,2                      ; @errno
l_.str.8:                               ; @.str.8
	.asciz	"Rewriting block at 0x%x\n"

l_.str.9:                               ; @.str.9
	.asciz	"Error writing block (%s)\n"

l_.str.10:                              ; @.str.10
	.asciz	"Done.\n"

.subsections_via_symbols
