// File: /workspace/github_c_makefile_star2_O3/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 0x2d44
movq %rdi, %r15
movq 0x30(%rdi), %rax
cmpq %rax, %rcx
jae 0x2d44
movq %rsi, %rcx
shrq %rcx
cmpq %rbx, %rcx
jae 0x2b36
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2da9
movq %rax, %r15
jmp 0x2d47
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 0x2b4f
movq (%rax,%r14,8), %r12
testq %r12, %r12
je 0x2bef
leaq 0x18(%r12), %rdx
movq $-0x20, %rcx
movl (%rdx), %esi
addq $0x4, %rdx
addq $0x20, %rcx
testl %esi, %esi
je 0x2b77
movl $0x1, %edi
xorl %r15d, %r15d
testb $0x1, %sil
jne 0x2b9c
addl %edi, %edi
incq %r15
testl %esi, %edi
je 0x2b93
xorl %esi, %edi
movl %edi, -0x4(%rdx)
decw 0x14(%r12)
jne 0x2bb9
movq (%r12), %rdx
movq %rdx, (%rax,%r14,8)
movq $0x0, (%r12)
addq %rcx, %r15
movb 0x12(%r12), %cl
shlq %cl, %r15
cmpb $0x1, 0x38c9(%rip)      # 0x6494
jne 0x2be5
movq 0x8(%r12), %rdi
addq %r15, %rdi
movzwl 0x10(%r12), %edx
movl $0xd0, %esi
callq 0x1130
addq 0x8(%r12), %r15
jmp 0x2d47
movq %r15, %rdi
callq 0x2da9
testq %rax, %rax
je 0x2d44
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 0x2d39
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 0x2cb5
leal -0x1f(%r12), %eax
movl %eax, (%rsp)
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 (%rsp), %eax
cmpl $0x21, %eax
movl $0x20, %ecx
cmovael %eax, %ecx
decl %ecx
andl $-0x20, %ecx
addl $0x20, %ecx
cmpl %r12d, %ecx
jae 0x2cd2
movl $0x1, %eax
shll %cl, %eax
movl %ecx, %edx
shrl $0x5, %edx
orl %eax, 0x18(%r13,%rdx,4)
incl %ecx
cmpl %ecx, %r12d
jne 0x2cba
movq 0x10(%rsp), %rdi
cmpq %rdi, %r13
jne 0x2d09
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 0x2ce1
subl %ecx, %r8d
movw %r8w, 0x14(%r13)
movw %r8w, 0x16(%r13)
movb 0x8(%r15), %cl
shrq %cl, %rdi
subq 0x20(%r15), %rdi
movq 0x30(%r15), %rax
movq %r13, (%rax,%rdi,8)
movq 0x30(%r15), %rax
movq (%rax,%r14,8), %rcx
movq %rcx, (%r13)
movq %r13, (%rax,%r14,8)
movq 0x30(%r15), %rax
movq (%rax,%r14,8), %r12
jmp 0x2b6b
movq %r15, %rdi
movq %r12, %rsi
callq 0x2699
xorl %r15d, %r15d
cmpb $0x1, 0x3742(%rip)      # 0x6490
jne 0x2d55
testq %r15, %r15
je 0x2d82
cmpb $0x1, 0x3744(%rip)      # 0x64a0
jne 0x2d70
testq %r15, %r15
je 0x2d70
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 0x371f(%rip), %rsi      # 0x64a8
leaq 0x1521(%rip), %rdi      # 0x42b1
leaq 0x1568(%rip), %rdx      # 0x42ff
leaq 0x16ad(%rip), %rcx      # 0x444b
callq *0x33a4(%rip)           # 0x6148
callq 0x1050