	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_MmAllocateHighestMemoryBelowAddress ## -- Begin function MmAllocateHighestMemoryBelowAddress
	.p2align	4, 0x90
_MmAllocateHighestMemoryBelowAddress:   ## @MmAllocateHighestMemoryBelowAddress
	.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
	pushq	%rax
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	testl	%edi, %edi
	je	LBB0_1
## %bb.3:
	movl	%edx, %r14d
	movq	%rsi, %r12
	movl	%edi, %r13d
	movq	_MM_PAGE_SIZE@GOTPCREL(%rip), %rbx
	movq	(%rbx), %rsi
	callq	_ROUND_UP
	movq	(%rbx), %rcx
	movq	%rax, %rdx
	orq	%rcx, %rdx
	shrq	$32, %rdx
	je	LBB0_4
## %bb.5:
	cqto
	idivq	%rcx
	movq	%rax, %r15
	jmp	LBB0_6
LBB0_1:
	leaq	L_.str(%rip), %rdi
	callq	_WARN
	leaq	L_.str.1(%rip), %rdi
	jmp	LBB0_2
LBB0_4:
                                        ## kill: def $eax killed $eax killed $rax
	xorl	%edx, %edx
	divl	%ecx
	movl	%eax, %r15d
LBB0_6:
	movq	_FreePagesInLookupTable@GOTPCREL(%rip), %rax
	cmpq	%r15, (%rax)
	jl	LBB0_7
## %bb.8:
	movq	%r12, %rax
	orq	%rcx, %rax
	shrq	$32, %rax
	je	LBB0_9
## %bb.10:
	movq	%r12, %rax
	cqto
	idivq	%rcx
	jmp	LBB0_11
LBB0_9:
	movl	%r12d, %eax
	xorl	%edx, %edx
	divl	%ecx
                                        ## kill: def $eax killed $eax def $rax
LBB0_11:
	movq	_PageLookupTableAddress@GOTPCREL(%rip), %rbx
	movl	(%rbx), %edi
	movq	_TotalPagesInLookupTable@GOTPCREL(%rip), %rcx
	movl	(%rcx), %esi
	movq	%r15, %rdx
	movq	%rax, %rcx
	callq	_MmFindAvailablePagesBeforePage
	testq	%rax, %rax
	je	LBB0_7
## %bb.12:
	movq	%rax, %r12
	movl	(%rbx), %edi
	movq	%rax, %rsi
	movq	%r15, %rdx
	movl	%r14d, %ecx
	callq	_MmAllocatePagesInLookupTable
	movq	_FreePagesInLookupTable@GOTPCREL(%rip), %rax
	subq	%r15, (%rax)
	movq	_MM_PAGE_SIZE@GOTPCREL(%rip), %rax
	movq	(%rax), %rbx
	imulq	%r12, %rbx
	movslq	%r13d, %r14
	leaq	L_.str.4(%rip), %rdi
	movq	%r14, %rsi
	movq	%r15, %rdx
	movq	%r12, %rcx
	xorl	%eax, %eax
	callq	_TRACE
	leaq	L_.str.5(%rip), %rdi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	_TRACE
	addq	%rbx, %r14
	movq	_PAGE_SHIFT@GOTPCREL(%rip), %rax
	movb	(%rax), %cl
	sarq	%cl, %r14
	movq	_LoaderPagesSpanned@GOTPCREL(%rip), %rax
	cmpq	(%rax), %r14
	jle	LBB0_14
## %bb.13:
	movq	%r14, (%rax)
	jmp	LBB0_14
LBB0_7:
	leaq	L_.str.2(%rip), %rdi
	movl	%r13d, %esi
	callq	_ERR
	leaq	L_.str.3(%rip), %rdi
LBB0_2:
	callq	_UiMessageBoxCritical
	xorl	%ebx, %ebx
