// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq %rax, 0x4c3e(%rip)      # 0x74a8
cmpl $0x0, 0x4c3f(%rip)      # 0x74b0
jle 0x28aa
cmpl $0x1, 0x4c36(%rip)      # 0x74b0
jne 0x2892
leaq 0x2b41(%rip), %rdi      # 0x53c4
callq 0x2ce0
movl $0x2, 0x4c1e(%rip)      # 0x74b0
callq 0x1060
movl $0x16, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x2a24
movl $0x1, 0x4bfc(%rip)      # 0x74b0
cmpl $0x0, 0x4bf9(%rip)      # 0x74b4
jne 0x2905
cmpq $0x0, -0x18(%rbp)
je 0x28f2
leaq 0x2b09(%rip), %rdi      # 0x53d4
callq 0x2ce0
movl $0x0, 0x4bd6(%rip)      # 0x74b0
callq 0x1060
movl $0x16, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x2a24
movq -0x10(%rbp), %rdi
callq 0x2470
movl $0x1, 0x4baf(%rip)      # 0x74b4
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
cmpq %rcx, %rax
jne 0x292d
movq $0x0, -0x18(%rbp)
cmpl $0x0, 0x4b64(%rip)      # 0x7498
je 0x295e
cmpq $0x0, -0x20(%rbp)
jne 0x295e
cmpq $0x0, -0x18(%rbp)
je 0x2951
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2d20
movq $0x0, -0x30(%rbp)
jmp 0x29e6
cmpq $0x0, -0x20(%rbp)
jne 0x2993
cmpq $0x0, -0x18(%rbp)
je 0x2979
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2d20
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
subq $0x1, %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x30(%rbp)
jmp 0x29e4
cmpq $0x0, -0x18(%rbp)
jne 0x29bd
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2df0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
jmp 0x29e2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x2ec0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
jmp 0x29e4
jmp 0x29e6
movl $0x0, 0x4ac0(%rip)      # 0x74b0
cmpl $0x0, 0x4aa5(%rip)      # 0x749c
je 0x2a0b
cmpl $0x0, -0x34(%rbp)
je 0x2a0b
leaq 0x29ee(%rip), %rdi      # 0x53f4
callq 0x2c00
cmpl $0x0, -0x34(%rbp)
je 0x2a1c
callq 0x1060
movl $0xc, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop