// File: /workspace/github_c_makefile_star2_O0/USArmyResearchLab[P]ARL_OpenSHMEM/src/xmalloc.c
// Function: malloc_bytes
static void *
malloc_bytes( struct __xmem_struct* xm, size_t size)
{
    size_t i;
    int j;
    u_int u;
    struct  pginfo *bp;
    size_t k;
    u_int *lp;

    /* Don't bother with anything less than this */
    if (size < malloc_minsize)
	size = malloc_minsize;


    /* Find the right bucket */
    j = 1;
    i = size-1;
    while (i >>= 1)
	j++;

    /* If it's empty, make a page more of that size chunks */
    if (xm->page_dir[j] == NULL && !malloc_make_chunks(xm, j))
	return NULL;

    bp = xm->page_dir[j];

    /* Find first word of bitmap which isn't empty */
    for (lp = bp->bits; !*lp; lp++)
	;

    /* Find that bit, and tweak it */
    u = 1;
    k = 0;
    while (!(*lp & u)) {
	u += u;
	k++;
    }
    *lp ^= u;

    /* If there are no more free, remove from free-list */
    if (!--bp->free) {
	xm->page_dir[j] = bp->next;
	bp->next = NULL;
    }

    /* Adjust to the real offset of that chunk */
    k += (lp-bp->bits)*MALLOC_BITS;
    k <<= bp->shift;

    if (malloc_junk)
	memset((u_char*)bp->page + k, SOME_JUNK, (size_t)bp->size);

    return (u_char *)bp->page + k;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x10, -0x18(%rbp)
jae 0x39bf
movq $0x10, -0x18(%rbp)
movl $0x1, -0x24(%rbp)
movq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
shrq %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x39ee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x39d2
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x24(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x3a1f
movq -0x10(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x3d90
cmpl $0x0, %eax
jne 0x3a1f
movq $0x0, -0x8(%rbp)
jmp 0x3b4e
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, (%rax)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3a51
jmp 0x3a61
jmp 0x3a53
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x40(%rbp)
jmp 0x3a3f
movl $0x1, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl -0x28(%rbp), %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3a87
jmp 0x3a9e
movl -0x28(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x3a70
movl -0x28(%rbp), %ecx
movq -0x40(%rbp), %rax
xorl (%rax), %ecx
movl %ecx, (%rax)
movq -0x30(%rbp), %rcx
movw 0x14(%rcx), %ax
addw $-0x1, %ax
movw %ax, 0x14(%rcx)
cmpw $0x0, %ax
jne 0x3ae1
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x18, %rcx
subq %rcx, %rax
sarq $0x2, %rax
shlq $0x5, %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movzwl 0x12(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, %ecx
shlq %cl, %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, 0x3978(%rip)      # 0x7494
je 0x3b3e
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
addq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rax
movzwl 0x10(%rax), %eax
movl %eax, %edx
movl $0xd0, %esi
callq 0x1130
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)