// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/src/jemalloc.c
// Function: je_get_defrag_hint
JEMALLOC_NOTHROW
je_get_defrag_hint(void* ptr, int *bin_util, int *run_util) {
    int defrag = 0;
    arena_chunk_t *chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
    if (likely(chunk != ptr)) { /* indication that this is not a HUGE alloc */
        size_t pageind = ((uintptr_t)ptr - (uintptr_t)chunk) >> LG_PAGE;
        size_t mapbits = arena_mapbits_get(chunk, pageind);
        if (likely((mapbits & CHUNK_MAP_LARGE) == 0)) { /* indication that this is not a LARGE alloc */
            arena_t *arena = extent_node_arena_get(&chunk->node);
            size_t rpages_ind = pageind - arena_mapbits_small_runind_get(chunk, pageind);
            arena_run_t *run = &arena_miscelm_get_mutable(chunk, rpages_ind)->run;
            arena_bin_t *bin = &arena->bins[run->binind];
            tsd_t *tsd = tsd_fetch();
            malloc_mutex_lock(tsd_tsdn(tsd), &bin->lock);
            /* runs that are in the same chunk in as the current chunk, are likely to be the next currun */
            if (chunk != (arena_chunk_t *)CHUNK_ADDR2BASE(bin->runcur)) {
                arena_bin_info_t *bin_info = &arena_bin_info[run->binind];
                size_t availregs = bin_info->nregs * bin->stats.curruns;
                *bin_util = (bin->stats.curregs<<16) / availregs;
                *run_util = ((bin_info->nregs - run->nfree)<<16) / bin_info->nregs;
                defrag = 1;
            }
	    malloc_mutex_unlock(tsd_tsdn(tsd), &bin->lock);
        }
    }
    return defrag;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x2c959(%rip), %rbx     # 0x4d0d0
movq (%rbx), %r12
notq %r12
andq %rdi, %r12
xorl %ebp, %ebp
cmpq %rdi, %r12
je 0x20895
subq %r12, %rdi
shrq $0xc, %rdi
leaq 0x2c827(%rip), %rax     # 0x4cfc0
movq (%rax), %rax
movq %rdi, %rcx
subq %rax, %rcx
movq 0x78(%r12,%rcx,8), %rcx
testb $0x2, %cl
jne 0x20895
movq %rsi, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq (%r12), %r15
shrq $0xd, %rcx
subq %rcx, %rdi
leaq 0x2c7fc(%rip), %rcx     # 0x4cfc8
movq (%rcx), %rcx
addq %r12, %rcx
leaq (%rdi,%rdi,2), %r13
shlq $0x5, %r13
addq %rcx, %r13
negq %rax
leaq (%rax,%rax,2), %r14
shlq $0x5, %r14
movl 0x18(%r14,%r13), %ebp
movq 0x2b7f4(%rip), %rax     # 0x4bfe8
movq %fs:0x0, %rsi
addq %rax, %rsi
movl %fs:(%rax), %ecx
testl %ecx, %ecx
je 0x208a6
cmpl $0x2, %ecx
je 0x208af
imulq $0xa8, %rbp, %rax
addq %rax, %r15
addq $0x980, %r15            # imm = 0x980
movq %r15, %rdi
callq 0xb5a0
movq (%rbx), %rax
notq %rax
andq 0x50(%r15), %rax
xorl %ebp, %ebp
cmpq %rax, %r12
je 0x2088d
addq %r14, %r13
movl 0x18(%r13), %ecx
shlq $0x6, %rcx
leaq 0x2bd90(%rip), %rsi     # 0x4c5e0
movl 0x20(%rsi,%rcx), %edi
imulq 0xa0(%r15), %rdi
movq 0x78(%r15), %rax
shlq $0x10, %rax
xorl %edx, %edx
divq %rdi
movq 0x8(%rsp), %rdx
movl %eax, (%rdx)
movl 0x20(%rsi,%rcx), %ecx
movl %ecx, %eax
subl 0x1c(%r13), %eax
shll $0x10, %eax
xorl %edx, %edx
divl %ecx
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl $0x1, %ebp
movq %r15, %rdi
callq 0xb380
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %fs:(%rax)
jmp 0x208b6
movl $0x3, %fs:(%rax)
leaq 0x2cc17(%rip), %rax     # 0x4d4d4
movl (%rax), %edi
callq 0xb5b0
testl %eax, %eax
je 0x20814
leaq 0x1b8ae(%rip), %rdi     # 0x3c181
callq 0x35efc
cmpb $0x1, 0x2bc41(%rip)     # 0x4c520
jne 0x20814
callq 0xb070