// File: UTSASRG[P]Guarder/./bigheap.hh
// Function: BigHeap::allocateAlignedAtBigHeap(unsigned long, unsigned long)
void * allocateAlignedAtBigHeap(size_t alignment, size_t size) {
		assert(IF_CANARY_CONDITION);

		size_t pageUpSize = alignup(alignment + size, PageSize);
		size_t slackSize = pageUpSize - size;
		bigObjectStatus * objStatus = (bigObjectStatus *)HeapAllocator::allocate(sizeof(bigObjectStatus));
		void * ptr = MM::mmapAllocatePrivate(pageUpSize, NULL);

		uintptr_t userStartPtr = (uintptr_t)ptr + slackSize;
		size_t residualBytes = userStartPtr % alignment;
		userStartPtr -= residualBytes;

		acquireGlobalLock();
    _xmap.insert((void *)userStartPtr, sizeof(void *), objStatus);
		releaseGlobalLock();

		objStatus->actualStart = ptr;
		objStatus->userStart = (void *)userStartPtr;
		objStatus->pageUpSize = pageUpSize;
		objStatus->usableSize = size + residualBytes;
		objStatus->size = size;

		PRDBG("BigHeap returning 0x%lx (begins @ %p), size %zu (actual %zu, usable %zu)",
						userStartPtr, ptr, size, pageUpSize, objStatus->usableSize);
		return (void *)userStartPtr;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x80000, -0x28(%rbp)   # imm = 0x80000
jbe 0x7e2e
jmp 0x7e4d
leaq 0x593f(%rip), %rdi      # 0xd774
leaq 0x594c(%rip), %rsi      # 0xd788
movl $0x55, %edx
leaq 0x594d(%rip), %rcx      # 0xd795
callq 0x5300
movq -0x20(%rbp), %rdi
addq -0x28(%rbp), %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x59b0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x28, %edi
callq 0x5530
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x55d0
movq -0x68(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x20(%rbp)
movq %rdx, -0x58(%rbp)
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x50(%rbp)
callq 0x51d0
movq -0x68(%rbp), %rdi
addq $0x10, %rdi
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rcx
leaq -0x60(%rbp), %rsi
movl $0x8, %edx
callq 0x52c0
movq -0x68(%rbp), %rdi
callq 0x5040
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
addq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
callq 0x52d0
movq %rax, -0x78(%rbp)
callq 0x5400
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movq -0x50(%rbp), %r14
movq -0x48(%rbp), %rbx
movq -0x28(%rbp), %r11
movq -0x30(%rbp), %r10
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movl $0x1000, %esi           # imm = 0x1000
leaq 0x5863(%rip), %rdx      # 0xd7cd
leaq 0x5817(%rip), %r8       # 0xd788
movl $0x6b, %r9d
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x57e0
callq 0x52d0
movq %rax, -0x70(%rbp)
callq 0x52d0
movq %rax, %rdi
callq 0x51e0
movq -0x70(%rbp), %rsi
movq %rax, %rdx
movl $0x2, %edi
callq 0x5160
movq -0x50(%rbp), %rax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)