// File: /workspace/github_c_makefile_star2_O3/USArmyResearchLab[P]ARL_OpenSHMEM/src/xmalloc.c
// Function: malloc_init
static void
malloc_init( struct __xmem_struct* xm )
{
    const char *p;
    char b[64];
    size_t i;
    ssize_t j;
    int save_errno = errno;

    /*
     * Compute page-size related variables.
     */
    xm->malloc_pagesize = (size_t)sysconf(_SC_PAGESIZE);
    xm->malloc_pagemask = xm->malloc_pagesize - 1;
    for (xm->malloc_pageshift = 0;
	 (1UL << xm->malloc_pageshift) != xm->malloc_pagesize;
	 xm->malloc_pageshift++)
	/* nothing */ ;

    INIT_MMAP();

#ifdef MALLOC_EXTRA_SANITY
    xm->malloc_junk = 1;
#endif /* MALLOC_EXTRA_SANITY */

    for (i = 0; i < 3; i++) {
	if (i == 0) {
	    j = readlink("/etc/malloc.conf", b, sizeof b - 1);
	    if (j <= 0)
		continue;
	    b[j] = '\0';
	    p = b;
	} else if (i == 1) {
	    p = getenv("XMALLOC_OPTIONS");
	} else {
	    p = _malloc_options;
	}
	for (; p != NULL && *p != '\0'; p++) {
	    switch (*p) {
		case '>': xm->malloc_cache   <<= 1; break;
		case '<': xm->malloc_cache   >>= 1; break;
		case 'a': malloc_abort   = 0; break;
		case 'A': malloc_abort   = 1; break;
		case 'h': xm->malloc_hint    = 0; break;
		case 'H': xm->malloc_hint    = 1; break;
		case 'r': xm->malloc_realloc = 0; break;
		case 'R': xm->malloc_realloc = 1; break;
		case 'j': malloc_junk    = 0; break;
		case 'J': malloc_junk    = 1; break;
#ifdef HAS_UTRACE
		case 'u': xm->malloc_utrace  = 0; break;
		case 'U': xm->malloc_utrace  = 1; break;
#endif
		case 'v': malloc_sysv    = 0; break;
		case 'V': malloc_sysv    = 1; break;
		case 'x': malloc_xmalloc = 0; break;
		case 'X': malloc_xmalloc = 1; break;
		case 'z': malloc_zero    = 0; break;
		case 'Z': malloc_zero    = 1; break;
		default:
		    _malloc_message(getprogname(), malloc_func,
			 " warning: ", "unknown char in MALLOC_OPTIONS\n");
		    break;
	    }
	}
    }

    UTRACE(0, 0, 0);

    /*
     * We want junk in the entire allocation, and zero only in the part
     * the user asked for.
     */
    if (malloc_zero)
	malloc_junk = 1;

    /* Allocate one page for the page directory */
    xm->page_dir = MMAP(xm->malloc_pagesize);

    if (xm->page_dir == MAP_FAILED)
	wrterror("mmap(2) failed, check limits.\n");

    /*
     * We need a maximum of malloc_pageshift buckets, steal these from the
     * front of the page_directory;
     */
    xm->malloc_origo = pageround((size_t)(uintptr_t)__sbrk(xm,(intptr_t)0))
	>> xm->malloc_pageshift;
    xm->malloc_origo -= xm->malloc_pageshift;

    xm->malloc_ninfo = xm->malloc_pagesize / sizeof(*xm->page_dir);

    /* Recalculate the cache size in bytes, and make sure it's nonzero */

    if (!xm->malloc_cache)
	xm->malloc_cache++;

    xm->malloc_cache <<= xm->malloc_pageshift;

    /*
     * This is a nice hack from Kaleb Keithly (kaleb@x.org).
     * We can sbrk(2) further back when we keep this on a low address.
     */
    xm->px = __host_malloc(sizeof(*xm->px));

    errno = save_errno;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
callq 0x1060
movq %rax, 0x8(%rsp)
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movl $0x1e, %edi
callq 0x1200
movq %rax, (%rbx)
leaq -0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq $-0x1, %rcx
incq %rcx
movl $0x1, %edx
shlq %cl, %rdx
cmpq %rax, %rdx
jne 0x1f3b
movq %rcx, 0x8(%rbx)
xorl %r14d, %r14d
leaq 0x229f(%rip), %r12      # 0x41f8
leaq 0x2360(%rip), %rbp      # 0x42c0
leaq 0x22b5(%rip), %r13      # 0x421c
cmpq $0x1, %r14
je 0x1f9d
testq %r14, %r14
jne 0x1fae
movl $0x3f, %edx
leaq 0x2312(%rip), %rdi      # 0x4290
leaq 0x10(%rsp), %rsi
callq 0x1080
testq %rax, %rax
jle 0x2105
movb $0x0, 0x10(%rsp,%rax)
leaq 0x10(%rsp), %r15
jmp 0x1fe0
leaq 0x22fd(%rip), %rdi      # 0x42a1
callq 0x1030
movq %rax, %r15
jmp 0x1fb5
movq 0x44d3(%rip), %r15      # 0x6488
testq %r15, %r15
jne 0x1fe0
jmp 0x2105
movq 0x44e2(%rip), %rsi      # 0x64a8
leaq 0x22e4(%rip), %rdi      # 0x42b1
leaq 0x22e1(%rip), %rdx      # 0x42b5
movq %rbp, %rcx
callq *0x416b(%rip)           # 0x6148
incq %r15
movzbl (%r15), %eax
cmpl $0x60, %eax
jg 0x2008
cmpl $0x47, %eax
jle 0x2028
leal -0x52(%rax), %ecx
cmpl $0x8, %ecx
ja 0x205c
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0x68(%rbx)
jmp 0x1fdd
cmpl $0x71, %eax
jle 0x2040
addl $-0x72, %eax
cmpl $0x8, %eax
ja 0x1fbf
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x0, 0x68(%rbx)
jmp 0x1fdd
cmpl $0x3d, %eax
jle 0x207a
cmpl $0x3e, %eax
je 0x2088
cmpl $0x41, %eax
jne 0x1fbf
movb $0x1, 0x4452(%rip)      # 0x6490
jmp 0x1fdd
cmpl $0x61, %eax
je 0x20c1
cmpl $0x68, %eax
je 0x20b5
cmpl $0x6a, %eax
jne 0x1fbf
movb $0x0, 0x443a(%rip)      # 0x6494
jmp 0x1fdd
cmpl $0x48, %eax
je 0x20f1
cmpl $0x4a, %eax
jne 0x1fbf
movb $0x1, 0x441f(%rip)      # 0x6494
jmp 0x1fdd
cmpl $0x3c, %eax
jne 0x20fd
shrq 0x18(%rbx)
jmp 0x1fdd
shlq 0x18(%rbx)
jmp 0x1fdd
movb $0x0, 0x4408(%rip)      # 0x64a0
jmp 0x1fdd
movb $0x0, 0x43f4(%rip)      # 0x6498
jmp 0x1fdd
movb $0x0, 0x43ec(%rip)      # 0x649c
jmp 0x1fdd
movl $0x0, 0x6c(%rbx)
jmp 0x1fdd
movb $0x0, 0x43c8(%rip)      # 0x6490
jmp 0x1fdd
movb $0x1, 0x43cc(%rip)      # 0x64a0
jmp 0x1fdd
movb $0x1, 0x43b8(%rip)      # 0x6498
jmp 0x1fdd
movb $0x1, 0x43b0(%rip)      # 0x649c
jmp 0x1fdd
movl $0x1, 0x6c(%rbx)
jmp 0x1fdd
testl %eax, %eax
jne 0x1fbf
incq %r14
cmpq $0x3, %r14
jne 0x1f67
cmpb $0x1, 0x4387(%rip)      # 0x64a0
jne 0x2122
movb $0x1, 0x4372(%rip)      # 0x6494
movq (%rbx), %rsi
xorl %edi, %edi
movl $0x3, %edx
movl $0x22, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %r9d, %r9d
callq 0x10e0
movq %rax, 0x30(%rbx)
cmpq $-0x1, %rax
je 0x21d0
movq 0x90(%rbx), %rcx
movq $-0x1, %rax
cmpq 0x80(%rbx), %rcx
jb 0x216f
cmpq 0x88(%rbx), %rcx
cmovbeq %rcx, %rax
movq 0x10(%rbx), %rdx
addq %rdx, %rax
notq %rdx
andq %rax, %rdx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
shrq %cl, %rdx
subq %rcx, %rdx
movq %rdx, 0x20(%rbx)
shrq $0x3, %rax
movq %rax, 0x38(%rbx)
movq 0x18(%rbx), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
shlq %cl, %rax
movq %rax, 0x18(%rbx)
movl $0x28, %edi
callq 0x11b0
movq %rax, 0x78(%rbx)
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x42d1(%rip), %rsi      # 0x64a8
leaq 0x20d3(%rip), %rdi      # 0x42b1
leaq 0x211a(%rip), %rdx      # 0x42ff
leaq 0x20f4(%rip), %rcx      # 0x42e0
callq *0x3f56(%rip)           # 0x6148
callq 0x1050