LBB0_14:
	movq	%rbx, %rax
	addq	$8, %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	retq
	.cfi_endproc
                                        ## -- End function
	.section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
	.asciz	"MmAllocateHighestMemoryBelowAddress() called for 0 bytes. Returning NULL.\n"

L_.str.1:                               ## @.str.1
	.asciz	"Memory allocation failed: MmAllocateHighestMemoryBelowAddress() called for 0 bytes."

	.comm	_MM_PAGE_SIZE,8,3               ## @MM_PAGE_SIZE
	.comm	_FreePagesInLookupTable,8,3     ## @FreePagesInLookupTable
L_.str.2:                               ## @.str.2
	.asciz	"Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n"

L_.str.3:                               ## @.str.3
	.asciz	"Memory allocation failed: out of memory."

	.comm	_PageLookupTableAddress,4,2     ## @PageLookupTableAddress
	.comm	_TotalPagesInLookupTable,4,2    ## @TotalPagesInLookupTable
L_.str.4:                               ## @.str.4
	.asciz	"Allocated %d bytes (%d pages) of memory starting at page %d.\n"

L_.str.5:                               ## @.str.5
	.asciz	"Memory allocation pointer: 0x%x\n"

	.comm	_PAGE_SHIFT,8,3                 ## @PAGE_SHIFT
	.comm	_LoaderPagesSpanned,8,3         ## @LoaderPagesSpanned
.subsections_via_symbols

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_MmAllocateHighestMemoryBelowAddress ; -- Begin function MmAllocateHighestMemoryBelowAddress
	.p2align	2
_MmAllocateHighestMemoryBelowAddress:   ; @MmAllocateHighestMemoryBelowAddress
	.cfi_startproc
; %bb.0:
	sub	sp, sp, #96
	.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
	cbz	w0, LBB0_6
; %bb.1:
	mov	x20, x2
	mov	x22, x1
	mov	x19, x0
Lloh0:
	adrp	x23, _MM_PAGE_SIZE@GOTPAGE
Lloh1:
	ldr	x23, [x23, _MM_PAGE_SIZE@GOTPAGEOFF]
	ldr	x1, [x23]
	bl	_ROUND_UP
	ldr	x8, [x23]
	sdiv	x21, x0, x8
Lloh2:
	adrp	x24, _FreePagesInLookupTable@GOTPAGE
Lloh3:
	ldr	x24, [x24, _FreePagesInLookupTable@GOTPAGEOFF]
	ldr	x9, [x24]
	cmp	x9, x21
	b.lt	LBB0_5
; %bb.2:
Lloh4:
	adrp	x25, _PageLookupTableAddress@GOTPAGE
Lloh5:
	ldr	x25, [x25, _PageLookupTableAddress@GOTPAGEOFF]
	ldr	w0, [x25]
Lloh6:
	adrp	x9, _TotalPagesInLookupTable@GOTPAGE
Lloh7:
	ldr	x9, [x9, _TotalPagesInLookupTable@GOTPAGEOFF]
Lloh8:
	ldr	w1, [x9]
	sdiv	x3, x22, x8
	mov	x2, x21
	bl	_MmFindAvailablePagesBeforePage
	cbz	x0, LBB0_5
; %bb.3:
	mov	x22, x0
	ldr	w0, [x25]
	mov	x1, x22
	mov	x2, x21
	mov	x3, x20
	bl	_MmAllocatePagesInLookupTable
	ldr	x8, [x24]
	sub	x8, x8, x21
	str	x8, [x24]
	ldr	x8, [x23]
	mul	x20, x8, x22
	sxtw	x19, w19
	stp	x21, x22, [sp]
Lloh9:
	adrp	x0, l_.str.4@PAGE
Lloh10:
	add	x0, x0, l_.str.4@PAGEOFF
	mov	x1, x19
	bl	_TRACE
Lloh11:
	adrp	x0, l_.str.5@PAGE
Lloh12:
	add	x0, x0, l_.str.5@PAGEOFF
	mov	x1, x20
	bl	_TRACE
	add	x8, x20, x19
