// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x1e
popq %rdi
callq 0x1200
movq %rax, (%rbx)
leaq -0x1(%rax), %rcx
movq %rcx, 0x10(%rbx)
pushq $-0x1
popq %rcx
pushq $0x1
popq %rdx
incq %rcx
movq %rdx, %rsi
shlq %cl, %rsi
cmpq %rax, %rsi
jne 0x1e7e
movq %rcx, 0x8(%rbx)
xorl %r13d, %r13d
leaq 0x2382(%rip), %rbp      # 0x421c
leaq 0x241f(%rip), %r15      # 0x42c0
leaq 0x2350(%rip), %r14      # 0x41f8
testq %r13, %r13
je 0x1ed7
cmpq $0x1, %r13
je 0x1ec6
cmpq $0x3, %r13
je 0x203b
movq 0x45c4(%rip), %r12      # 0x6488
jmp 0x1efe
leaq 0x23d4(%rip), %rdi      # 0x42a1
callq 0x1030
movq %rax, %r12
jmp 0x1efe
leaq 0x23b2(%rip), %rdi      # 0x4290
leaq 0x10(%rsp), %rsi
pushq $0x3f
popq %rdx
callq 0x1080
testq %rax, %rax
jle 0x2033
movb $0x0, 0x10(%rsp,%rax)
leaq 0x10(%rsp), %r12
testq %r12, %r12
je 0x2033
movzbl (%r12), %eax
leal -0x52(%rax), %ecx
cmpl $0x8, %ecx
jbe 0x1f93
leal -0x72(%rax), %ecx
cmpl $0x8, %ecx
jbe 0x1fa8
cmpl $0x3c, %eax
je 0x201e
cmpl $0x3e, %eax
je 0x1ff7
cmpl $0x41, %eax
je 0x2006
cmpl $0x48, %eax
je 0x1ffd
cmpl $0x4a, %eax
je 0x2024
cmpl $0x61, %eax
je 0x1fee
cmpl $0x68, %eax
je 0x200f
cmpl $0x6a, %eax
je 0x2015
testl %eax, %eax
je 0x2033
movq 0x4531(%rip), %rsi      # 0x64a8
leaq 0x2333(%rip), %rdi      # 0x42b1
leaq 0x2330(%rip), %rdx      # 0x42b5
movq %r15, %rcx
callq *0x41ba(%rip)           # 0x6148
jmp 0x202b
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movl $0x1, 0x68(%rbx)
jmp 0x202b
movslq (%rbp,%rcx,4), %rax
addq %rbp, %rax
jmpq *%rax
andl $0x0, 0x68(%rbx)
jmp 0x202b
movb $0x1, 0x44dd(%rip)      # 0x649c
jmp 0x202b
movb $0x1, 0x44d8(%rip)      # 0x64a0
jmp 0x202b
movb $0x1, 0x44c7(%rip)      # 0x6498
jmp 0x202b
movb $0x0, 0x44c2(%rip)      # 0x649c
jmp 0x202b
movb $0x0, 0x44bd(%rip)      # 0x64a0
jmp 0x202b
movb $0x0, 0x44ac(%rip)      # 0x6498
jmp 0x202b
movb $0x0, 0x449b(%rip)      # 0x6490
jmp 0x202b
shlq 0x18(%rbx)
jmp 0x202b
movl $0x1, 0x6c(%rbx)
jmp 0x202b
movb $0x1, 0x4483(%rip)      # 0x6490
jmp 0x202b
andl $0x0, 0x6c(%rbx)
jmp 0x202b
movb $0x0, 0x4478(%rip)      # 0x6494
jmp 0x202b
shrq 0x18(%rbx)
jmp 0x202b
movb $0x1, 0x4469(%rip)      # 0x6494
incq %r12
jmp 0x1efe
incq %r13
jmp 0x1ea8
cmpb $0x1, 0x445e(%rip)      # 0x64a0
jne 0x204b
movb $0x1, 0x4449(%rip)      # 0x6494
movq (%rbx), %rsi
pushq $0x3
popq %rdx
pushq $0x22
popq %rcx
pushq $-0x1
popq %r8
xorl %edi, %edi
xorl %r9d, %r9d
callq 0x10e0
movq %rax, 0x30(%rbx)
cmpq $-0x1, %rax
je 0x20f2
movq 0x90(%rbx), %rcx
cmpq 0x80(%rbx), %rcx
jae 0x2085
pushq $-0x1
popq %rax
jmp 0x2093
cmpq 0x88(%rbx), %rcx
pushq $-0x1
popq %rax
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)
pushq $0x28
popq %rdi
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
leaq 0x21e7(%rip), %rdi      # 0x42e0
callq 0x2531