	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_bd_mem_alloc                   ## -- Begin function bd_mem_alloc
	.p2align	4, 0x90
_bd_mem_alloc:                          ## @bd_mem_alloc
	.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	$56, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movl	%esi, %r12d
	movq	_OBJ_TYPE_TAG@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	callq	_obj_lookup
	movl	$-1, %r14d
	testq	%rax, %rax
	je	LBB0_7
## %bb.1:
	movq	%rax, %rbx
	movq	_OBJ_TYPE_MD@GOTPCREL(%rip), %rax
	movl	(%rax), %edi
	callq	_obj_alloc
	testq	%rax, %rax
	je	LBB0_7
## %bb.2:
	movq	%rax, %r15
	leaq	-88(%rbp), %r13
	movq	%r13, %rdi
	xorl	%esi, %esi
	movl	$48, %edx
	callq	_memset
	movq	_PROTO_IOC_BUSDMA_MEM_ALLOC@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, -84(%rbp)
	movl	20(%rbx), %eax
	movl	%eax, -52(%rbp)
	movl	%r12d, -56(%rbp)
	movl	16(%rbx), %edi
	movq	_PROTO_IOC_BUSDMA@GOTPCREL(%rip), %r12
	movl	(%r12), %esi
	movq	%r13, %rdx
	callq	_ioctl
	cmpl	$-1, %eax
	je	LBB0_6
## %bb.3:
	movl	$1, (%r15)
	movl	16(%rbx), %eax
	movl	%eax, 16(%r15)
	movq	%rbx, 8(%r15)
	incl	(%rbx)
	movl	-48(%rbp), %eax
	movl	%eax, 20(%r15)
	xorl	%edi, %edi
	cmpl	$1, -80(%rbp)
	sete	%dil
	callq	_assert
	xorl	%edi, %edi
	cmpl	$1, -76(%rbp)
	sete	%dil
	callq	_assert
	movq	_BUSDMA_MD_PHYS@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	movq	-72(%rbp), %rdx
	movl	24(%rbx), %ecx
	movq	%r15, %rdi
	callq	_bd_md_add_seg
	movq	_BUSDMA_MD_BUS@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	movq	-64(%rbp), %rdx
	movl	24(%rbx), %ecx
	movq	%r15, %rdi
	callq	_bd_md_add_seg
	movq	_PROT_READ@GOTPCREL(%rip), %rax
	movq	_PROT_WRITE@GOTPCREL(%rip), %rcx
	movl	(%rcx), %edx
	orl	(%rax), %edx
	movl	24(%rbx), %esi
	movq	_MAP_NOCORE@GOTPCREL(%rip), %rax
	movq	_MAP_SHARED@GOTPCREL(%rip), %rcx
	movl	(%rcx), %ecx
	orl	(%rax), %ecx
	movl	16(%r15), %r8d
	movq	-72(%rbp), %r9
	xorl	%edi, %edi
	callq	_mmap
	movq	_MAP_FAILED@GOTPCREL(%rip), %rcx
	cmpq	(%rcx), %rax
	jne	LBB0_4
