	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_via_mem_alloc                  ## -- Begin function via_mem_alloc
	.p2align	4, 0x90
_via_mem_alloc:                         ## @via_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	$24, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	(%rsi), %rax
	movq	_VIA_MEM_AGP@GOTPCREL(%rip), %r12
	cmpq	(%r12), %rax
	jle	LBB0_3
## %bb.1:
	leaq	L_.str(%rip), %rdi
	callq	_DRM_ERROR
	jmp	LBB0_2
LBB0_3:
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	8(%rdi), %r13
	movq	(%rdx), %r15
	callq	_mutex_lock
	movq	(%rbx), %rax
	movq	_VIA_MEM_VIDEO@GOTPCREL(%rip), %rdx
	xorl	%ecx, %ecx
	cmpq	(%rdx), %rax
	setne	%cl
	cmpq	$0, (%r13,%rcx,8)
	je	LBB0_4
## %bb.5:
	movq	%r15, -56(%rbp)                 ## 8-byte Spill
	movq	_GFP_KERNEL@GOTPCREL(%rip), %rax
	movl	(%rax), %esi
	movl	$16, %edi
	callq	_kzalloc
	movq	%rax, %r15
	testq	%rax, %rax
	je	LBB0_6
## %bb.7:
	movq	_VIA_MM_ALIGN_MASK@GOTPCREL(%rip), %rax
	movq	(%rax), %rdx
	addq	8(%rbx), %rdx
	movq	_VIA_MM_ALIGN_SHIFT@GOTPCREL(%rip), %rax
	movb	(%rax), %cl
	shrq	%cl, %rdx
	movq	(%rbx), %rax
	xorl	%ecx, %ecx
	cmpq	(%r12), %rax
	sete	%cl
	leaq	36(,%rcx,4), %rdi
	addq	%r13, %rdi
	movq	%r15, %rsi
	callq	_drm_mm_insert_node
	movl	%eax, %r12d
	testl	%eax, %eax
	jne	LBB0_11
## %bb.8:
	movq	%r13, -48(%rbp)                 ## 8-byte Spill
	leaq	32(%r13), %rdi
	movq	_GFP_KERNEL@GOTPCREL(%rip), %rax
	movl	(%rax), %r8d
	xorl	%r13d, %r13d
	movq	%r15, %rsi
	movl	$1, %edx
	xorl	%ecx, %ecx
	callq	_idr_alloc
	movl	%eax, %r12d
	movq	%r15, %rdi
	testl	%eax, %eax
	js	LBB0_10
## %bb.9:
	addq	$8, %rdi
	movq	-56(%rbp), %rsi                 ## 8-byte Reload
	callq	_list_add
	movq	%r14, %rdi
	callq	_mutex_unlock
	movq	(%rbx), %rax
	xorl	%edx, %edx
	movq	_VIA_MEM_VIDEO@GOTPCREL(%rip), %rcx
	cmpq	(%rcx), %rax
	sete	%dl
	movq	(%r15), %rax
	movq	_VIA_MM_ALIGN_SHIFT@GOTPCREL(%rip), %rcx
	movb	(%rcx), %cl
	shlq	%cl, %rax
	movq	-48(%rbp), %rcx                 ## 8-byte Reload
	addq	16(%rcx,%rdx,8), %rax
	movq	%rax, 24(%rbx)
	movl	%r12d, 16(%rbx)
	jmp	LBB0_12
LBB0_4:
	leaq	L_.str.1(%rip), %rdi
	callq	_DRM_ERROR
	movq	%r14, %rdi
	callq	_mutex_unlock
LBB0_2:
	movq	_EINVAL@GOTPCREL(%rip), %rax
	xorl	%r13d, %r13d
	subl	(%rax), %r13d
	jmp	LBB0_12
LBB0_6:
	movq	_ENOMEM@GOTPCREL(%rip), %rax
	xorl	%r12d, %r12d
	subl	(%rax), %r12d
LBB0_11:
	movq	%r15, %rdi
	callq	_kfree
	movq	%r14, %rdi
	callq	_mutex_unlock
	movq	$0, 24(%rbx)
	movq	$0, 8(%rbx)
	movl	$0, 16(%rbx)
	leaq	L_.str.2(%rip), %rdi
	callq	_DRM_DEBUG
	movl	%r12d, %r13d
LBB0_12:
	movl	%r13d, %eax
	addq	$24, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
LBB0_10:
	callq	_drm_mm_remove_node
	jmp	LBB0_11
	.cfi_endproc
                                        ## -- End function
	.comm	_VIA_MEM_AGP,8,3                ## @VIA_MEM_AGP
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"Unknown memory type allocation\n"

	.comm	_EINVAL,4,2                     ## @EINVAL
	.comm	_VIA_MEM_VIDEO,8,3              ## @VIA_MEM_VIDEO
L_.str.1:                               ## @.str.1
	.asciz	"Attempt to allocate from uninitialized memory manager.\n"

	.comm	_GFP_KERNEL,4,2                 ## @GFP_KERNEL
	.comm	_ENOMEM,4,2                     ## @ENOMEM
	.comm	_VIA_MM_ALIGN_MASK,8,3          ## @VIA_MM_ALIGN_MASK
	.comm	_VIA_MM_ALIGN_SHIFT,8,3         ## @VIA_MM_ALIGN_SHIFT
L_.str.2:                               ## @.str.2
	.asciz	"Video memory allocation failed\n"

.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_via_mem_alloc                  ; -- Begin function via_mem_alloc
	.p2align	2
_via_mem_alloc:                         ; @via_mem_alloc
	.cfi_startproc
; %bb.0:
	stp	x28, x27, [sp, #-96]!           ; 16-byte Folded Spill
	.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
	.cfi_offset w27, -88
	.cfi_offset w28, -96
	ldr	x8, [x1]
Lloh0:
	adrp	x22, _VIA_MEM_AGP@GOTPAGE
Lloh1:
	ldr	x22, [x22, _VIA_MEM_AGP@GOTPAGEOFF]
	ldr	x9, [x22]
	cmp	x8, x9
	b.le	LBB0_2
; %bb.1:
Lloh2:
	adrp	x0, l_.str@PAGE
Lloh3:
	add	x0, x0, l_.str@PAGEOFF
	bl	_DRM_ERROR
	b	LBB0_8
LBB0_2:
	mov	x19, x1
	mov	x20, x0
	ldr	x24, [x0, #8]
	ldr	x23, [x2]
	bl	_mutex_lock
Lloh4:
	adrp	x25, _VIA_MEM_VIDEO@GOTPAGE
Lloh5:
	ldr	x25, [x25, _VIA_MEM_VIDEO@GOTPAGEOFF]
	ldr	x8, [x19]
	ldr	x9, [x25]
	cmp	x8, x9
	cset	w8, ne
	ldr	x8, [x24, w8, uxtw #3]
	cbz	x8, LBB0_7
; %bb.3:
Lloh6:
	adrp	x27, _GFP_KERNEL@GOTPAGE
Lloh7:
	ldr	x27, [x27, _GFP_KERNEL@GOTPAGEOFF]
	ldr	w1, [x27]
	mov	w0, #16
	bl	_kzalloc
	mov	x21, x0
	cbz	x0, LBB0_9
; %bb.4:
Lloh8:
	adrp	x8, _VIA_MM_ALIGN_MASK@GOTPAGE
Lloh9:
	ldr	x8, [x8, _VIA_MM_ALIGN_MASK@GOTPAGEOFF]
Lloh10:
	ldr	x8, [x8]
	ldp	x10, x9, [x19]
	add	x8, x8, x9
Lloh11:
	adrp	x26, _VIA_MM_ALIGN_SHIFT@GOTPAGE
Lloh12:
	ldr	x26, [x26, _VIA_MM_ALIGN_SHIFT@GOTPAGEOFF]
	ldr	x9, [x26]
	lsr	x2, x8, x9
	ldr	x8, [x22]
	add	x9, x24, #36
	add	x11, x24, #40
	cmp	x10, x8
	csel	x0, x11, x9, eq
	mov	x1, x21
	bl	_drm_mm_insert_node
	mov	x22, x0
	cbnz	w0, LBB0_10
; %bb.5:
	add	x0, x24, #32
	ldr	w4, [x27]
	mov	x1, x21
	mov	w2, #1
	mov	w3, #0
	bl	_idr_alloc
	mov	x22, x0
	tbnz	w0, #31, LBB0_12
; %bb.6:
	add	x0, x21, #8
	mov	x1, x23
	bl	_list_add
	mov	x0, x20
	bl	_mutex_unlock
	ldr	x8, [x19]
	ldr	x9, [x25]
	mov	w10, #16
	mov	w11, #24
	cmp	x8, x9
	csel	x8, x11, x10, eq
	ldr	x8, [x24, x8]
	ldr	x9, [x21]
	ldr	x10, [x26]
	lsl	x9, x9, x10
	add	x8, x9, x8
	str	x8, [x19, #24]
	str	w22, [x19, #16]
	mov	w22, #0
	b	LBB0_11
LBB0_7:
Lloh13:
	adrp	x0, l_.str.1@PAGE
Lloh14:
	add	x0, x0, l_.str.1@PAGEOFF
	bl	_DRM_ERROR
	mov	x0, x20
	bl	_mutex_unlock
LBB0_8:
Lloh15:
	adrp	x8, _EINVAL@GOTPAGE
Lloh16:
	ldr	x8, [x8, _EINVAL@GOTPAGEOFF]
Lloh17:
	ldr	w8, [x8]
	neg	w22, w8
	b	LBB0_11
LBB0_9:
Lloh18:
	adrp	x8, _ENOMEM@GOTPAGE
Lloh19:
	ldr	x8, [x8, _ENOMEM@GOTPAGEOFF]
Lloh20:
	ldr	w8, [x8]
	neg	w22, w8
LBB0_10:
	mov	x0, x21
	bl	_kfree
	mov	x0, x20
	bl	_mutex_unlock
	str	xzr, [x19, #24]
	str	xzr, [x19, #8]
	str	wzr, [x19, #16]
Lloh21:
	adrp	x0, l_.str.2@PAGE
Lloh22:
	add	x0, x0, l_.str.2@PAGEOFF
	bl	_DRM_DEBUG
LBB0_11:
	mov	x0, x22
	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
	ldp	x28, x27, [sp], #96             ; 16-byte Folded Reload
	ret
LBB0_12:
	mov	x0, x21
	bl	_drm_mm_remove_node
	b	LBB0_10
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpAdd	Lloh2, Lloh3
	.loh AdrpLdrGot	Lloh4, Lloh5
	.loh AdrpLdrGot	Lloh6, Lloh7
	.loh AdrpLdrGot	Lloh11, Lloh12
	.loh AdrpLdrGotLdr	Lloh8, Lloh9, Lloh10
	.loh AdrpAdd	Lloh13, Lloh14
	.loh AdrpLdrGotLdr	Lloh15, Lloh16, Lloh17
	.loh AdrpLdrGotLdr	Lloh18, Lloh19, Lloh20
	.loh AdrpAdd	Lloh21, Lloh22
	.cfi_endproc
                                        ; -- End function
	.comm	_VIA_MEM_AGP,8,3                ; @VIA_MEM_AGP
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"Unknown memory type allocation\n"

	.comm	_EINVAL,4,2                     ; @EINVAL
	.comm	_VIA_MEM_VIDEO,8,3              ; @VIA_MEM_VIDEO
l_.str.1:                               ; @.str.1
	.asciz	"Attempt to allocate from uninitialized memory manager.\n"

	.comm	_GFP_KERNEL,4,2                 ; @GFP_KERNEL
	.comm	_ENOMEM,4,2                     ; @ENOMEM
	.comm	_VIA_MM_ALIGN_MASK,8,3          ; @VIA_MM_ALIGN_MASK
	.comm	_VIA_MM_ALIGN_SHIFT,8,3         ; @VIA_MM_ALIGN_SHIFT
l_.str.2:                               ; @.str.2
	.asciz	"Video memory allocation failed\n"

.subsections_via_symbols
