// File: /workspace/github_c_makefile_star2_O1/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, 0x42a4(%rip)      # 0x64a8
movl 0x42a6(%rip), %eax      # 0x64b0
testl %eax, %eax
jle 0x2221
cmpl $0x1, %eax
jne 0x2256
movl $0x2, %ebx
leaq 0x20e9(%rip), %rdi      # 0x4308
jmp 0x224b
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movl $0x1, 0x427c(%rip)      # 0x64b0
cmpb $0x0, 0x4279(%rip)      # 0x64b4
jne 0x2281
testq %r12, %r12
je 0x2272
xorl %ebx, %ebx
leaq 0x20cd(%rip), %rdi      # 0x4318
callq 0x260f
movl %ebx, 0x425a(%rip)      # 0x64b0
movl $0x16, %ebx
xorl %r12d, %r12d
callq 0x1060
movl %ebx, (%rax)
movq %r12, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rbx, %rdi
callq 0x1eed
movb $0x1, 0x4233(%rip)      # 0x64b4
movq 0x8(%rbx), %rax
leal -0x1(%rax), %ecx
movl $0x1, %edx
shlq %cl, %rdx
xorl %r15d, %r15d
cmpq %r12, %rdx
cmovneq %r12, %r15
testq %r14, %r14
jne 0x22bd
testb $0x1, 0x41f2(%rip)      # 0x6498
je 0x22bd
testq %r15, %r15
je 0x22b8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2653
xorl %r12d, %r12d
jmp 0x2308
testq %r14, %r14
je 0x22ea
testq %r15, %r15
je 0x230f
movq %r15, %rdx
movl %eax, %ecx
shrq %cl, %rdx
movq 0x20(%rbx), %rcx
movq %rdx, %rdi
subq %rcx, %rdi
cmpq %rax, %rdi
jae 0x2325
leaq 0x2062(%rip), %rdi      # 0x4347
jmp 0x2410
testq %r15, %r15
je 0x22fa
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2653
movb 0x8(%rbx), %cl
decb %cl
movl $0x1, %r12d
shlq %cl, %r12
xorl %eax, %eax
jmp 0x241e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a70
movq %rax, %r12
testq %rax, %rax
jmp 0x241b
cmpq 0x28(%rbx), %rdi
jbe 0x2337
leaq 0x203b(%rip), %rdi      # 0x436d
jmp 0x2410
movq 0x30(%rbx), %rsi
movq (%rsi,%rdi,8), %rax
cmpq $0x2, %rax
je 0x2357
cmpq $0x4, %rax
jae 0x2369
leaq 0x2059(%rip), %rdi      # 0x43ab
jmp 0x2410
testq %r15, 0x10(%rbx)
je 0x2383
leaq 0x205f(%rip), %rdi      # 0x43c3
jmp 0x2410
movzwl 0x10(%rax), %r13d
leaq -0x1(%r13), %rcx
testq %r15, %rcx
je 0x23ec
leaq 0x2078(%rip), %rdi      # 0x43f6
jmp 0x2410
movq (%rbx), %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 0x239c
cmpl $0x0, 0x68(%rbx)
jne 0x246f
movq %r13, %rdx
subq %r14, %rdx
jb 0x246f
movq %r13, %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jae 0x246f
cmpb $0x1, 0x40bf(%rip)      # 0x6494
jne 0x23e7
addq %r15, %r14
movq %r14, %rdi
movl $0xd0, %esi
callq 0x1130
movq %r15, %r12
jmp 0x2418
movq 0x10(%rbx), %rdx
andq %r15, %rdx
movb 0x12(%rax), %cl
shrq %cl, %rdx
movq %rdx, %rcx
shrq $0x5, %rcx
movl 0x18(%rax,%rcx,4), %eax
btl %edx, %eax
jae 0x2447
leaq 0x2002(%rip), %rdi      # 0x4412
callq 0x260f
xorl %r12d, %r12d
testq %r12, %r12
sete %al
movl $0x0, 0x4088(%rip)      # 0x64b0
cmpb $0x1, 0x406d(%rip)      # 0x649c
jne 0x2435
testb %al, %al
jne 0x24ac
movl $0xc, %ebx
testb %al, %al
jne 0x225e
jmp 0x2265
movq %r13, %rdx
subq %r14, %rdx
jb 0x246f
cmpl $0x0, 0x68(%rbx)
jne 0x246f
movl %r13d, %eax
shrl %eax
cmpq %r14, %rax
setae %al
cmpq $0x10, %r13
setne %cl
testb %al, %cl
je 0x23ce
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a70
movq %rax, %r12
testq %rax, %rax
je 0x2418
testq %r13, %r13
je 0x249c
cmpq %r14, %r13
cmovbq %r13, %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1190
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2653
jmp 0x2418
movq 0x3ff5(%rip), %rsi      # 0x64a8
leaq 0x1df7(%rip), %rdi      # 0x42b1
leaq 0x1e3e(%rip), %rdx      # 0x42ff
leaq 0x1e70(%rip), %rcx      # 0x4338
callq *0x3c7a(%rip)           # 0x6148
callq 0x1050