// File: /workspace/github_c_makefile_star2_O1/lh3[P]fermi-lite/rle.c
// Function: rle_rank2a
void rle_rank2a(const uint8_t *block, int64_t x, int64_t y, int64_t *cx, int64_t *cy, const int64_t ec[6])
{
	int a;
	int64_t tot, cnt[6];
	const uint8_t *p;

	y = y >= x? y : x;
	tot = ec[0] + ec[1] + ec[2] + ec[3] + ec[4] + ec[5];
	if (tot == 0) return;
	if (x <= (tot - y) + (tot>>3)) {
		int c = 0;
		int64_t l, z = 0;
		memset(cnt, 0, 48);
		p = block + 2;
		while (z < x) {
			rle_dec1(p, c, l);
			z += l; cnt[c] += l;
		}
		for (a = 0; a != 6; ++a) cx[a] += cnt[a];
		cx[c] -= z - x;
		if (cy) {
			while (z < y) {
				rle_dec1(p, c, l);
				z += l; cnt[c] += l;
			}
			for (a = 0; a != 6; ++a) cy[a] += cnt[a];
			cy[c] -= z - y;
		}
	} else {
#define move_backward(_x) \
		while (z >= (_x)) { \
			--p; \
			if (*p>>6 != 2) { \
				l |= *p>>7? (int64_t)rle_auxtab[*p>>3&7]>>4 << t : *p>>3; \
				z -= l; cnt[*p&7] -= l; \
				l = 0; t = 0; \
			} else { \
				l |= (*p&0x3fL) << t; \
				t += 6; \
			} \
		} \

		int t = 0;
		int64_t l = 0, z = tot;
		memcpy(cnt, ec, 48);
		p = block + 2 + *(const uint16_t*)block;
		if (cy) {
			move_backward(y)
			for (a = 0; a != 6; ++a) cy[a] += cnt[a];
			cy[*p&7] += y - z;
		}
		move_backward(x)
		for (a = 0; a != 6; ++a) cx[a] += cnt[a];
		cx[*p&7] += x - z;

#undef move_backward
	}
}

