// File: /workspace/github_c_makefile_star2_O0/zhou-yuxin[P]redis-aof-no-cow/deps/jemalloc/include/jemalloc/internal/arena.h
// Function: je_arena_run_regind
JEMALLOC_INLINE size_t
arena_run_regind(arena_run_t *run, arena_bin_info_t *bin_info, const void *ptr)
{
	size_t diff, interval, shift, regind;
	arena_chunk_map_misc_t *miscelm = arena_run_to_miscelm(run);
	void *rpages = arena_miscelm_to_rpages(miscelm);

	/*
	 * Freeing a pointer lower than region zero can cause assertion
	 * failure.
	 */
	assert((uintptr_t)ptr >= (uintptr_t)rpages +
	    (uintptr_t)bin_info->reg0_offset);

	/*
	 * Avoid doing division with a variable divisor if possible.  Using
	 * actual division here can reduce allocator throughput by over 20%!
	 */
	diff = (size_t)((uintptr_t)ptr - (uintptr_t)rpages -
	    bin_info->reg0_offset);

	/* Rescale (factor powers of 2 out of the numerator and denominator). */
	interval = bin_info->reg_interval;
	shift = ffs_zu(interval) - 1;
	diff >>= shift;
	interval >>= shift;

	if (interval == 1) {
		/* The divisor was a power of 2. */
		regind = diff;
	} else {
		/*
		 * To divide by a number D that is not a power of two we
		 * multiply by (2^21 / D) and then right shift by 21 positions.
		 *
		 *   X / D
		 *
		 * becomes
		 *
		 *   (X * interval_invs[D - 3]) >> SIZE_INV_SHIFT
		 *
		 * We can omit the first three elements, because we never
		 * divide by 0, and 1 and 2 are both powers of two, which are
		 * handled above.
		 */
#define	SIZE_INV_SHIFT	((sizeof(size_t) << 3) - LG_RUN_MAXREGS)
#define	SIZE_INV(s)	(((ZU(1) << SIZE_INV_SHIFT) / (s)) + 1)
		static const size_t interval_invs[] = {
		    SIZE_INV(3),
		    SIZE_INV(4), SIZE_INV(5), SIZE_INV(6), SIZE_INV(7),
		    SIZE_INV(8), SIZE_INV(9), SIZE_INV(10), SIZE_INV(11),
		    SIZE_INV(12), SIZE_INV(13), SIZE_INV(14), SIZE_INV(15),
		    SIZE_INV(16), SIZE_INV(17), SIZE_INV(18), SIZE_INV(19),
		    SIZE_INV(20), SIZE_INV(21), SIZE_INV(22), SIZE_INV(23),
		    SIZE_INV(24), SIZE_INV(25), SIZE_INV(26), SIZE_INV(27),
		    SIZE_INV(28), SIZE_INV(29), SIZE_INV(30), SIZE_INV(31)
		};

		if (likely(interval <= ((sizeof(interval_invs) / sizeof(size_t))
		    + 2))) {
			regind = (diff * interval_invs[interval - 3]) >>
			    SIZE_INV_SHIFT;
		} else
			regind = diff / interval;
#undef SIZE_INV
#undef SIZE_INV_SHIFT
	}
	assert(diff == regind * interval);
	assert(regind < bin_info->nregs);

	return (regind);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x18, %rsp
movq %rdi, -0x58(%rbp)
movq %rsi, -0x60(%rbp)
movq %rdx, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
subq $0x18, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
leaq 0x552b7(%rip), %rcx     # 0xa40b0
movq (%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
leaq 0x55296(%rip), %rcx     # 0xa40b0
movq (%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
addq 0x55171(%rip), %rcx     # 0xa3fa8
subq %rcx, %rax
movl $0x60, %ecx
xorl %edx, %edx
divq %rcx
addq 0x55155(%rip), %rax     # 0xa3fa0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
shlq $0xc, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
jmp 0x4ee6f
movq -0x68(%rbp), %rax
movq -0x98(%rbp), %rcx
subq %rcx, %rax
movq -0x60(%rbp), %rcx
movl 0x38(%rcx), %ecx
subq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdx
tzcntq %rdx, %rax
addq $0x1, %rax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmoveq %rcx, %rax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rcx
movq -0x70(%rbp), %rax
shrq %cl, %rax
movq %rax, -0x70(%rbp)
movq -0x80(%rbp), %rcx
movq -0x78(%rbp), %rax
shrq %cl, %rax
movq %rax, -0x78(%rbp)
cmpq $0x1, -0x78(%rbp)
jne 0x4eef9
movq -0x70(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x4ef4c
cmpq $0x1f, -0x78(%rbp)
setbe %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x4ef37
movq -0x70(%rbp), %rax
movq -0x78(%rbp), %rdx
subq $0x3, %rdx
leaq 0x426ab(%rip), %rcx     # 0x915d0
imulq (%rcx,%rdx,8), %rax
shrq $0x37, %rax
movq %rax, -0x88(%rbp)
jmp 0x4ef4a
movq -0x70(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x78(%rbp)
movq %rax, -0x88(%rbp)
jmp 0x4ef4c
jmp 0x4ef4e
jmp 0x4ef50
jmp 0x4ef52
jmp 0x4ef54
movq -0x88(%rbp), %rax
addq $0x18, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)