// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi-lite/rope.c
// Function: rope_count_to_leaf
static rpnode_t *rope_count_to_leaf(const rope_t *rope, int64_t x, int64_t cx[6], int64_t *rest)
{
	rpnode_t *u, *v = 0, *p = rope->root;
	int64_t y = 0;
	int a;

	memset(cx, 0, 48);
	do {
		u = p;
		if (v && x - y > v->l>>1) {
			p += p->n - 1; y += v->l;
			for (a = 0; a != 6; ++a) cx[a] += v->c[a];
			for (; y >= x; --p) {
				y -= p->l;
				for (a = 0; a != 6; ++a) cx[a] -= p->c[a];
			}
			++p;
		} else {
			for (; y + p->l < x; ++p) {
				y += p->l;
				for (a = 0; a != 6; ++a) cx[a] += p->c[a];
			}
		}
		v = p; p = p->p;
	} while (!u->is_bottom);
	*rest = x - y;
	return v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2110
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x23197
movq -0x10(%rbp), %rax
subq -0x40(%rbp), %rax
movq -0x30(%rbp), %rdx
movabsq $0x3fffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFF
andq 0x8(%rdx), %rcx
shrq %rcx
cmpq %rcx, %rax
jbe 0x23197
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x36, %rax
andq $0x1ff, %rax            # imm = 0x1FF
movl %eax, %ecx
subl $0x1, %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
movabsq $0x3fffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFF
andq 0x8(%rcx), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x6, -0x44(%rbp)
je 0x23115
movq -0x30(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x230e7
jmp 0x23117
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jl 0x23186
movq -0x38(%rbp), %rax
movabsq $0x3fffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFF
andq 0x8(%rax), %rcx
movq -0x40(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x6, -0x44(%rbp)
je 0x23176
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x23145
jmp 0x23178
movq -0x38(%rbp), %rax
addq $-0x40, %rax
movq %rax, -0x38(%rbp)
jmp 0x23117
movq -0x38(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x38(%rbp)
jmp 0x23219
jmp 0x23199
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rdx
movabsq $0x3fffffffffffff, %rcx # imm = 0x3FFFFFFFFFFFFF
andq 0x8(%rdx), %rcx
addq %rcx, %rax
cmpq -0x10(%rbp), %rax
jae 0x23217
movq -0x38(%rbp), %rcx
movabsq $0x3fffffffffffff, %rax # imm = 0x3FFFFFFFFFFFFF
andq 0x8(%rcx), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x6, -0x44(%rbp)
je 0x23207
movq -0x38(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq 0x10(%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x231d9
jmp 0x23209
movq -0x38(%rbp), %rax
addq $0x40, %rax
movq %rax, -0x38(%rbp)
jmp 0x23199
jmp 0x23219
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x3f, %rax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x23064
movq -0x10(%rbp), %rcx
subq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)