Lloh13:
	adrp	x9, _PAGE_SHIFT@GOTPAGE
Lloh14:
	ldr	x9, [x9, _PAGE_SHIFT@GOTPAGEOFF]
Lloh15:
	ldr	x9, [x9]
	asr	x8, x8, x9
Lloh16:
	adrp	x9, _LoaderPagesSpanned@GOTPAGE
Lloh17:
	ldr	x9, [x9, _LoaderPagesSpanned@GOTPAGEOFF]
	ldr	x10, [x9]
	cmp	x8, x10
	b.le	LBB0_8
; %bb.4:
	str	x8, [x9]
	b	LBB0_8
LBB0_5:
Lloh18:
	adrp	x0, l_.str.2@PAGE
Lloh19:
	add	x0, x0, l_.str.2@PAGEOFF
	mov	x1, x19
	bl	_ERR
Lloh20:
	adrp	x0, l_.str.3@PAGE
Lloh21:
	add	x0, x0, l_.str.3@PAGEOFF
	b	LBB0_7
LBB0_6:
Lloh22:
	adrp	x0, l_.str@PAGE
Lloh23:
	add	x0, x0, l_.str@PAGEOFF
	bl	_WARN
Lloh24:
	adrp	x0, l_.str.1@PAGE
Lloh25:
	add	x0, x0, l_.str.1@PAGEOFF
LBB0_7:
	bl	_UiMessageBoxCritical
	mov	x20, #0
LBB0_8:
	mov	x0, x20
	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
	add	sp, sp, #96
	ret
	.loh AdrpLdrGot	Lloh2, Lloh3
	.loh AdrpLdrGot	Lloh0, Lloh1
	.loh AdrpLdrGotLdr	Lloh6, Lloh7, Lloh8
	.loh AdrpLdrGot	Lloh4, Lloh5
	.loh AdrpLdrGot	Lloh16, Lloh17
	.loh AdrpLdrGotLdr	Lloh13, Lloh14, Lloh15
	.loh AdrpAdd	Lloh11, Lloh12
	.loh AdrpAdd	Lloh9, Lloh10
	.loh AdrpAdd	Lloh20, Lloh21
	.loh AdrpAdd	Lloh18, Lloh19
	.loh AdrpAdd	Lloh24, Lloh25
	.loh AdrpAdd	Lloh22, Lloh23
	.cfi_endproc
                                        ; -- End function
	.section	__TEXT,__cstring,cstring_literals
l_.str:                                 ; @.str
	.asciz	"MmAllocateHighestMemoryBelowAddress() called for 0 bytes. Returning NULL.\n"

l_.str.1:                               ; @.str.1
	.asciz	"Memory allocation failed: MmAllocateHighestMemoryBelowAddress() called for 0 bytes."

	.comm	_MM_PAGE_SIZE,8,3               ; @MM_PAGE_SIZE
	.comm	_FreePagesInLookupTable,8,3     ; @FreePagesInLookupTable
l_.str.2:                               ; @.str.2
	.asciz	"Memory allocation failed in MmAllocateHighestMemoryBelowAddress(). Not enough free memory to allocate %d bytes.\n"

l_.str.3:                               ; @.str.3
	.asciz	"Memory allocation failed: out of memory."

	.comm	_PageLookupTableAddress,4,2     ; @PageLookupTableAddress
	.comm	_TotalPagesInLookupTable,4,2    ; @TotalPagesInLookupTable
l_.str.4:                               ; @.str.4
	.asciz	"Allocated %d bytes (%d pages) of memory starting at page %d.\n"

l_.str.5:                               ; @.str.5
	.asciz	"Memory allocation pointer: 0x%x\n"

	.comm	_PAGE_SHIFT,8,3                 ; @PAGE_SHIFT
	.comm	_LoaderPagesSpanned,8,3         ; @LoaderPagesSpanned
.subsections_via_symbols
