// File: /workspace/github_c_makefile_star2_O2/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 0x304a6(%rip), %rbx     # 0x490d0
movq (%rbx), %r12
notq %r12
andq %rdi, %r12
xorl %ebp, %ebp
cmpq %rdi, %r12
je 0x18d3e
subq %r12, %rdi
shrq $0xc, %rdi
leaq 0x30374(%rip), %rax     # 0x48fc0
movq (%rax), %rax
movq %rdi, %rcx
subq %rax, %rcx
movq 0x78(%r12,%rcx,8), %rcx
testb $0x2, %cl
jne 0x18d3e
movq %rsi, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq (%r12), %r15
shrq $0xd, %rcx
subq %rcx, %rdi
leaq 0x30349(%rip), %rcx     # 0x48fc8
movq (%rcx), %rcx
addq %r12, %rcx
imulq $0x60, %rdi, %r13
addq %rcx, %r13
negq %rax
imulq $0x60, %rax, %r14
movl 0x18(%r14,%r13), %ebp
movq 0x2f351(%rip), %rax     # 0x47ff0
movq %fs:0x0, %rsi
addq %rax, %rsi
movl %fs:(%rax), %ecx
testl %ecx, %ecx
je 0x18d4f
cmpl $0x2, %ecx
je 0x18d58
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 0x18d36
addq %r14, %r13
movl 0x18(%r13), %ecx
shlq $0x6, %rcx
leaq 0x2f8e5(%rip), %rsi     # 0x485e0
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)
pushq $0x1
popq %rbp
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 0x18d5f
movl $0x3, %fs:(%rax)
leaq 0x3076e(%rip), %rax     # 0x494d4
movl (%rax), %edi
callq 0xb5b0
testl %eax, %eax
je 0x18cbf
leaq 0x1e005(%rip), %rdi     # 0x36d81
callq 0x3126c
cmpb $0x1, 0x2f798(%rip)     # 0x48520
jne 0x18cbf
callq 0xb070