// Assembly:
cmpq %rsi, %rdx
cmovleq %rsi, %rdx
movq 0x8(%r9), %r11
addq (%r9), %r11
addq 0x10(%r9), %r11
addq 0x18(%r9), %r11
addq 0x20(%r9), %r11
addq 0x28(%r9), %r11
je 0x16485
pushq %rbp
pushq %r14
pushq %rbx
movq %rcx, %rax
movq %r11, %rcx
subq %rdx, %rcx
movq %r11, %rbx
sarq $0x3, %rbx
addq %rcx, %rbx
leaq 0x2(%rdi), %r10
cmpq %rsi, %rbx
jge 0x161f8
movups (%r9), %xmm0
movups 0x10(%r9), %xmm1
movups 0x20(%r9), %xmm2
movaps %xmm2, -0x10(%rsp)
movaps %xmm1, -0x20(%rsp)
movaps %xmm0, -0x30(%rsp)
movzwl (%rdi), %ecx
addq %rcx, %r10
testq %r8, %r8
je 0x16299
cmpq %rdx, %r11
jge 0x16364
xorl %ecx, %ecx
xorl %edi, %edi
jmp 0x163c9
xorps %xmm0, %xmm0
movaps %xmm0, -0x10(%rsp)
movaps %xmm0, -0x20(%rsp)
movaps %xmm0, -0x30(%rsp)
testq %rsi, %rsi
jle 0x162a2
xorl %ecx, %ecx
movzbl (%r10), %edi
testb %dil, %dil
js 0x1623a
incq %r10
movl %edi, %r9d
shrl $0x3, %r9d
andl $0x7, %edi
addq %r9, %rcx
addq %r9, -0x30(%rsp,%rdi,8)
cmpq %rsi, %rcx
jl 0x16215
jmp 0x162a6
movl %edi, %r9d
andl $-0x20, %r9d
cmpl $0xc0, %r9d
jne 0x16264
movl %edi, %r9d
andl $0x18, %r9d
movzbl 0x1(%r10), %r11d
andl $0x3f, %r11d
leaq (%r11,%r9,8), %r9
addq $0x2, %r10
jmp 0x16228
movl %edi, %r11d
shrl $0x2, %r11d
andl $0x4, %r11d
movl %edi, %r9d
shrl $0x3, %r9d
andl $0x1, %r9d
incq %r10
xorl $-0x3, %r11d
shlq $0x6, %r9
movzbl (%r10), %ebx
andl $0x3f, %ebx
orq %rbx, %r9
incq %r10
incl %r11d
jne 0x16281
jmp 0x16228
xorl %ecx, %ecx
xorl %edi, %edi
jmp 0x163ed
xorl %edi, %edi
xorl %ecx, %ecx
xorl %r9d, %r9d
movq -0x30(%rsp,%r9,8), %r11
addq %r11, (%rax,%r9,8)
incq %r9
cmpq $0x6, %r9
jne 0x162a9
subq %rcx, %rsi
movl %edi, %r9d
addq %rsi, (%rax,%r9,8)
testq %r8, %r8
je 0x16481
cmpq %rdx, %rcx
jge 0x16342
movzbl (%r10), %edi
testb %dil, %dil
js 0x162f1
incq %r10
movl %edi, %eax
shrl $0x3, %eax
andl $0x7, %edi
addq %rax, %rcx
addq %rax, -0x30(%rsp,%rdi,8)
jmp 0x162ce
movl %edi, %eax
andl $-0x20, %eax
cmpl $0xc0, %eax
jne 0x16314
movl %edi, %eax
andl $0x18, %eax
movzbl 0x1(%r10), %esi
andl $0x3f, %esi
leaq (%rsi,%rax,8), %rax
addq $0x2, %r10
jmp 0x162e4
movl %edi, %esi
shrl $0x2, %esi
andl $0x4, %esi
movl %edi, %eax
shrl $0x3, %eax
andl $0x1, %eax
incq %r10
xorl $-0x3, %esi
shlq $0x6, %rax
movzbl (%r10), %r9d
andl $0x3f, %r9d
orq %r9, %rax
incq %r10
incl %esi
jne 0x1632a
jmp 0x162e4
xorl %eax, %eax
movq -0x30(%rsp,%rax,8), %rsi
addq %rsi, (%r8,%rax,8)
incq %rax
cmpq $0x6, %rax
jne 0x16344
subq %rcx, %rdx
movl %edi, %eax
leaq (%r8,%rax,8), %rax
jmp 0x1647e
xorl %edi, %edi
leaq 0x1c04(%rip), %r9       # 0x17f71
xorl %ecx, %ecx
movzbl -0x1(%r10), %ebx
movl %ebx, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x1638f
andl $0x3f, %ebx
shlq %cl, %rbx
orq %rbx, %rdi
addl $0x6, %ecx
jmp 0x163c1
movl %ebx, %r14d
shrl $0x3, %r14d
testb %bl, %bl
js 0x1639f
movl %r14d, %r14d
jmp 0x163af
andl $0x7, %r14d
movzbl (%r14,%r9), %r14d
shrl $0x4, %r14d
shlq %cl, %r14
orq %rdi, %r14
andl $0x7, %ebx
subq %r14, -0x30(%rsp,%rbx,8)
subq %r14, %r11
xorl %ecx, %ecx
xorl %edi, %edi
decq %r10
cmpq %rdx, %r11
jge 0x1636f
xorl %r9d, %r9d
movq -0x30(%rsp,%r9,8), %rbx
addq %rbx, (%r8,%r9,8)
incq %r9
cmpq $0x6, %r9
jne 0x163cc
subq %r11, %rdx
movzbl (%r10), %r9d
andl $0x7, %r9d
addq %rdx, (%r8,%r9,8)
cmpq %rsi, %r11
jl 0x16459
leaq 0x1b78(%rip), %rdx      # 0x17f71
movzbl -0x1(%r10), %r8d
movl %r8d, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x1641d
andl $0x3f, %r8d
shlq %cl, %r8
orq %r8, %rdi
addl $0x6, %ecx
jmp 0x16451
movl %r8d, %r9d
shrl $0x3, %r9d
testb %r8b, %r8b
js 0x1642e
movl %r9d, %r9d
jmp 0x1643e
andl $0x7, %r9d
movzbl (%r9,%rdx), %r9d
shrl $0x4, %r9d
shlq %cl, %r9
orq %rdi, %r9
andl $0x7, %r8d
subq %r9, -0x30(%rsp,%r8,8)
subq %r9, %r11
xorl %ecx, %ecx
xorl %edi, %edi
decq %r10
cmpq %rsi, %r11
jge 0x163f9
xorl %ecx, %ecx
movq -0x30(%rsp,%rcx,8), %rdx
addq %rdx, (%rax,%rcx,8)
incq %rcx
cmpq $0x6, %rcx
jne 0x1645b
subq %r11, %rsi
movzbl (%r10), %ecx
andl $0x7, %ecx
leaq (%rax,%rcx,8), %rax
movq %rsi, %rdx
addq %rdx, (%rax)
popq %rbx
popq %r14
popq %rbp
retq