// File: /workspace/github_c_makefile_star2_O3/lh3[P]fermi-lite/mrope.c
// Function: mr_rank2a
void mr_rank2a(const mrope_t *mr, int64_t x, int64_t y, int64_t *cx, int64_t *cy)
{
	int a, b;
	int64_t z, c[6], l;
	memset(c, 0, 48);
	for (a = 0, z = 0; a < 6; ++a) {
		const int64_t *ca = mr->r[a]->c;
		l = ca[0] + ca[1] + ca[2] + ca[3] + ca[4] + ca[5];
		if (z + l >= x) break;
		for (b = 0; b < 6; ++b) c[b] += ca[b];
		z += l;
	}
	assert(a != 6);
	if (y >= 0 && z + l >= y) { // [x,y) is in the same bucket
		rope_rank2a(mr->r[a], x - z, y - z, cx, cy);
		for (b = 0; b < 6; ++b)
			cx[b] += c[b], cy[b] += c[b];
		return;
	}
	if (x != z) rope_rank1a(mr->r[a], x - z, cx);
	else memset(cx, 0, 48);
	for (b = 0; b < 6; ++b)
		cx[b] += c[b], c[b] += mr->r[a]->c[b];
	if (y < 0) return;
	for (++a, z += l; a < 6; ++a) {
		const int64_t *ca = mr->r[a]->c;
		l = ca[0] + ca[1] + ca[2] + ca[3] + ca[4] + ca[5];
		if (z + l >= y) break;
		for (b = 0; b < 6; ++b) c[b] += ca[b];
		z += l;
	}
	assert(a != 6);
	if (y != z + l) rope_rank1a(mr->r[a], y - z, cy);
	else for (b = 0; b < 6; ++b) cy[b] = mr->r[a]->c[b];
	for (b = 0; b < 6; ++b) cy[b] += c[b];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r12
movq %rdx, %r9
movq %rdi, %r15
pxor %xmm0, %xmm0
movdqa %xmm0, 0x30(%rsp)
movdqa %xmm0, 0x20(%rsp)
movdqa %xmm0, 0x10(%rsp)
xorl %ebp, %ebp
xorl %eax, %eax
movq 0x8(%r15,%rbp,8), %rcx
movdqu 0x8(%rcx), %xmm0
movdqu 0x18(%rcx), %xmm1
paddq %xmm0, %xmm1
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
paddq %xmm1, %xmm0
movq %xmm0, %rbx
addq 0x28(%rcx), %rbx
addq 0x30(%rcx), %rbx
leaq (%rbx,%rax), %r13
cmpq %rsi, %r13
jge 0x7c0f
xorl %eax, %eax
movdqu 0x8(%rcx,%rax,8), %xmm0
paddq 0x10(%rsp,%rax,8), %xmm0
movdqa %xmm0, 0x10(%rsp,%rax,8)
addq $0x2, %rax
cmpq $0x6, %rax
jne 0x7bc8
incq %rbp
movq %r13, %rax
cmpq $0x6, %rbp
jne 0x7b94
leaq 0xfa4a(%rip), %rdi      # 0x17641
leaq 0xfa1b(%rip), %rsi      # 0x17619
leaq 0xfa43(%rip), %rcx      # 0x17648
movl $0x52, %edx
callq 0x20e0
testq %r9, %r9
js 0x7c51
cmpq %r9, %r13
jl 0x7c51
movl %ebp, %ecx
movq 0x8(%r15,%rcx,8), %rdi
subq %rax, %rsi
subq %rax, %r9
movq %r9, %rdx
movq %r12, %rcx
movq %r8, %rbx
callq 0x1595c
xorl %eax, %eax
movq 0x10(%rsp,%rax,8), %rcx
addq %rcx, (%r12,%rax,8)
addq %rcx, (%rbx,%rax,8)
incq %rax
cmpq $0x6, %rax
jne 0x7c36
jmp 0x7dbb
subq %rax, %rsi
jne 0x7c73
pxor %xmm0, %xmm0
movdqu %xmm0, 0x20(%r12)
movdqu %xmm0, 0x10(%r12)
movdqu %xmm0, (%r12)
movl %ebp, %r14d
jmp 0x7c9f
movl %ebp, %r14d
movq 0x8(%r15,%r14,8), %rdi
movq $-0x1, %rdx
movq %r12, %rcx
movq %r8, 0x8(%rsp)
xorl %r8d, %r8d
movq %r9, (%rsp)
callq 0x1595c
movq (%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x8(%r15,%r14,8), %rax
xorl %ecx, %ecx
movq 0x10(%rsp,%rcx,8), %rdx
addq %rdx, (%r12,%rcx,8)
addq 0x8(%rax,%rcx,8), %rdx
movq %rdx, 0x10(%rsp,%rcx,8)
incq %rcx
cmpq $0x6, %rcx
jne 0x7ca6
testq %r9, %r9
js 0x7dbb
cmpq $0x4, %rbp
ja 0x7d4f
incq %r14
movq 0x8(%r15,%r14,8), %rax
movdqu 0x8(%rax), %xmm0
movdqu 0x18(%rax), %xmm1
paddq %xmm0, %xmm1
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
paddq %xmm1, %xmm0
movq %xmm0, %rbx
addq 0x28(%rax), %rbx
addq 0x30(%rax), %rbx
leaq (%rbx,%r13), %rcx
cmpq %r9, %rcx
jge 0x7d59
xorl %edx, %edx
movdqu 0x8(%rax,%rdx,8), %xmm0
paddq 0x10(%rsp,%rdx,8), %xmm0
movdqa %xmm0, 0x10(%rsp,%rdx,8)
addq $0x2, %rdx
cmpq $0x6, %rdx
jne 0x7d08
incq %r14
movq %rcx, %r13
cmpq $0x6, %r14
jne 0x7cd4
leaq 0xf90a(%rip), %rdi      # 0x17641
leaq 0xf8db(%rip), %rsi      # 0x17619
leaq 0xf903(%rip), %rcx      # 0x17648
movl $0x65, %edx
callq 0x20e0
leal 0x1(%rbp), %r14d
cmpl $0x6, %r14d
je 0x7d30
addq %r13, %rbx
movl %r14d, %eax
movq 0x8(%r15,%rax,8), %rdi
cmpq %r9, %rbx
jne 0x7d7f
xorl %eax, %eax
movq 0x8(%rdi,%rax,8), %rcx
movq %rcx, (%r8,%rax,8)
incq %rax
cmpq $0x6, %rax
jne 0x7d6b
jmp 0x7d9d
subq %r13, %r9
movq %r9, %rsi
movq $-0x1, %rdx
movq %r8, %rcx
movq %r8, %rbx
xorl %r8d, %r8d
callq 0x1595c
movq %rbx, %r8
xorl %eax, %eax
movdqu (%r8,%rax,8), %xmm0
paddq 0x10(%rsp,%rax,8), %xmm0
movdqu %xmm0, (%r8,%rax,8)
addq $0x2, %rax
cmpq $0x6, %rax
jne 0x7d9f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq