// File: /workspace/github_c_makefile_star2_O2/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 %r8, %rbx
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 %eax, %eax
xorl %ecx, %ecx
cmpq $0x6, %rax
je 0x6935
movq 0x8(%r15,%rax,8), %rdx
movdqu 0x8(%rdx), %xmm0
movdqu 0x18(%rdx), %xmm1
paddq %xmm0, %xmm1
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
paddq %xmm1, %xmm0
movq %xmm0, %r13
addq 0x28(%rdx), %r13
addq 0x30(%rdx), %r13
leaq (%rcx,%r13), %rdi
cmpq %rsi, %rdi
jge 0x67bd
xorl %ecx, %ecx
cmpq $0x6, %rcx
je 0x67b5
movq 0x8(%rdx,%rcx,8), %r8
addq %r8, 0x10(%rsp,%rcx,8)
incq %rcx
jmp 0x67a0
incq %rax
movq %rdi, %rcx
jmp 0x6762
leaq (%rcx,%r13), %rbp
testq %r9, %r9
js 0x6804
cmpq %r9, %rbp
jl 0x6804
movl %eax, %eax
movq 0x8(%r15,%rax,8), %rdi
subq %rcx, %rsi
subq %rcx, %r9
movq %r9, %rdx
movq %r12, %rcx
movq %rbx, %r8
callq 0x12c58
xorl %eax, %eax
cmpq $0x6, %rax
je 0x6926
movq 0x10(%rsp,%rax,8), %rcx
addq %rcx, (%r12,%rax,8)
addq %rcx, (%rbx,%rax,8)
incq %rax
jmp 0x67e8
subq %rcx, %rsi
jne 0x6826
pxor %xmm0, %xmm0
movdqu %xmm0, 0x20(%r12)
movdqu %xmm0, 0x10(%r12)
movdqu %xmm0, (%r12)
movl %eax, %r14d
jmp 0x6846
movl %eax, %r14d
movq 0x8(%r15,%r14,8), %rdi
pushq $-0x1
popq %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r9, 0x8(%rsp)
callq 0x12c58
movq 0x8(%rsp), %r9
movq 0x8(%r15,%r14,8), %rax
xorl %ecx, %ecx
cmpq $0x6, %rcx
je 0x686b
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
jmp 0x684d
testq %r9, %r9
js 0x6926
movq %r14, %rax
incq %r14
cmpq $0x4, %rax
ja 0x68d0
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, %r13
addq 0x28(%rax), %r13
addq 0x30(%rax), %r13
movq %r13, %rcx
addq %rbp, %rcx
cmpq %r9, %rcx
jge 0x68d6
xorl %edx, %edx
cmpq $0x6, %rdx
je 0x68cb
movq 0x8(%rax,%rdx,8), %rsi
addq %rsi, 0x10(%rsp,%rdx,8)
incq %rdx
jmp 0x68b6
movq %rcx, %rbp
jmp 0x6874
cmpq $0x6, %r14
je 0x6952
addq %rbp, %r13
movl %r14d, %eax
movq 0x8(%r15,%rax,8), %rdi
cmpq %r9, %r13
jne 0x68fc
xorl %eax, %eax
cmpq $0x6, %rax
je 0x6910
movq 0x8(%rdi,%rax,8), %rcx
movq %rcx, (%rbx,%rax,8)
incq %rax
jmp 0x68e8
subq %rbp, %r9
pushq $-0x1
popq %rdx
movq %r9, %rsi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x12c58
xorl %eax, %eax
cmpq $0x6, %rax
je 0x6926
movq 0x10(%rsp,%rax,8), %rcx
addq %rcx, (%rbx,%rax,8)
incq %rax
jmp 0x6912
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdce6(%rip), %rdi      # 0x14622
leaq 0xdcb7(%rip), %rsi      # 0x145fa
leaq 0xdcdf(%rip), %rcx      # 0x14629
pushq $0x52
popq %rdx
callq 0x20e0
leaq 0xdcc9(%rip), %rdi      # 0x14622
leaq 0xdc9a(%rip), %rsi      # 0x145fa
leaq 0xdcc2(%rip), %rcx      # 0x14629
pushq $0x65
jmp 0x694c