	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	4, 0x90                         ## -- Begin function InsertCartridge
_InsertCartridge:                       ## @InsertCartridge
	.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	$32, %rsp
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %r14
	movq	%rdi, %rbx
	movq	___stack_chk_guard@GOTPCREL(%rip), %rax
	movq	(%rax), %rax
	movq	%rax, -40(%rbp)
	leaq	L_.str(%rip), %rsi
	callq	_fopen
	testq	%rax, %rax
	je	LBB0_1
## %bb.2:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	_Util_flen
	movl	%eax, %r12d
	movq	%r15, %rdi
	callq	_Util_rewind
	movq	(%r14), %rdi
	cmpq	%rbx, %rdi
	je	LBB0_4
## %bb.3:
	movq	%rbx, %rsi
	callq	_strcpy
LBB0_4:
	testl	$1023, %r12d                    ## imm = 0x3FF
	je	LBB0_5
## %bb.16:
	leaq	-64(%rbp), %rdi
	movl	$1, %esi
	movl	$16, %edx
	movq	%r15, %rcx
	callq	_fread
	cmpl	$15, %eax
	jg	LBB0_18
## %bb.17:
	leaq	L_.str.1(%rip), %rdi
	callq	_Log_print
LBB0_18:
	movdqa	-64(%rbp), %xmm0
	movd	%xmm0, %eax
	cmpl	$1414676803, %eax               ## imm = 0x54524143
	jne	LBB0_26
## %bb.19:
	movzbl	-60(%rbp), %eax
	shlq	$24, %rax
	movsbl	-59(%rbp), %ecx
	shll	$16, %ecx
	orq	%rax, %rcx
	movsbl	-58(%rbp), %eax
	shll	$8, %eax
	movsbl	-57(%rbp), %ebx
	orq	%rax, %rbx
	orq	%rcx, %rbx
	testl	%ebx, %ebx
	jle	LBB0_26
## %bb.20:
	movq	_CARTRIDGE_LAST_SUPPORTED@GOTPCREL(%rip), %rax
	cmpl	(%rax), %ebx
	jg	LBB0_26
## %bb.21:
	movq	_CARTRIDGE_kb@GOTPCREL(%rip), %rax
	movq	(%rax), %rax
	movl	(%rax,%rbx,4), %r12d
	movl	%r12d, 20(%r14)
	shll	$10, %r12d
	movl	%r12d, %edi
	callq	_Util_malloc
	movq	%rax, 8(%r14)
	movq	%rax, %rdi
	movl	$1, %esi
	movl	%r12d, %edx
	movq	%r15, %rcx
	callq	_fread
	cmpl	%r12d, %eax
	jge	LBB0_23
## %bb.22:
	leaq	L_.str.1(%rip), %rdi
	callq	_Log_print
LBB0_23:
	movq	%r15, %rdi
	callq	_fclose
	movl	-56(%rbp), %eax
	shll	$24, %eax
	movsbl	-55(%rbp), %ecx
	shll	$16, %ecx
	orl	%eax, %ecx
	movsbl	-54(%rbp), %eax
	shll	$8, %eax
	movsbl	-53(%rbp), %r15d
	orl	%eax, %r15d
	orl	%ecx, %r15d
	movl	%ebx, 16(%r14)
	movq	8(%r14), %rdi
	movl	%r12d, %esi
	callq	_CARTRIDGE_Checksum
	xorl	%r12d, %r12d
	cmpl	%eax, %r15d
	je	LBB0_25
## %bb.24:
	movq	_CARTRIDGE_BAD_CHECKSUM@GOTPCREL(%rip), %rax
	movl	(%rax), %r12d
LBB0_25:
	movq	%r14, %rdi
	callq	_InitCartridge
	jmp	LBB0_29
LBB0_1:
	movq	_CARTRIDGE_CANT_OPEN@GOTPCREL(%rip), %rax
	jmp	LBB0_28
LBB0_26:
	movq	%r15, %rdi
	callq	_fclose
	jmp	LBB0_27
LBB0_5:
	movl	%r12d, %edi
	callq	_Util_malloc
	movq	%rax, 8(%r14)
	movq	%rax, %rdi
	movl	$1, %esi
	movl	%r12d, %edx
	movq	%r15, %rcx
	callq	_fread
	cmpl	%r12d, %eax
	jge	LBB0_7
## %bb.6:
	leaq	L_.str.1(%rip), %rdi
	callq	_Log_print
