// File: /workspace/github_c_makefile_star2_O1/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 0x1f2a
movq %rcx, 0x8(%rbx)
xorl %r14d, %r14d
leaq 0x22b0(%rip), %r12      # 0x41f8
leaq 0x2371(%rip), %rbp      # 0x42c0
leaq 0x22c6(%rip), %r13      # 0x421c
cmpq $0x1, %r14
je 0x1f8c
testq %r14, %r14
jne 0x1f9d
movl $0x3f, %edx
leaq 0x2323(%rip), %rdi      # 0x4290
leaq 0x10(%rsp), %rsi
callq 0x1080
testq %rax, %rax
jle 0x20f4
movb $0x0, 0x10(%rsp,%rax)
leaq 0x10(%rsp), %r15
jmp 0x1fa4
leaq 0x230e(%rip), %rdi      # 0x42a1
callq 0x1030
movq %rax, %r15
jmp 0x1fa4
movq 0x44e4(%rip), %r15      # 0x6488
testq %r15, %r15
jne 0x1fcf
jmp 0x20f4
movq 0x44f3(%rip), %rsi      # 0x64a8
leaq 0x22f5(%rip), %rdi      # 0x42b1
leaq 0x22f2(%rip), %rdx      # 0x42b5
movq %rbp, %rcx
callq *0x417c(%rip)           # 0x6148
incq %r15
movzbl (%r15), %eax
cmpl $0x60, %eax
jg 0x1ff7
cmpl $0x47, %eax
jle 0x2017
leal -0x52(%rax), %ecx
cmpl $0x8, %ecx
ja 0x204b
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movl $0x1, 0x68(%rbx)
jmp 0x1fcc
cmpl $0x71, %eax
jle 0x202f
addl $-0x72, %eax
cmpl $0x8, %eax
ja 0x1fae
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movl $0x0, 0x68(%rbx)
jmp 0x1fcc
cmpl $0x3d, %eax
jle 0x2069
cmpl $0x3e, %eax
je 0x2077
cmpl $0x41, %eax
jne 0x1fae
movb $0x1, 0x4463(%rip)      # 0x6490
jmp 0x1fcc
cmpl $0x61, %eax
je 0x20b0
cmpl $0x68, %eax
je 0x20a4
cmpl $0x6a, %eax
jne 0x1fae
movb $0x0, 0x444b(%rip)      # 0x6494
jmp 0x1fcc
cmpl $0x48, %eax
je 0x20e0
cmpl $0x4a, %eax
jne 0x1fae
movb $0x1, 0x4430(%rip)      # 0x6494
jmp 0x1fcc
cmpl $0x3c, %eax
jne 0x20ec
shrq 0x18(%rbx)
jmp 0x1fcc
shlq 0x18(%rbx)
jmp 0x1fcc
movb $0x0, 0x4419(%rip)      # 0x64a0
jmp 0x1fcc
movb $0x0, 0x4405(%rip)      # 0x6498
jmp 0x1fcc
movb $0x0, 0x43fd(%rip)      # 0x649c
jmp 0x1fcc
movl $0x0, 0x6c(%rbx)
jmp 0x1fcc
movb $0x0, 0x43d9(%rip)      # 0x6490
jmp 0x1fcc
movb $0x1, 0x43dd(%rip)      # 0x64a0
jmp 0x1fcc
movb $0x1, 0x43c9(%rip)      # 0x6498
jmp 0x1fcc
movb $0x1, 0x43c1(%rip)      # 0x649c
jmp 0x1fcc
movl $0x1, 0x6c(%rbx)
jmp 0x1fcc
testl %eax, %eax
jne 0x1fae
incq %r14
cmpq $0x3, %r14
jne 0x1f56
cmpb $0x1, 0x4398(%rip)      # 0x64a0
jne 0x2111
movb $0x1, 0x4383(%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 0x21bf
movq 0x90(%rbx), %rcx
movq $-0x1, %rax
cmpq 0x80(%rbx), %rcx
jb 0x215e
cmpq 0x88(%rbx), %rcx
cmovbeq %rcx, %rax
movq 0x10(%rbx), %rdx
addq %rdx, %rax
notq %rdx
andq %rax, %rdx
movq 0x8(%rbx), %rcx
shrq %cl, %rdx
movq (%rbx), %rax
subq %rcx, %rdx
movq %rdx, 0x20(%rbx)
shrq $0x3, %rax
movq %rax, 0x38(%rbx)
cmpq $0x0, 0x18(%rbx)
jne 0x2193
movq $0x1, 0x18(%rbx)
shlq %cl, 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 0x42e2(%rip), %rsi      # 0x64a8
leaq 0x20e4(%rip), %rdi      # 0x42b1
leaq 0x212b(%rip), %rdx      # 0x42ff
leaq 0x2105(%rip), %rcx      # 0x42e0
callq *0x3f67(%rip)           # 0x6148
callq 0x1050