## %bb.5:
	leaq	-88(%rbp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	movl	$48, %edx
	callq	_memset
	movq	_PROTO_IOC_BUSDMA_MEM_FREE@GOTPCREL(%rip), %rax
	movl	(%rax), %eax
	movl	%eax, -84(%rbp)
	movl	20(%r15), %eax
	movl	%eax, -88(%rbp)
	movl	16(%r15), %edi
	movl	(%r12), %esi
	movq	%rbx, %rdx
	callq	_ioctl
	movq	8(%r15), %rax
	decl	(%rax)
LBB0_6:
	movq	%r15, %rdi
	callq	_obj_free
	jmp	LBB0_7
LBB0_4:
	movq	_BUSDMA_MD_VIRT@GOTPCREL(%rip), %rcx
	movl	(%rcx), %esi
	movl	24(%rbx), %ecx
	movq	%r15, %rdi
	movq	%rax, %rdx
	callq	_bd_md_add_seg
	movl	4(%r15), %r14d
LBB0_7:
	movl	%r14d, %eax
	addq	$56, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.comm	_OBJ_TYPE_TAG,4,2               ## @OBJ_TYPE_TAG
	.comm	_OBJ_TYPE_MD,4,2                ## @OBJ_TYPE_MD
	.comm	_PROTO_IOC_BUSDMA_MEM_ALLOC,4,2 ## @PROTO_IOC_BUSDMA_MEM_ALLOC
	.comm	_PROTO_IOC_BUSDMA,4,2           ## @PROTO_IOC_BUSDMA
	.comm	_BUSDMA_MD_PHYS,4,2             ## @BUSDMA_MD_PHYS
	.comm	_BUSDMA_MD_BUS,4,2              ## @BUSDMA_MD_BUS
	.comm	_PROT_READ,4,2                  ## @PROT_READ
	.comm	_PROT_WRITE,4,2                 ## @PROT_WRITE
	.comm	_MAP_NOCORE,4,2                 ## @MAP_NOCORE
	.comm	_MAP_SHARED,4,2                 ## @MAP_SHARED
	.comm	_MAP_FAILED,8,3                 ## @MAP_FAILED
	.comm	_BUSDMA_MD_VIRT,4,2             ## @BUSDMA_MD_VIRT
	.comm	_PROTO_IOC_BUSDMA_MEM_FREE,4,2  ## @PROTO_IOC_BUSDMA_MEM_FREE
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_bd_mem_alloc                   ; -- Begin function bd_mem_alloc
	.p2align	2
_bd_mem_alloc:                          ; @bd_mem_alloc
	.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	x21, x1
Lloh0:
	adrp	x8, _OBJ_TYPE_TAG@GOTPAGE
Lloh1:
	ldr	x8, [x8, _OBJ_TYPE_TAG@GOTPAGEOFF]
Lloh2:
	ldr	w1, [x8]
	bl	_obj_lookup
	cbz	x0, LBB0_6
; %bb.1:
	mov	x20, x0
Lloh3:
	adrp	x8, _OBJ_TYPE_MD@GOTPAGE
Lloh4:
	ldr	x8, [x8, _OBJ_TYPE_MD@GOTPAGEOFF]
Lloh5:
	ldr	w0, [x8]
	bl	_obj_alloc
	cbz	x0, LBB0_6
; %bb.2:
	mov	x19, x0
	mov	x0, sp
	mov	w1, #0
	mov	w2, #48
	bl	_memset
Lloh6:
	adrp	x8, _PROTO_IOC_BUSDMA_MEM_ALLOC@GOTPAGE
Lloh7:
	ldr	x8, [x8, _PROTO_IOC_BUSDMA_MEM_ALLOC@GOTPAGEOFF]
Lloh8:
	ldr	w8, [x8]
	ldr	w9, [x20, #20]
	stp	w21, w9, [sp, #32]
	str	w8, [sp, #4]
	ldr	w0, [x20, #16]
Lloh9:
	adrp	x21, _PROTO_IOC_BUSDMA@GOTPAGE
Lloh10:
	ldr	x21, [x21, _PROTO_IOC_BUSDMA@GOTPAGEOFF]
	ldr	w1, [x21]
	mov	x2, sp
	bl	_ioctl
	cmn	w0, #1
	b.eq	LBB0_5
; %bb.3:
	mov	w8, #1
	str	w8, [x19]
	ldr	w8, [x20, #16]
	str	w8, [x19, #16]
	str	x20, [x19, #8]
	ldr	w8, [x20]
	add	w8, w8, #1
	str	w8, [x20]
	ldr	w8, [sp, #40]
	ldr	w9, [sp, #8]
	str	w8, [x19, #20]
	cmp	w9, #1
	cset	w0, eq
	bl	_assert
	ldr	w8, [sp, #12]
	cmp	w8, #1
	cset	w0, eq
	bl	_assert
Lloh11:
	adrp	x8, _BUSDMA_MD_PHYS@GOTPAGE
Lloh12:
	ldr	x8, [x8, _BUSDMA_MD_PHYS@GOTPAGEOFF]
Lloh13:
	ldr	w1, [x8]
	ldr	x2, [sp, #16]
	ldr	w3, [x20, #24]
	mov	x0, x19
	bl	_bd_md_add_seg
Lloh14:
	adrp	x8, _BUSDMA_MD_BUS@GOTPAGE
Lloh15:
	ldr	x8, [x8, _BUSDMA_MD_BUS@GOTPAGEOFF]
Lloh16:
	ldr	w1, [x8]
	ldr	x2, [sp, #24]
	ldr	w3, [x20, #24]
	mov	x0, x19
	bl	_bd_md_add_seg
	ldr	w1, [x20, #24]
Lloh17:
	adrp	x8, _PROT_READ@GOTPAGE
Lloh18:
	ldr	x8, [x8, _PROT_READ@GOTPAGEOFF]
Lloh19:
	adrp	x9, _PROT_WRITE@GOTPAGE
Lloh20:
	ldr	x9, [x9, _PROT_WRITE@GOTPAGEOFF]
Lloh21:
	ldr	w8, [x8]
Lloh22:
	ldr	w9, [x9]
	orr	w2, w9, w8
Lloh23:
	adrp	x8, _MAP_NOCORE@GOTPAGE
Lloh24:
	ldr	x8, [x8, _MAP_NOCORE@GOTPAGEOFF]
Lloh25:
	ldr	w8, [x8]
Lloh26:
	adrp	x9, _MAP_SHARED@GOTPAGE
Lloh27:
	ldr	x9, [x9, _MAP_SHARED@GOTPAGEOFF]
Lloh28:
	ldr	w9, [x9]
	orr	w3, w9, w8
	ldr	w4, [x19, #16]
	ldr	x5, [sp, #16]
	mov	x0, #0
	bl	_mmap
Lloh29:
	adrp	x8, _MAP_FAILED@GOTPAGE
Lloh30:
	ldr	x8, [x8, _MAP_FAILED@GOTPAGEOFF]
Lloh31:
	ldr	x8, [x8]
	cmp	x0, x8
	b.ne	LBB0_8
; %bb.4:
	mov	x0, sp
	mov	w1, #0
	mov	w2, #48
	bl	_memset
Lloh32:
	adrp	x8, _PROTO_IOC_BUSDMA_MEM_FREE@GOTPAGE
Lloh33:
	ldr	x8, [x8, _PROTO_IOC_BUSDMA_MEM_FREE@GOTPAGEOFF]
Lloh34:
	ldr	w8, [x8]
	ldp	w0, w9, [x19, #16]
	stp	w9, w8, [sp]
	ldr	w1, [x21]
	mov	x2, sp
	bl	_ioctl
	ldr	x8, [x19, #8]
	ldr	w9, [x8]
	sub	w9, w9, #1
	str	w9, [x8]
LBB0_5:
	mov	x0, x19
	bl	_obj_free
LBB0_6:
	mov	w0, #-1
LBB0_7:
	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
LBB0_8:
	mov	x2, x0
Lloh35:
	adrp	x8, _BUSDMA_MD_VIRT@GOTPAGE
Lloh36:
	ldr	x8, [x8, _BUSDMA_MD_VIRT@GOTPAGEOFF]
Lloh37:
	ldr	w1, [x8]
	ldr	w3, [x20, #24]
	mov	x0, x19
	bl	_bd_md_add_seg
	ldr	w0, [x19, #4]
	b	LBB0_7
	.loh AdrpLdrGotLdr	Lloh0, Lloh1, Lloh2
	.loh AdrpLdrGotLdr	Lloh3, Lloh4, Lloh5
	.loh AdrpLdrGot	Lloh9, Lloh10
	.loh AdrpLdrGotLdr	Lloh6, Lloh7, Lloh8
	.loh AdrpLdrGotLdr	Lloh29, Lloh30, Lloh31
	.loh AdrpLdrGotLdr	Lloh26, Lloh27, Lloh28
	.loh AdrpLdrGotLdr	Lloh23, Lloh24, Lloh25
	.loh AdrpLdrGotLdr	Lloh19, Lloh20, Lloh22
	.loh AdrpLdrGotLdr	Lloh17, Lloh18, Lloh21
	.loh AdrpLdrGotLdr	Lloh14, Lloh15, Lloh16
	.loh AdrpLdrGotLdr	Lloh11, Lloh12, Lloh13
	.loh AdrpLdrGotLdr	Lloh32, Lloh33, Lloh34
	.loh AdrpLdrGotLdr	Lloh35, Lloh36, Lloh37
	.cfi_endproc
                                        ; -- End function
	.comm	_OBJ_TYPE_TAG,4,2               ; @OBJ_TYPE_TAG
	.comm	_OBJ_TYPE_MD,4,2                ; @OBJ_TYPE_MD
	.comm	_PROTO_IOC_BUSDMA_MEM_ALLOC,4,2 ; @PROTO_IOC_BUSDMA_MEM_ALLOC
	.comm	_PROTO_IOC_BUSDMA,4,2           ; @PROTO_IOC_BUSDMA
	.comm	_BUSDMA_MD_PHYS,4,2             ; @BUSDMA_MD_PHYS
	.comm	_BUSDMA_MD_BUS,4,2              ; @BUSDMA_MD_BUS
	.comm	_PROT_READ,4,2                  ; @PROT_READ
	.comm	_PROT_WRITE,4,2                 ; @PROT_WRITE
	.comm	_MAP_NOCORE,4,2                 ; @MAP_NOCORE
	.comm	_MAP_SHARED,4,2                 ; @MAP_SHARED
	.comm	_MAP_FAILED,8,3                 ; @MAP_FAILED
	.comm	_BUSDMA_MD_VIRT,4,2             ; @BUSDMA_MD_VIRT
	.comm	_PROTO_IOC_BUSDMA_MEM_FREE,4,2  ; @PROTO_IOC_BUSDMA_MEM_FREE
.subsections_via_symbols
