// File: /workspace/github_c_makefile_star2_O3/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, 0x4293(%rip)      # 0x64a8
movl 0x4295(%rip), %eax      # 0x64b0
testl %eax, %eax
jle 0x223c
cmpl $0x1, %eax
jne 0x2273
leaq 0x20dd(%rip), %rdi      # 0x4308
callq 0x2655
movl $0x2, 0x4276(%rip)      # 0x64b0
jmp 0x2273
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movl $0x1, 0x4261(%rip)      # 0x64b0
cmpb $0x0, 0x425e(%rip)      # 0x64b4
jne 0x229c
testq %rbx, %rbx
je 0x228d
leaq 0x20b4(%rip), %rdi      # 0x4318
callq 0x2655
movl $0x0, 0x423d(%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 0x1efe
movb $0x1, 0x4218(%rip)      # 0x64b4
movq 0x8(%r14), %rax
leal -0x1(%rax), %ecx
movl $0x1, %edx
shlq %cl, %rdx
xorl %r12d, %r12d
cmpq %rbx, %rdx
cmovneq %rbx, %r12
testq %r15, %r15
jne 0x22e1
testb $0x1, 0x41d7(%rip)      # 0x6498
je 0x22e1
testq %r12, %r12
je 0x22d3
movq %r14, %rdi
movq %r12, %rsi
callq 0x2699
xorl %ebx, %ebx
movl $0x0, 0x41d1(%rip)      # 0x64b0
jmp 0x2280
testq %r15, %r15
je 0x230e
testq %r12, %r12
je 0x232e
movq %r12, %rdx
movl %eax, %ecx
shrq %cl, %rdx
movq 0x20(%r14), %rcx
movq %rdx, %rdi
subq %rcx, %rdi
cmpq %rax, %rdi
jae 0x2341
leaq 0x203e(%rip), %rdi      # 0x4347
jmp 0x2435
testq %r12, %r12
je 0x2353
movq %r14, %rdi
movq %r12, %rsi
callq 0x2699
movb 0x8(%r14), %cl
decb %cl
movl $0x1, %ebx
shlq %cl, %rbx
jmp 0x22d5
movq %r14, %rdi
movq %r15, %rsi
callq 0x2ae8
movq %rax, %rbx
jmp 0x243c
cmpq 0x28(%r14), %rdi
jbe 0x235b
leaq 0x201f(%rip), %rdi      # 0x436d
jmp 0x2435
movq %rdx, %rbx
jmp 0x22d5
movq 0x30(%r14), %rsi
movq (%rsi,%rdi,8), %rax
cmpq $0x2, %rax
je 0x237b
cmpq $0x4, %rax
jae 0x238d
leaq 0x2035(%rip), %rdi      # 0x43ab
jmp 0x2435
testq %r12, 0x10(%r14)
je 0x23a7
leaq 0x203b(%rip), %rdi      # 0x43c3
jmp 0x2435
movzwl 0x10(%rax), %r13d
leaq -0x1(%r13), %rcx
testq %r12, %rcx
je 0x2411
leaq 0x2054(%rip), %rdi      # 0x43f6
jmp 0x2435
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 0x23c0
cmpl $0x0, 0x68(%r14)
jne 0x24b1
movq %r13, %rdx
subq %r15, %rdx
jb 0x24b1
movq %r13, %rcx
subq %rax, %rcx
cmpq %r15, %rcx
jae 0x24b1
cmpb $0x1, 0x409a(%rip)      # 0x6494
jne 0x240c
addq %r12, %r15
movq %r15, %rdi
movl $0xd0, %esi
callq 0x1130
movq %r12, %rbx
jmp 0x243c
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 0x2471
leaq 0x1fdd(%rip), %rdi      # 0x4412
callq 0x2655
xorl %ebx, %ebx
movl $0x0, 0x406a(%rip)      # 0x64b0
cmpb $0x1, 0x404f(%rip)      # 0x649c
jne 0x2458
testq %rbx, %rbx
je 0x24f2
testq %rbx, %rbx
jne 0x2280
callq 0x1060
movl $0xc, (%rax)
jmp 0x227e
movq %r13, %rdx
subq %r15, %rdx
jb 0x24b1
cmpl $0x0, 0x68(%r14)
jne 0x24b1
movl %r13d, %eax
shrl %eax
cmpq %r15, %rax
setae %al
cmpq $0x10, %r13
setne %cl
testb %al, %cl
jne 0x24b1
cmpb $0x1, 0x3ff7(%rip)      # 0x6494
jne 0x243c
addq %r15, %r12
movq %r12, %rdi
movl $0xd0, %esi
callq 0x1130
jmp 0x243c
movq %r14, %rdi
movq %r15, %rsi
callq 0x2ae8
testq %rax, %rax
je 0x243a
movq %rax, %rbx
testq %r13, %r13
je 0x24e2
cmpq %r15, %r13
cmovbq %r13, %r15
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1190
movq %r14, %rdi
movq %r12, %rsi
callq 0x2699
jmp 0x22d5
movq 0x3faf(%rip), %rsi      # 0x64a8
leaq 0x1db1(%rip), %rdi      # 0x42b1
leaq 0x1df8(%rip), %rdx      # 0x42ff
leaq 0x1e2a(%rip), %rcx      # 0x4338
callq *0x3c34(%rip)           # 0x6148
callq 0x1050