// File: /workspace/github_c_makefile_star2_O0/USArmyResearchLab[P]ARL_OpenSHMEM/src/xmalloc.c
// Function: free_bytes
static inline void
free_bytes( struct __xmem_struct* xm, void *ptr, size_t idx, struct pginfo *info)
{
    size_t i;
    struct pginfo **mp;
    void *vp;

    /* Find the chunk number on the page */
    i = ((size_t)(uintptr_t)ptr & xm->malloc_pagemask) >> info->shift;

    if (((size_t)(uintptr_t)ptr & (info->size-1))) {
	wrtwarning("modified (chunk-) pointer.\n");
	return;
    }

    if (info->bits[i/MALLOC_BITS] & (1UL << (i % MALLOC_BITS))) {
	wrtwarning("chunk is already free.\n");
	return;
    }

    if (malloc_junk)
		wrtwarning("XXX no filling alloc with junk!\n");

    info->bits[i/MALLOC_BITS] |= (u_int)(1UL << (i % MALLOC_BITS));
    info->free++;

    mp = xm->page_dir + info->shift;

    if (info->free == 1) {

	/* Page became non-full */

	mp = xm->page_dir + info->shift;
	/* Insert in address order */
	while (*mp && (*mp)->next && (*mp)->next->page < info->page)
	    mp = &(*mp)->next;
	info->next = *mp;
	*mp = info;
	return;
    }

    if (info->free != info->total)
	return;

    /* Find & remove this page in the queue */
    while (*mp != info) {
	mp = &((*mp)->next);
#ifdef MALLOC_EXTRA_SANITY
	if (!*mp)
		wrterror("(ES): Not on queue.\n");
#endif /* MALLOC_EXTRA_SANITY */
    }
    *mp = info->next;

    /* Free the page & the info structure if need be */
    xm->page_dir[idx] = MALLOC_FIRST;
    vp = info->page;		/* Order is important ! */
    if(vp != (void*)info) 
	__host_free(info);
    ifree(xm,vp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
andq 0x10(%rcx), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x3751
leaq 0x1d6b(%rip), %rdi      # 0x54b2
callq 0x2ce0
jmp 0x3918
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shrq $0x5, %rcx
movl 0x18(%rax,%rcx,4), %eax
movq -0x28(%rbp), %rcx
andq $0x1f, %rcx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x378e
leaq 0x1d4a(%rip), %rdi      # 0x54ce
callq 0x2ce0
jmp 0x3918
cmpl $0x0, 0x3cff(%rip)      # 0x7494
je 0x37a3
leaq 0x1d48(%rip), %rdi      # 0x54e6
callq 0x2ce0
movq -0x28(%rbp), %rcx
andq $0x1f, %rcx
movl $0x1, %eax
shlq %cl, %rax
movl %eax, %edx
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shrq $0x5, %rcx
orl 0x18(%rax,%rcx,4), %edx
movl %edx, 0x18(%rax,%rcx,4)
movq -0x20(%rbp), %rax
movw 0x14(%rax), %cx
addw $0x1, %cx
movw %cx, 0x14(%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movzwl 0x14(%rax), %eax
cmpl $0x1, %eax
jne 0x3897
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x20(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x39(%rbp)
je 0x3863
movq -0x30(%rbp), %rax
movq (%rax), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x39(%rbp)
je 0x3863
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x8(%rcx), %rax
setb %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x386c
jmp 0x3879
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x3826
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x3918
movq -0x20(%rbp), %rax
movzwl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
movzwl 0x16(%rcx), %ecx
cmpl %ecx, %eax
je 0x38ad
jmp 0x3918
jmp 0x38af
movq -0x30(%rbp), %rax
movq (%rax), %rax
cmpq -0x20(%rbp), %rax
je 0x38c9
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x38af
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl $0x2, %edx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x390b
movq -0x20(%rbp), %rdi
callq 0x3980
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2d20
addq $0x40, %rsp
popq %rbp
retq
nop