LBB0_7:
	movq	%r15, %rdi
	callq	_fclose
	movq	_CARTRIDGE_NONE@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, 16(%r14)
	sarl	$10, %r12d
	movl	%r12d, 20(%r14)
	movq	_CARTRIDGE_LAST_SUPPORTED@GOTPCREL(%rip), %rcx
	movl	(%rcx), %ecx
	testl	%ecx, %ecx
	jle	LBB0_15
## %bb.8:
	movq	_CARTRIDGE_kb@GOTPCREL(%rip), %rdx
	movq	(%rdx), %rdx
	incq	%rcx
	movl	$1, %esi
	movl	%eax, %edi
	jmp	LBB0_9
	.p2align	4, 0x90
LBB0_12:                                ##   in Loop: Header=BB0_9 Depth=1
	incq	%rsi
	cmpq	%rsi, %rcx
	je	LBB0_13
LBB0_9:                                 ## =>This Inner Loop Header: Depth=1
	cmpl	%r12d, (%rdx,%rsi,4)
	jne	LBB0_12
## %bb.10:                              ##   in Loop: Header=BB0_9 Depth=1
	cmpl	%eax, %edi
	jne	LBB0_31
## %bb.11:                              ##   in Loop: Header=BB0_9 Depth=1
	movl	%esi, 16(%r14)
	movl	%esi, %edi
	jmp	LBB0_12
LBB0_13:
	cmpl	%eax, %edi
	jne	LBB0_14
LBB0_15:
	movq	8(%r14), %rdi
	callq	_free
	movq	$0, 8(%r14)
LBB0_27:
	movq	_CARTRIDGE_BAD_FORMAT@GOTPCREL(%rip), %rax
LBB0_28:
	movl	(%rax), %r12d
LBB0_29:
	movq	___stack_chk_guard@GOTPCREL(%rip), %rax
	movq	(%rax), %rax
	cmpq	-40(%rbp), %rax
	jne	LBB0_32
## %bb.30:
	movl	%r12d, %eax
	addq	$32, %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_31:
	movq	_CARTRIDGE_UNKNOWN@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, 16(%r14)
	jmp	LBB0_29
LBB0_14:
	movq	%r14, %rdi
	callq	_InitCartridge
	xorl	%r12d, %r12d
	jmp	LBB0_29
LBB0_32:
	callq	___stack_chk_fail
	.cfi_endproc
                                        ## -- End function
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"rb"

	.comm	_CARTRIDGE_CANT_OPEN,4,2        ## @CARTRIDGE_CANT_OPEN
L_.str.1:                               ## @.str.1
	.asciz	"Error reading cartridge.\n"

	.comm	_CARTRIDGE_NONE,4,2             ## @CARTRIDGE_NONE
	.comm	_CARTRIDGE_LAST_SUPPORTED,4,2   ## @CARTRIDGE_LAST_SUPPORTED
	.comm	_CARTRIDGE_kb,8,3               ## @CARTRIDGE_kb
	.comm	_CARTRIDGE_UNKNOWN,4,2          ## @CARTRIDGE_UNKNOWN
	.comm	_CARTRIDGE_BAD_FORMAT,4,2       ## @CARTRIDGE_BAD_FORMAT
	.comm	_CARTRIDGE_BAD_CHECKSUM,4,2     ## @CARTRIDGE_BAD_CHECKSUM
	.no_dead_strip	_InsertCartridge
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.p2align	2                               ; -- Begin function InsertCartridge
_InsertCartridge:                       ; @InsertCartridge
	.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	x19, x1
	mov	x22, x0
Lloh0:
	adrp	x8, ___stack_chk_guard@GOTPAGE
Lloh1:
	ldr	x8, [x8, ___stack_chk_guard@GOTPAGEOFF]
