// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
callq 0x1060
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl $0x1e, %edi
callq 0x1200
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
subq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %eax
shlq %cl, %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
je 0x24e9
jmp 0x24d7
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
jmp 0x24bc
movq $0x0, -0x58(%rbp)
cmpq $0x3, -0x58(%rbp)
jae 0x26e9
cmpq $0x0, -0x58(%rbp)
jne 0x253b
leaq -0x50(%rbp), %rsi
leaq 0x2e3e(%rip), %rdi      # 0x534c
movl $0x3f, %edx
callq 0x1080
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jg 0x2528
jmp 0x26d8
movq -0x60(%rbp), %rax
movb $0x0, -0x50(%rbp,%rax)
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0x2561
cmpq $0x1, -0x58(%rbp)
jne 0x2554
leaq 0x2e14(%rip), %rdi      # 0x535d
callq 0x1030
movq %rax, -0x10(%rbp)
jmp 0x255f
movq 0x4f2d(%rip), %rax      # 0x7488
movq %rax, -0x10(%rbp)
jmp 0x2561
jmp 0x2563
xorl %eax, %eax
cmpq $0x0, -0x10(%rbp)
movb %al, -0x65(%rbp)
je 0x257f
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x258b
jmp 0x26d6
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
addl $-0x3c, %eax
movl %eax, %ecx
movq %rcx, -0x70(%rbp)
subl $0x3e, %eax
ja 0x269e
movq -0x70(%rbp), %rax
leaq 0x2c51(%rip), %rcx      # 0x5200
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
shlq %rcx
movq %rcx, 0x18(%rax)
jmp 0x26c3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
shrq %rcx
movq %rcx, 0x18(%rax)
jmp 0x26c3
movl $0x0, 0x4ea6(%rip)      # 0x7490
jmp 0x26c3
movl $0x1, 0x4e97(%rip)      # 0x7490
jmp 0x26c3
movq -0x8(%rbp), %rax
movl $0x0, 0x6c(%rax)
jmp 0x26c3
movq -0x8(%rbp), %rax
movl $0x1, 0x6c(%rax)
jmp 0x26c3
movq -0x8(%rbp), %rax
movl $0x0, 0x68(%rax)
jmp 0x26c3
movq -0x8(%rbp), %rax
movl $0x1, 0x68(%rax)
jmp 0x26c3
movl $0x0, 0x4e4c(%rip)      # 0x7494
jmp 0x26c3
movl $0x1, 0x4e40(%rip)      # 0x7494
jmp 0x26c3
movl $0x0, 0x4e38(%rip)      # 0x7498
jmp 0x26c3
movl $0x1, 0x4e2c(%rip)      # 0x7498
jmp 0x26c3
movl $0x0, 0x4e24(%rip)      # 0x749c
jmp 0x26c3
movl $0x1, 0x4e18(%rip)      # 0x749c
jmp 0x26c3
movl $0x0, 0x4e10(%rip)      # 0x74a0
jmp 0x26c3
movl $0x1, 0x4e04(%rip)      # 0x74a0
jmp 0x26c3
movq 0x4a9b(%rip), %rax      # 0x7140
movq 0x4dfc(%rip), %rsi      # 0x74a8
leaq 0x2cba(%rip), %rdi      # 0x536d
leaq 0x2cb7(%rip), %rdx      # 0x5371
leaq 0x2cbb(%rip), %rcx      # 0x537c
callq *%rax
jmp 0x26c5
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x2563
jmp 0x26d8
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x24f1
cmpl $0x0, 0x4db0(%rip)      # 0x74a0
je 0x26fc
movl $0x1, 0x4d98(%rip)      # 0x7494
movq -0x8(%rbp), %rax
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %r9d
movl $0x3, %edx
movl $0x22, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq %r9, %rdi
callq 0x10e0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
movq $-0x1, %rcx
cmpq %rcx, 0x30(%rax)
jne 0x2748
leaq 0x2c59(%rip), %rdi      # 0x539c
callq 0x2c00
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x2c40
movq -0x8(%rbp), %rcx
addq 0x10(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq %cl, %rax
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
shrq $0x3, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x27c7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x18(%rax)
movl $0x28, %edi
callq 0x2cc0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
movl -0x64(%rbp), %eax
movl %eax, -0x74(%rbp)
callq 0x1060
movl -0x74(%rbp), %ecx
movl %ecx, (%rax)
addq $0x80, %rsp
popq %rbp
retq
nop