// File: /workspace/github_c_makefile_star2_O2/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 0x13a38
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 0x1380e
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 0x1399a
leaq 0x180a(%rip), %r9       # 0x14fb1
xorl %ecx, %ecx
xorl %edi, %edi
movq %rdx, %rbx
subq %r11, %rbx
jg 0x13956
movzbl -0x1(%r10), %ebx
movl %ebx, %ebp
andl $-0x40, %ebp
cmpl $0x80, %ebp
jne 0x137db
andl $0x3f, %ebx
shlq %cl, %rbx
decq %r10
orq %rbx, %rdi
addq $0x6, %rcx
jmp 0x137ab
movl %ebx, %r14d
shrl $0x3, %r14d
testb %bl, %bl
js 0x137eb
movl %r14d, %r14d
jmp 0x137fb
andl $0x7, %r14d
movzbl (%r14,%r9), %r14d
shrl $0x4, %r14d
shlq %cl, %r14
decq %r10
orq %rdi, %r14
subq %r14, %r11
andl $0x7, %ebx
subq %r14, -0x30(%rsp,%rbx,8)
jmp 0x137a7
pxor %xmm0, %xmm0
movdqa %xmm0, -0x10(%rsp)
movdqa %xmm0, -0x20(%rsp)
movdqa %xmm0, -0x30(%rsp)
xorl %ecx, %ecx
xorl %edi, %edi
movq %rsi, %r9
subq %rdi, %r9
jle 0x138b5
movzbl (%r10), %ecx
testb %cl, %cl
js 0x13853
incq %r10
movl %ecx, %r9d
shrl $0x3, %r9d
andl $0x7, %ecx
addq %r9, %rdi
addq %r9, -0x30(%rsp,%rcx,8)
jmp 0x13828
movl %ecx, %r9d
andl $-0x20, %r9d
cmpl $0xc0, %r9d
jne 0x1387d
movl %ecx, %r9d
andl $0x18, %r9d
movzbl 0x1(%r10), %r11d
andl $0x3f, %r11d
leaq (%r11,%r9,8), %r9
addq $0x2, %r10
jmp 0x13846
movl %ecx, %r11d
shrl $0x2, %r11d
andl $0x4, %r11d
movl %ecx, %r9d
shrl $0x3, %r9d
andl $0x1, %r9d
incq %r10
xorl $-0x3, %r11d
testl %r11d, %r11d
je 0x13846
shlq $0x6, %r9
movzbl (%r10), %ebx
andl $0x3f, %ebx
orq %rbx, %r9
incq %r10
incl %r11d
jmp 0x1389a
xorl %esi, %esi
cmpq $0x6, %rsi
je 0x138cb
movq -0x30(%rsp,%rsi,8), %r11
addq %r11, (%rax,%rsi,8)
incq %rsi
jmp 0x138b7
movl %ecx, %esi
addq %r9, (%rax,%rsi,8)
testq %r8, %r8
je 0x13a34
movq %rdx, %r9
subq %rdi, %r9
jle 0x13979
movzbl (%r10), %ecx
testb %cl, %cl
js 0x13903
incq %r10
movl %ecx, %eax
shrl $0x3, %eax
andl $0x7, %ecx
addq %rax, %rdi
addq %rax, -0x30(%rsp,%rcx,8)
jmp 0x138da
movl %ecx, %eax
andl $-0x20, %eax
cmpl $0xc0, %eax
jne 0x13926
movl %ecx, %eax
andl $0x18, %eax
movzbl 0x1(%r10), %esi
andl $0x3f, %esi
leaq (%rsi,%rax,8), %rax
addq $0x2, %r10
jmp 0x138f6
movl %ecx, %esi
shrl $0x2, %esi
andl $0x4, %esi
movl %ecx, %eax
shrl $0x3, %eax
andl $0x1, %eax
incq %r10
xorl $-0x3, %esi
testl %esi, %esi
je 0x138f6
shlq $0x6, %rax
movzbl (%r10), %r9d
andl $0x3f, %r9d
orq %r9, %rax
incq %r10
incl %esi
jmp 0x1393c
xorl %edx, %edx
cmpq $0x6, %rdx
je 0x1396c
movq -0x30(%rsp,%rdx,8), %r9
addq %r9, (%r8,%rdx,8)
incq %rdx
jmp 0x13958
movzbl (%r10), %edx
andl $0x7, %edx
addq %rbx, (%r8,%rdx,8)
jmp 0x1399e
xorl %eax, %eax
cmpq $0x6, %rax
je 0x1398f
movq -0x30(%rsp,%rax,8), %rdx
addq %rdx, (%r8,%rax,8)
incq %rax
jmp 0x1397b
movl %ecx, %eax
leaq (%r8,%rax,8), %rax
jmp 0x13a31
xorl %ecx, %ecx
xorl %edi, %edi
leaq 0x160c(%rip), %rdx      # 0x14fb1
decq %r10
movl %ecx, %ecx
movq %rsi, %r9
subq %r11, %r9
jg 0x13a0f
movzbl (%r10), %r8d
movl %r8d, %r9d
andl $-0x40, %r9d
cmpl $0x80, %r9d
jne 0x139d9
andl $0x3f, %r8d
shlq %cl, %r8
orq %r8, %rdi
decq %r10
addq $0x6, %rcx
jmp 0x139aa
movl %r8d, %r9d
shrl $0x3, %r9d
testb %r8b, %r8b
js 0x139ea
movl %r9d, %r9d
jmp 0x139fa
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
jmp 0x139a5
xorl %ecx, %ecx
cmpq $0x6, %rcx
je 0x13a25
movq -0x30(%rsp,%rcx,8), %rdx
addq %rdx, (%rax,%rcx,8)
incq %rcx
jmp 0x13a11
movzbl 0x1(%r10), %ecx
andl $0x7, %ecx
leaq (%rax,%rcx,8), %rax
addq %r9, (%rax)
popq %rbx
popq %r14
popq %rbp
retq