Lloh2:
	ldr	x8, [x8]
	str	x8, [sp, #24]
Lloh3:
	adrp	x1, l_.str@PAGE
Lloh4:
	add	x1, x1, l_.str@PAGEOFF
	bl	_fopen
	cbz	x0, LBB0_9
; %bb.1:
	mov	x20, x0
	bl	_Util_flen
	mov	x21, x0
	mov	x0, x20
	bl	_Util_rewind
	ldr	x0, [x19]
	cmp	x0, x22
	b.eq	LBB0_3
; %bb.2:
	mov	x1, x22
	bl	_strcpy
LBB0_3:
	tst	w21, #0x3ff
	b.eq	LBB0_10
; %bb.4:
	add	x0, sp, #8
	mov	w1, #1
	mov	w2, #16
	mov	x3, x20
	bl	_fread
	cmp	w0, #15
	b.gt	LBB0_6
; %bb.5:
Lloh5:
	adrp	x0, l_.str.1@PAGE
Lloh6:
	add	x0, x0, l_.str.1@PAGEOFF
	bl	_Log_print
LBB0_6:
	ldr	s0, [sp, #8]
	ushll.8h	v0, v0, #0
	xtn.8b	v0, v0
	fmov	w8, s0
	mov	w9, #16707
	movk	w9, #21586, lsl #16
	cmp	w8, w9
	b.ne	LBB0_8
; %bb.7:
	ldrb	w8, [sp, #12]
	ldrsb	w9, [sp, #13]
	lsl	w9, w9, #16
	orr	x8, x9, x8, lsl #24
	ldrsb	w9, [sp, #14]
	lsl	w9, w9, #8
	orr	x8, x8, x9
	ldrsb	w9, [sp, #15]
	orr	x22, x8, x9
Lloh7:
	adrp	x8, _CARTRIDGE_LAST_SUPPORTED@GOTPAGE
Lloh8:
	ldr	x8, [x8, _CARTRIDGE_LAST_SUPPORTED@GOTPAGEOFF]
Lloh9:
	ldr	w8, [x8]
	cmp	w22, #1
	ccmp	w22, w8, #0, ge
	b.le	LBB0_18
LBB0_8:
	mov	x0, x20
	bl	_fclose
	b	LBB0_23
LBB0_9:
Lloh10:
	adrp	x8, _CARTRIDGE_CANT_OPEN@GOTPAGE
Lloh11:
	ldr	x8, [x8, _CARTRIDGE_CANT_OPEN@GOTPAGEOFF]
	b	LBB0_24
LBB0_10:
	mov	x0, x21
	bl	_Util_malloc
	str	x0, [x19, #8]
	mov	w1, #1
	mov	x2, x21
	mov	x3, x20
	bl	_fread
	cmp	w0, w21
	b.ge	LBB0_12
; %bb.11:
Lloh12:
	adrp	x0, l_.str.1@PAGE
Lloh13:
	add	x0, x0, l_.str.1@PAGEOFF
	bl	_Log_print
LBB0_12:
	mov	x0, x20
	bl	_fclose
Lloh14:
	adrp	x8, _CARTRIDGE_NONE@GOTPAGE
Lloh15:
	ldr	x8, [x8, _CARTRIDGE_NONE@GOTPAGEOFF]
Lloh16:
	ldr	w8, [x8]
	asr	w20, w21, #10
	stp	w8, w20, [x19, #16]
Lloh17:
	adrp	x9, _CARTRIDGE_LAST_SUPPORTED@GOTPAGE
Lloh18:
	ldr	x9, [x9, _CARTRIDGE_LAST_SUPPORTED@GOTPAGEOFF]
Lloh19:
	ldr	w10, [x9]
	cmp	w10, #1
	b.lt	LBB0_22
; %bb.13:
Lloh20:
	adrp	x9, _CARTRIDGE_kb@GOTPAGE
Lloh21:
	ldr	x9, [x9, _CARTRIDGE_kb@GOTPAGEOFF]
Lloh22:
	ldr	x9, [x9]
	add	x10, x10, #1
	mov	w11, #1
	mov	x12, x8
	b	LBB0_15
LBB0_14:                                ;   in Loop: Header=BB0_15 Depth=1
	add	x11, x11, #1
	cmp	x10, x11
	b.eq	LBB0_21
LBB0_15:                                ; =>This Inner Loop Header: Depth=1
	ldr	w13, [x9, x11, lsl #2]
	cmp	w13, w20
	b.ne	LBB0_14
; %bb.16:                               ;   in Loop: Header=BB0_15 Depth=1
	cmp	w12, w8
	b.ne	LBB0_27
; %bb.17:                               ;   in Loop: Header=BB0_15 Depth=1
	str	w11, [x19, #16]
	mov	x12, x11
	b	LBB0_14
LBB0_18:
Lloh23:
	adrp	x8, _CARTRIDGE_kb@GOTPAGE
Lloh24:
	ldr	x8, [x8, _CARTRIDGE_kb@GOTPAGEOFF]
Lloh25:
	ldr	x8, [x8]
	ldr	w8, [x8, x22, lsl #2]
	lsl	w21, w8, #10
	str	w8, [x19, #20]
	mov	x0, x21
	bl	_Util_malloc
	str	x0, [x19, #8]
	mov	w1, #1
	mov	x2, x21
	mov	x3, x20
	bl	_fread
	cmp	w0, w21
	b.ge	LBB0_20
; %bb.19:
Lloh26:
	adrp	x0, l_.str.1@PAGE
Lloh27:
	add	x0, x0, l_.str.1@PAGEOFF
	bl	_Log_print
LBB0_20:
	mov	x0, x20
	bl	_fclose
	ldrb	w8, [sp, #16]
	ldrsb	w9, [sp, #17]
	lsl	w9, w9, #16
	orr	w8, w9, w8, lsl #24
	ldrsb	w9, [sp, #18]
	orr	w8, w8, w9, lsl #8
	ldrsb	w9, [sp, #19]
	orr	w20, w8, w9
	str	w22, [x19, #16]
	ldr	x0, [x19, #8]
	mov	x1, x21
	bl	_CARTRIDGE_Checksum
Lloh28:
	adrp	x8, _CARTRIDGE_BAD_CHECKSUM@GOTPAGE
Lloh29:
	ldr	x8, [x8, _CARTRIDGE_BAD_CHECKSUM@GOTPAGEOFF]
Lloh30:
	ldr	w8, [x8]
	cmp	w20, w0
	csel	w20, wzr, w8, eq
	mov	x0, x19
	bl	_InitCartridge
	b	LBB0_25
LBB0_21:
	cmp	w12, w8
	b.ne	LBB0_28
LBB0_22:
	ldr	x0, [x19, #8]
	bl	_free
	str	xzr, [x19, #8]
LBB0_23:
Lloh31:
	adrp	x8, _CARTRIDGE_BAD_FORMAT@GOTPAGE
Lloh32:
	ldr	x8, [x8, _CARTRIDGE_BAD_FORMAT@GOTPAGEOFF]
LBB0_24:
	ldr	w20, [x8]
LBB0_25:
	ldr	x8, [sp, #24]
Lloh33:
	adrp	x9, ___stack_chk_guard@GOTPAGE
Lloh34:
	ldr	x9, [x9, ___stack_chk_guard@GOTPAGEOFF]
Lloh35:
	ldr	x9, [x9]
	cmp	x9, x8
	b.ne	LBB0_29
; %bb.26:
	mov	x0, x20
	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
LBB0_27:
Lloh36:
	adrp	x8, _CARTRIDGE_UNKNOWN@GOTPAGE
Lloh37:
	ldr	x8, [x8, _CARTRIDGE_UNKNOWN@GOTPAGEOFF]
Lloh38:
	ldr	w8, [x8]
	str	w8, [x19, #16]
	b	LBB0_25
LBB0_28:
	mov	x0, x19
	bl	_InitCartridge
	mov	w20, #0
	b	LBB0_25
LBB0_29:
	bl	___stack_chk_fail
	.loh AdrpAdd	Lloh3, Lloh4
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpAdd	Lloh5, Lloh6
	.loh AdrpLdrGotLdr	Lloh7, Lloh8, Lloh9
	.loh AdrpLdrGot	Lloh10, Lloh11
	.loh AdrpAdd	Lloh12, Lloh13
	.loh AdrpLdrGotLdr	Lloh17, Lloh18, Lloh19
	.loh AdrpLdrGotLdr	Lloh14, Lloh15, Lloh16
	.loh AdrpLdrGotLdr	Lloh20, Lloh21, Lloh22
	.loh AdrpLdrGotLdr	Lloh23, Lloh24, Lloh25
	.loh AdrpAdd	Lloh26, Lloh27
	.loh AdrpLdrGotLdr	Lloh28, Lloh29, Lloh30
	.loh AdrpLdrGot	Lloh31, Lloh32
	.loh AdrpLdrGotLdr	Lloh33, Lloh34, Lloh35
	.loh AdrpLdrGotLdr	Lloh36, Lloh37, Lloh38
	.cfi_endproc
                                        ; -- End function
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"rb"

	.comm	_CARTRIDGE_CANT_OPEN,4,2        ; @CARTRIDGE_CANT_OPEN
l_.str.1:                               ; @.str.1
	.asciz	"Error reading cartridge.\n"

	.comm	_CARTRIDGE_NONE,4,2             ; @CARTRIDGE_NONE
	.comm	_CARTRIDGE_LAST_SUPPORTED,4,2   ; @CARTRIDGE_LAST_SUPPORTED
	.comm	_CARTRIDGE_kb,8,3               ; @CARTRIDGE_kb
	.comm	_CARTRIDGE_UNKNOWN,4,2          ; @CARTRIDGE_UNKNOWN
	.comm	_CARTRIDGE_BAD_FORMAT,4,2       ; @CARTRIDGE_BAD_FORMAT
	.comm	_CARTRIDGE_BAD_CHECKSUM,4,2     ; @CARTRIDGE_BAD_CHECKSUM
	.no_dead_strip	_InsertCartridge
.subsections_via_symbols
