	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_kd_read_packet                 ## -- Begin function kd_read_packet
	.p2align	4, 0x90
_kd_read_packet:                        ## @kd_read_packet
	.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	$48, %rsp
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%rsi, %r14
	movq	%rdi, %rbx
	movq	$0, (%rsi)
	leaq	-72(%rbp), %rsi
	movl	$32, %edx
	callq	_iob_read
	testq	%rax, %rax
	jle	LBB0_1
## %bb.2:
	leaq	-72(%rbp), %rdi
	callq	_kd_packet_is_valid
	testl	%eax, %eax
	je	LBB0_3
## %bb.4:
	movl	-64(%rbp), %edi
	addl	$32, %edi
	callq	_malloc
	testq	%rax, %rax
	je	LBB0_1
## %bb.5:
	movq	%rax, %r15
	leaq	-72(%rbp), %rsi
	movq	%rax, %rdi
	movl	$32, %edx
	callq	_memcpy
	movl	-64(%rbp), %edx
	testl	%edx, %edx
	je	LBB0_6
## %bb.7:
	leaq	128(%r15), %rsi
	movq	%rbx, %rdi
	callq	_iob_read
	movl	-64(%rbp), %esi
	jmp	LBB0_8
LBB0_1:
	movq	_KD_E_IOERR@GOTPCREL(%rip), %rax
	jmp	LBB0_17
LBB0_3:
	movq	-72(%rbp), %rsi
	leaq	L_.str(%rip), %rdi
	xorl	%eax, %eax
	callq	_eprintf
	jmp	LBB0_16
LBB0_6:
	xorl	%esi, %esi
LBB0_8:
	movq	-56(%rbp), %r12
	movq	%r15, %rdi
	subq	$-128, %rdi
	callq	_kd_data_checksum
	cmpq	%rax, %r12
	jne	LBB0_9
## %bb.10:
	movq	-72(%rbp), %rax
	movq	_KD_PACKET_DATA@GOTPCREL(%rip), %rcx
	cmpq	(%rcx), %rax
	jne	LBB0_13
## %bb.11:
	leaq	-36(%rbp), %rsi
	movq	%rbx, %rdi
	movl	$1, %edx
	callq	_iob_read
	cmpl	$170, -36(%rbp)
	jne	LBB0_14
## %bb.12:
	movq	_KD_PACKET_TYPE_ACKNOWLEDGE@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	movl	$-2049, %edx                    ## imm = 0xF7FF
	andl	24(%r15), %edx
	movq	%rbx, %rdi
	callq	_kd_send_ctrl_packet
LBB0_13:
	movq	%r15, (%r14)
	movq	_KD_E_OK@GOTPCREL(%rip), %rax
	jmp	LBB0_17
LBB0_9:
	leaq	L_.str.1(%rip), %rdi
	xorl	%eax, %eax
	callq	_eprintf
	jmp	LBB0_15
LBB0_14:
	leaq	L_str(%rip), %rdi
	callq	_puts
LBB0_15:
	movq	%r15, %rdi
	callq	_free
LBB0_16:
	movq	_KD_E_MALFORMED@GOTPCREL(%rip), %rax
LBB0_17:
	movl	(%rax), %eax
	addq	$48, %rsp
	popq	%rbx
	popq	%r12
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.comm	_KD_E_IOERR,4,2                 ## @KD_E_IOERR
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"invalid leader %08x\n"

	.comm	_KD_E_MALFORMED,4,2             ## @KD_E_MALFORMED
L_.str.1:                               ## @.str.1
	.asciz	"Checksum mismatch!\n"

	.comm	_KD_PACKET_DATA,8,3             ## @KD_PACKET_DATA
	.comm	_KD_PACKET_TYPE_ACKNOWLEDGE,4,2 ## @KD_PACKET_TYPE_ACKNOWLEDGE
	.comm	_KD_E_OK,4,2                    ## @KD_E_OK
L_str:                                  ## @str
	.asciz	"Missing trailer 0xAA"

.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_kd_read_packet                 ; -- Begin function kd_read_packet
	.p2align	2
_kd_read_packet:                        ; @kd_read_packet
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #96
	.cfi_def_cfa_offset 96
	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
	mov	x19, x1
	mov	x20, x0
	str	xzr, [x1]
	add	x1, sp, #16
	mov	w2, #32
	bl	_iob_read
	cmp	x0, #0
	b.le	LBB0_5
; %bb.1:
	add	x0, sp, #16
	bl	_kd_packet_is_valid
	cbz	w0, LBB0_6
; %bb.2:
	ldr	w8, [sp, #24]
	add	w0, w8, #32
	bl	_malloc
	cbz	x0, LBB0_5
; %bb.3:
	mov	x21, x0
	add	x1, sp, #16
	mov	w2, #32
	bl	_memcpy
	ldr	w2, [sp, #24]
	cbz	w2, LBB0_7
; %bb.4:
	add	x1, x21, #128
	mov	x0, x20
	bl	_iob_read
	ldr	w1, [sp, #24]
	b	LBB0_8
LBB0_5:
Lloh0:
	adrp	x8, _KD_E_IOERR@GOTPAGE
Lloh1:
	ldr	x8, [x8, _KD_E_IOERR@GOTPAGEOFF]
	b	LBB0_17
LBB0_6:
	ldr	x8, [sp, #16]
	str	x8, [sp]
Lloh2:
	adrp	x0, l_.str@PAGE
Lloh3:
	add	x0, x0, l_.str@PAGEOFF
	bl	_eprintf
	b	LBB0_16
LBB0_7:
	mov	w1, #0
LBB0_8:
	ldr	x22, [sp, #32]
	add	x0, x21, #128
	bl	_kd_data_checksum
	cmp	x22, x0
	b.ne	LBB0_13
; %bb.9:
	ldr	x8, [sp, #16]
Lloh4:
	adrp	x9, _KD_PACKET_DATA@GOTPAGE
Lloh5:
	ldr	x9, [x9, _KD_PACKET_DATA@GOTPAGEOFF]
Lloh6:
	ldr	x9, [x9]
	cmp	x8, x9
	b.ne	LBB0_12
; %bb.10:
	add	x1, sp, #12
	mov	x0, x20
	mov	w2, #1
	bl	_iob_read
	ldr	w8, [sp, #12]
	cmp	w8, #170
	b.ne	LBB0_14
; %bb.11:
Lloh7:
	adrp	x8, _KD_PACKET_TYPE_ACKNOWLEDGE@GOTPAGE
Lloh8:
	ldr	x8, [x8, _KD_PACKET_TYPE_ACKNOWLEDGE@GOTPAGEOFF]
Lloh9:
	ldr	w1, [x8]
	ldr	w8, [x21, #24]
	and	w2, w8, #0xfffff7ff
	mov	x0, x20
	bl	_kd_send_ctrl_packet
LBB0_12:
	str	x21, [x19]
Lloh10:
	adrp	x8, _KD_E_OK@GOTPAGE
Lloh11:
	ldr	x8, [x8, _KD_E_OK@GOTPAGEOFF]
	b	LBB0_17
LBB0_13:
Lloh12:
	adrp	x0, l_.str.1@PAGE
Lloh13:
	add	x0, x0, l_.str.1@PAGEOFF
	bl	_eprintf
	b	LBB0_15
LBB0_14:
Lloh14:
	adrp	x0, l_str@PAGE
Lloh15:
	add	x0, x0, l_str@PAGEOFF
	bl	_puts
LBB0_15:
	mov	x0, x21
	bl	_free
LBB0_16:
Lloh16:
	adrp	x8, _KD_E_MALFORMED@GOTPAGE
Lloh17:
	ldr	x8, [x8, _KD_E_MALFORMED@GOTPAGEOFF]
LBB0_17:
	ldr	w0, [x8]
	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
	add	sp, sp, #96
	ret
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpAdd	Lloh2, Lloh3
	.loh AdrpLdrGotLdr	Lloh4, Lloh5, Lloh6
	.loh AdrpLdrGotLdr	Lloh7, Lloh8, Lloh9
	.loh AdrpLdrGot	Lloh10, Lloh11
	.loh AdrpAdd	Lloh12, Lloh13
	.loh AdrpAdd	Lloh14, Lloh15
	.loh AdrpLdrGot	Lloh16, Lloh17
	.cfi_endproc
                                        ; -- End function
	.comm	_KD_E_IOERR,4,2                 ; @KD_E_IOERR
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"invalid leader %08x\n"

	.comm	_KD_E_MALFORMED,4,2             ; @KD_E_MALFORMED
l_.str.1:                               ; @.str.1
	.asciz	"Checksum mismatch!\n"

	.comm	_KD_PACKET_DATA,8,3             ; @KD_PACKET_DATA
	.comm	_KD_PACKET_TYPE_ACKNOWLEDGE,4,2 ; @KD_PACKET_TYPE_ACKNOWLEDGE
	.comm	_KD_E_OK,4,2                    ; @KD_E_OK
l_str:                                  ; @str
	.asciz	"Missing trailer 0xAA"

.subsections_via_symbols
