// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rsi, %rbx
movq (%rdi), %rsi
movq %rsi, %rcx
addq %rbx, %rcx
jb 0x2cb5
movq %rdi, %r15
movq 0x30(%rdi), %rax
cmpq %rax, %rcx
jae 0x2cb5
movq %rsi, %rcx
shrq %rcx
cmpq %rbx, %rcx
jae 0x2abe
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2d1a
movq %rax, %r15
jmp 0x2cb8
cmpq $0x11, %rbx
movl $0x10, %ecx
cmovaeq %rbx, %rcx
decq %rcx
movl $0x1, %r14d
movq %rcx, %rdx
shrq %rdx
incq %r14
cmpq $0x3, %rcx
movq %rdx, %rcx
ja 0x2ad7
cmpq $0x0, (%rax,%r14,8)
je 0x2b7d
movq 0x30(%r15), %rcx
movq (%rcx,%r14,8), %r12
leaq 0x18(%r12), %rdx
movq $-0x20, %rax
movl (%rdx), %esi
addq $0x4, %rdx
addq $0x20, %rax
testl %esi, %esi
je 0x2b05
movl $0x1, %edi
xorl %r15d, %r15d
testb $0x1, %sil
jne 0x2b2a
addl %edi, %edi
incq %r15
testl %esi, %edi
je 0x2b21
xorl %esi, %edi
movl %edi, -0x4(%rdx)
decw 0x14(%r12)
jne 0x2b47
movq (%r12), %rdx
movq %rdx, (%rcx,%r14,8)
movq $0x0, (%r12)
addq %rax, %r15
movb 0x12(%r12), %cl
shlq %cl, %r15
cmpb $0x1, 0x393b(%rip)      # 0x6494
jne 0x2b73
movq 0x8(%r12), %rdi
addq %r15, %rdi
movzwl 0x10(%r12), %edx
movl $0xd0, %esi
callq 0x1130
addq 0x8(%r12), %r15
jmp 0x2cb8
movq %r15, %rdi
callq 0x2d1a
testq %rax, %rax
je 0x2cb5
movq %rax, %r12
movq (%r15), %rax
movl %r14d, %ecx
shrq %cl, %rax
movq %rax, 0x8(%rsp)
addq $0x1f, %rax
shrq $0x5, %rax
leaq 0x18(,%rax,4), %rbp
movq %rbp, %rdi
callq 0x11b0
testq %rax, %rax
je 0x2caa
movq %rax, %r13
leaq -0x1(%r14), %rcx
movl $0x2, %esi
shll %cl, %esi
movw %si, 0x10(%rax)
movw %r14w, 0x12(%rax)
movq 0x8(%rsp), %r8
movw %r8w, 0x14(%rax)
movw %r8w, 0x16(%rax)
movq %r12, 0x10(%rsp)
movq %r12, 0x8(%rax)
movzwl %r8w, %r12d
xorl %ecx, %ecx
cmpl $0x20, %r12d
jb 0x2c2e
leaq 0x18(%r13), %rdi
leal -0x20(%r12), %eax
shrl $0x5, %eax
leal 0x4(,%rax,4), %edx
movl %esi, 0x4(%rsp)
movl $0xff, %esi
callq 0x1130
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %r8
movl %r8d, %ecx
andl $0xffe0, %ecx           # imm = 0xFFE0
cmpl %r12d, %ecx
jae 0x2c4b
movl $0x1, %eax
shll %cl, %eax
movl %ecx, %edx
shrl $0x5, %edx
orl %eax, 0x18(%r13,%rdx,4)
incl %ecx
cmpl %ecx, %r12d
jne 0x2c33
movq 0x10(%rsp), %rdi
cmpq %rdi, %r13
jne 0x2c82
movslq %esi, %rax
xorl %ecx, %ecx
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
roll %cl, %edx
movl %ecx, %esi
shrl $0x5, %esi
andl %edx, 0x18(%r13,%rsi,4)
subq %rax, %rbp
incl %ecx
testq %rbp, %rbp
jg 0x2c5a
subl %ecx, %r8d
movw %r8w, 0x14(%r13)
movw %r8w, 0x16(%r13)
movb 0x8(%r15), %cl
shrq %cl, %rdi
movq 0x30(%r15), %rax
subq 0x20(%r15), %rdi
movq %r13, (%rax,%rdi,8)
movq 0x30(%r15), %rax
movq (%rax,%r14,8), %rcx
movq %rcx, (%r13)
movq %r13, (%rax,%r14,8)
jmp 0x2af1
movq %r15, %rdi
movq %r12, %rsi
callq 0x2653
xorl %r15d, %r15d
cmpb $0x1, 0x37d1(%rip)      # 0x6490
jne 0x2cc6
testq %r15, %r15
je 0x2cf3
cmpb $0x1, 0x37d3(%rip)      # 0x64a0
jne 0x2ce1
testq %r15, %r15
je 0x2ce1
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x1130
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x37ae(%rip), %rsi      # 0x64a8
leaq 0x15b0(%rip), %rdi      # 0x42b1
leaq 0x15f7(%rip), %rdx      # 0x42ff
leaq 0x173c(%rip), %rcx      # 0x444b
callq *0x3433(%rip)           # 0x6148
callq 0x1050