// File: /workspace/github_c_makefile_star2_O2/USArmyResearchLab[P]ARL_OpenSHMEM/src/xmalloc.c
// Function: pubrealloc
static void *
pubrealloc( struct __xmem_struct* xm, void *ptr, size_t size, const char *func)
{
    void *r;
    int err = 0;
    static int malloc_active; /* Recusion flag for public interface. */
    static unsigned malloc_started; /* Set when initialization has been done */

    /*
     * If a thread is inside our code with a functional lock held, and then
     * catches a signal which calls us again, we would get a deadlock if the
     * lock is not of a recursive type.
     */
    _MALLOC_LOCK();
    malloc_func = func;
    if (malloc_active > 0) {
	if (malloc_active == 1) {
	    wrtwarning("recursive call\n");
	    malloc_active = 2;
	}
        _MALLOC_UNLOCK();
	errno = EINVAL;
	return (NULL);
    } 
    malloc_active = 1;

    if (!malloc_started) {
        if (ptr != NULL) {
	    wrtwarning("malloc() has never been called\n");
	    malloc_active = 0;
            _MALLOC_UNLOCK();
	    errno = EINVAL;
	    return (NULL);
	}
	malloc_init(xm);
	malloc_started = 1;
    }
   
    if (ptr == ZEROSIZEPTR)
	ptr = NULL;
    if (malloc_sysv && !size) {
	if (ptr != NULL)
	    ifree(xm, ptr);
	r = NULL;
    } else if (!size) {
	if (ptr != NULL)
	    ifree(xm, ptr);
	r = ZEROSIZEPTR;
    } else if (ptr == NULL) {
	r = imalloc(xm, size);
	err = (r == NULL);
    } else {
        r = irealloc(xm, ptr, size);
	err = (r == NULL);
    }
    UTRACE(ptr, size, r);
    malloc_active = 0;
    _MALLOC_UNLOCK();
    if (malloc_xmalloc && err)
	wrterror("out of memory\n");
    if (err)
	errno = ENOMEM;
    return (r);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, 0x438c(%rip)      # 0x64a8
movl 0x438e(%rip), %eax      # 0x64b0
testl %eax, %eax
jle 0x2143
cmpl $0x1, %eax
jne 0x2177
leaq 0x21d6(%rip), %rdi      # 0x4308
callq 0x2555
movl $0x2, 0x436f(%rip)      # 0x64b0
jmp 0x2177
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movl $0x1, 0x435a(%rip)      # 0x64b0
cmpb $0x0, 0x4357(%rip)      # 0x64b4
jne 0x21a0
testq %rbx, %rbx
je 0x2191
leaq 0x21ad(%rip), %rdi      # 0x4318
callq 0x2555
andl $0x0, 0x4339(%rip)      # 0x64b0
callq 0x1060
movl $0x16, (%rax)
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x1e44
movb $0x1, 0x4314(%rip)      # 0x64b4
movq 0x8(%r14), %rax
leal -0x1(%rax), %ecx
pushq $0x1
popq %r13
movq %r13, %rdx
shlq %cl, %rdx
xorl %r12d, %r12d
cmpq %rbx, %rdx
cmovneq %rbx, %r12
testq %r15, %r15
jne 0x21e4
testb $0x1, 0x42d1(%rip)      # 0x6498
je 0x21e4
testq %r12, %r12
je 0x21d9
movq %r14, %rdi
movq %r12, %rsi
callq 0x257e
xorl %ebx, %ebx
andl $0x0, 0x42ce(%rip)      # 0x64b0
jmp 0x2184
testq %r15, %r15
je 0x2211
testq %r12, %r12
je 0x222f
movq %r12, %rdx
movl %eax, %ecx
shrq %cl, %rdx
movq 0x20(%r14), %rcx
movq %rdx, %rdi
subq %rcx, %rdi
cmpq %rax, %rdi
jae 0x2242
leaq 0x213b(%rip), %rdi      # 0x4347
jmp 0x2333
testq %r12, %r12
je 0x2254
movq %r14, %rdi
movq %r12, %rsi
callq 0x257e
movb 0x8(%r14), %cl
decb %cl
shlq %cl, %r13
movq %r13, %rbx
jmp 0x21db
movq %r14, %rdi
movq %r15, %rsi
callq 0x2979
movq %rax, %rbx
jmp 0x233a
cmpq 0x28(%r14), %rdi
jbe 0x2259
leaq 0x211e(%rip), %rdi      # 0x436d
jmp 0x2333
movq %rdx, %rbx
jmp 0x21db
movq 0x30(%r14), %rsi
movq (%rsi,%rdi,8), %rax
cmpq $0x2, %rax
je 0x2279
cmpq $0x4, %rax
jae 0x228b
leaq 0x2137(%rip), %rdi      # 0x43ab
jmp 0x2333
testq %r12, 0x10(%r14)
je 0x22a5
leaq 0x213d(%rip), %rdi      # 0x43c3
jmp 0x2333
movzwl 0x10(%rax), %r13d
leaq -0x1(%r13), %rcx
testq %r12, %rcx
je 0x230f
leaq 0x2156(%rip), %rdi      # 0x43f6
jmp 0x2333
movq (%r14), %rax
shlq $0x3, %rdx
shlq $0x3, %rcx
subq %rcx, %rdx
leaq (%rdx,%rsi), %rcx
addq $0x8, %rcx
xorl %r13d, %r13d
addq %rax, %r13
cmpq $0x3, (%rcx)
leaq 0x8(%rcx), %rcx
je 0x22be
cmpl $0x0, 0x68(%r14)
jne 0x23ac
movq %r13, %rdx
subq %r15, %rdx
jb 0x23ac
movq %r13, %rcx
subq %rax, %rcx
cmpq %r15, %rcx
jae 0x23ac
cmpb $0x1, 0x419c(%rip)      # 0x6494
jne 0x230a
addq %r12, %r15
movq %r15, %rdi
movl $0xd0, %esi
callq 0x1130
movq %r12, %rbx
jmp 0x233a
movq 0x10(%r14), %rdx
andq %r12, %rdx
movb 0x12(%rax), %cl
shrq %cl, %rdx
movq %rdx, %rcx
shrq $0x5, %rcx
movl 0x18(%rax,%rcx,4), %eax
btl %edx, %eax
jae 0x236c
leaq 0x20df(%rip), %rdi      # 0x4412
callq 0x2555
xorl %ebx, %ebx
andl $0x0, 0x416f(%rip)      # 0x64b0
cmpb $0x1, 0x4154(%rip)      # 0x649c
jne 0x2353
testq %rbx, %rbx
je 0x23ed
testq %rbx, %rbx
jne 0x2184
callq 0x1060
movl $0xc, (%rax)
jmp 0x2182
movq %r13, %rdx
subq %r15, %rdx
jb 0x23ac
cmpl $0x0, 0x68(%r14)
jne 0x23ac
movl %r13d, %eax
shrl %eax
cmpq %r15, %rax
setae %al
cmpq $0x10, %r13
setne %cl
testb %al, %cl
jne 0x23ac
cmpb $0x1, 0x40fc(%rip)      # 0x6494
jne 0x233a
addq %r15, %r12
movq %r12, %rdi
movl $0xd0, %esi
callq 0x1130
jmp 0x233a
movq %r14, %rdi
movq %r15, %rsi
callq 0x2979
testq %rax, %rax
je 0x2338
movq %rax, %rbx
testq %r13, %r13
je 0x23dd
cmpq %r15, %r13
cmovbq %r13, %r15
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1190
movq %r14, %rdi
movq %r12, %rsi
callq 0x257e
jmp 0x233a
leaq 0x1f44(%rip), %rdi      # 0x4338
callq 0x2531