// File: /workspace/github_c_makefile_star2_O3/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
movdqu (%r9), %xmm0
movdqu 0x10(%r9), %xmm1
paddq %xmm0, %xmm1
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
paddq %xmm1, %xmm0
movq %xmm0, %r11
addq 0x20(%r9), %r11
addq 0x28(%r9), %r11
je 0x16dc6
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 0x16b0d
movdqu (%r9), %xmm0
movdqu 0x10(%r9), %xmm1
movups 0x20(%r9), %xmm2
movaps %xmm2, -0x10(%rsp)
movdqa %xmm1, -0x20(%rsp)
movdqa %xmm0, -0x30(%rsp)
movzwl (%rdi), %ecx
addq %rcx, %r10
testq %r8, %r8
je 0x16bb2
cmpq %rdx, %r11
jge 0x16c92
xorl %ecx, %ecx
xorl %edi, %edi
jmp 0x16cf7
pxor %xmm0, %xmm0
movdqa %xmm0, -0x10(%rsp)
movdqa %xmm0, -0x20(%rsp)
movdqa %xmm0, -0x30(%rsp)
testq %rsi, %rsi
jle 0x16bbb
xorl %ecx, %ecx
movzbl (%r10), %edi
testb %dil, %dil
js 0x16b53
incq %r10
movl %edi, %r9d
shrl $0x3, %r9d
andl $0x7, %edi
addq %r9, %rcx
addq %r9, -0x30(%rsp,%rdi,8)
cmpq %rsi, %rcx
jl 0x16b2e
jmp 0x16bbf
movl %edi, %r9d
andl $-0x20, %r9d
cmpl $0xc0, %r9d
jne 0x16b7d
movl %edi, %r9d
andl $0x18, %r9d
movzbl 0x1(%r10), %r11d
andl $0x3f, %r11d
leaq (%r11,%r9,8), %r9
addq $0x2, %r10
jmp 0x16b41
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 0x16b9a
jmp 0x16b41
xorl %ecx, %ecx
xorl %edi, %edi
jmp 0x16d26
xorl %edi, %edi
xorl %ecx, %ecx
xorl %r9d, %r9d
movdqu (%rax,%r9,8), %xmm0
paddq -0x30(%rsp,%r9,8), %xmm0
movdqu %xmm0, (%rax,%r9,8)
addq $0x2, %r9
cmpq $0x6, %r9
jne 0x16bc2
subq %rcx, %rsi
movl %edi, %r9d
addq %rsi, (%rax,%r9,8)
testq %r8, %r8
je 0x16dc2
cmpq %rdx, %rcx
jge 0x16c66
movzbl (%r10), %edi
testb %dil, %dil
js 0x16c15
incq %r10
movl %edi, %eax
shrl $0x3, %eax
andl $0x7, %edi
addq %rax, %rcx
addq %rax, -0x30(%rsp,%rdi,8)
jmp 0x16bf2
movl %edi, %eax
andl $-0x20, %eax
cmpl $0xc0, %eax
jne 0x16c38
movl %edi, %eax
andl $0x18, %eax
movzbl 0x1(%r10), %esi
andl $0x3f, %esi
leaq (%rsi,%rax,8), %rax
addq $0x2, %r10
jmp 0x16c08
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 0x16c4e
jmp 0x16c08
xorl %eax, %eax
movdqu (%r8,%rax,8), %xmm0
paddq -0x30(%rsp,%rax,8), %xmm0
movdqu %xmm0, (%r8,%rax,8)
addq $0x2, %rax
cmpq $0x6, %rax
jne 0x16c68
subq %rcx, %rdx
movl %edi, %eax
leaq (%r8,%rax,8), %rax
jmp 0x16dbf
xorl %edi, %edi
leaq 0x13c5(%rip), %r9       # 0x18060
xorl %ecx, %ecx
movzbl -0x1(%r10), %ebx
movl %ebx, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x16cbd
andl $0x3f, %ebx
shlq %cl, %rbx
orq %rbx, %rdi
addl $0x6, %ecx
jmp 0x16cef
movl %ebx, %r14d
shrl $0x3, %r14d
testb %bl, %bl
js 0x16ccd
movl %r14d, %r14d
jmp 0x16cdd
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 0x16c9d
xorl %r9d, %r9d
movdqu (%r8,%r9,8), %xmm0
paddq -0x30(%rsp,%r9,8), %xmm0
movdqu %xmm0, (%r8,%r9,8)
addq $0x2, %r9
cmpq $0x6, %r9
jne 0x16cfa
subq %r11, %rdx
movzbl (%r10), %r9d
andl $0x7, %r9d
addq %rdx, (%r8,%r9,8)
cmpq %rsi, %r11
jl 0x16d92
leaq 0x132e(%rip), %rdx      # 0x18060
movzbl -0x1(%r10), %r8d
movl %r8d, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x16d56
andl $0x3f, %r8d
shlq %cl, %r8
orq %r8, %rdi
addl $0x6, %ecx
jmp 0x16d8a
movl %r8d, %r9d
shrl $0x3, %r9d
testb %r8b, %r8b
js 0x16d67
movl %r9d, %r9d
jmp 0x16d77
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 0x16d32
xorl %ecx, %ecx
movdqu (%rax,%rcx,8), %xmm0
paddq -0x30(%rsp,%rcx,8), %xmm0
movdqu %xmm0, (%rax,%rcx,8)
addq $0x2, %rcx
cmpq $0x6, %rcx
jne 0x16d94
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