// File: /workspace/github_c_makefile_star2_O2/USArmyResearchLab[P]ARL_OpenSHMEM/src/xmalloc.c
// Function: imalloc
static void *
imalloc( struct __xmem_struct* xm, size_t size)
{
    void *result;

    if ((size + xm->malloc_pagesize) < size)	/* Check for overflow */
	result = NULL;
    else if ((size + xm->malloc_pagesize) >= (uintptr_t)xm->page_dir)
	result = NULL;
    else if (size <= malloc_maxsize)
	result = malloc_bytes(xm, size);
    else
	result = malloc_pages(xm, size);

    if (malloc_abort && result == NULL)
	wrterror("allocation failed.\n");

    if (malloc_zero && result != NULL)
	memset(result, 0, size);

    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq (%rdi), %rsi
movq %rsi, %rcx
addq %rbx, %rcx
jb 0x2b30
movq %rdi, %r15
movq 0x30(%rdi), %rax
cmpq %rax, %rcx
jae 0x2b30
movq %rsi, %rcx
shrq %rcx
cmpq %rbx, %rcx
jae 0x29c4
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2bb3
movq %rax, %r15
jmp 0x2b33
cmpq $0x11, %rbx
pushq $0x10
popq %rcx
cmovaeq %rbx, %rcx
decq %rcx
pushq $0x1
popq %r14
cmpq $0x2, %rcx
jb 0x29e4
shrq %rcx
incq %r14
jmp 0x29d6
movq (%rax,%r14,8), %r12
testq %r12, %r12
je 0x2a5f
pushq $0x1
popq %rcx
leaq 0x18(%r12), %rdx
pushq $-0x20
popq %r15
movl (%rdx), %esi
addq $0x4, %rdx
addq $0x20, %r15
testl %esi, %esi
je 0x29f9
jmp 0x2a0e
addl %ecx, %ecx
incq %r15
testl %esi, %ecx
je 0x2a09
xorl %esi, %ecx
movl %ecx, -0x4(%rdx)
decw 0x14(%r12)
jne 0x2a2c
movq (%r12), %rcx
movq %rcx, (%rax,%r14,8)
andq $0x0, (%r12)
movb 0x12(%r12), %cl
shlq %cl, %r15
cmpb $0x1, 0x3a59(%rip)      # 0x6494
jne 0x2a55
movq 0x8(%r12), %rdi
addq %r15, %rdi
movzwl 0x10(%r12), %edx
movl $0xd0, %esi
callq 0x1130
addq 0x8(%r12), %r15
jmp 0x2b33
movq %r15, %rdi
callq 0x2bb3
testq %rax, %rax
je 0x2b30
movq %rax, %r12
movq (%r15), %rbp
movl %r14d, %ecx
shrq %cl, %rbp
leaq 0x1f(%rbp), %rax
shrq $0x5, %rax
leaq 0x18(,%rax,4), %r13
movq %r13, %rdi
callq 0x11b0
testq %rax, %rax
je 0x2b25
pushq $0x1
popq %rdi
movl %edi, %esi
movl %r14d, %ecx
shll %cl, %esi
movw %si, 0x10(%rax)
movw %r14w, 0x12(%rax)
movw %bp, 0x14(%rax)
movw %bp, 0x16(%rax)
movq %r12, 0x8(%rax)
movzwl %bp, %r8d
leal -0x1f(%r8), %ecx
leaq 0x18(%rax), %rdx
movslq %ecx, %r9
xorl %ecx, %ecx
movq %rdx, %r10
cmpq %r9, %rcx
jge 0x2af6
orl $-0x1, (%r10)
addq $0x20, %rcx
addq $0x4, %r10
jmp 0x2ad0
movl %edi, %r9d
shll %cl, %r9d
movl %ecx, %r10d
shrl $0x5, %r10d
orl %r9d, (%rdx,%r10,4)
incl %ecx
cmpl %r8d, %ecx
jb 0x2ae3
cmpq %r12, %rax
jne 0x2b78
movslq %esi, %rsi
xorl %ecx, %ecx
pushq $-0x2
popq %rdi
testq %r13, %r13
jle 0x2b6e
movl %edi, %r8d
roll %cl, %r8d
movl %ecx, %r9d
shrl $0x5, %r9d
andl %r8d, (%rdx,%r9,4)
subq %rsi, %r13
incl %ecx
jmp 0x2b08
movq %r15, %rdi
movq %r12, %rsi
callq 0x257e
xorl %r15d, %r15d
cmpb $0x1, 0x3956(%rip)      # 0x6490
jne 0x2b41
testq %r15, %r15
je 0x2ba7
cmpb $0x1, 0x3958(%rip)      # 0x64a0
jne 0x2b5c
testq %r15, %r15
je 0x2b5c
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1130
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl %ecx, %ebp
movw %bp, 0x14(%rax)
movw %bp, 0x16(%rax)
movb 0x8(%r15), %cl
shrq %cl, %r12
subq 0x20(%r15), %r12
movq 0x30(%r15), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x30(%r15), %rcx
movq (%rcx,%r14,8), %rdx
movq %rdx, (%rax)
movq %rax, (%rcx,%r14,8)
movq 0x30(%r15), %rax
movq (%rax,%r14,8), %r12
jmp 0x29ed
leaq 0x189d(%rip), %rdi      # 0x444b
callq 0x2531