// File: /workspace/github_c_makefile_star2_O0/lh3[P]fermi-lite/rle.c
// Function: rle_insert_cached
int rle_insert_cached(uint8_t *block, int64_t x, int a, int64_t rl, int64_t cnt[6], const int64_t ec[6], int *beg, int64_t bc[6])
{
	uint16_t *nptr = (uint16_t*)block;
	int diff;

	block += 2; // skip the first 2 counting bytes
	if (*nptr == 0) {
		memset(cnt, 0, 48);
		diff = rle_enc1(block, a, rl);
	} else {
		uint8_t *p, *end = block + *nptr, *q;
		int64_t pre, z, l = 0, tot, beg_l;
		int c = -1, n_bytes = 0, n_bytes2, t = 0;
		uint8_t tmp[24];
		beg_l = bc[0] + bc[1] + bc[2] + bc[3] + bc[4] + bc[5];
		tot   = ec[0] + ec[1] + ec[2] + ec[3] + ec[4] + ec[5];
		if (x < beg_l) {
			beg_l = 0, *beg = 0;
			memset(bc, 0, 48);
		}
		if (x == beg_l) {
			p = q = block + (*beg); z = beg_l;
			memcpy(cnt, bc, 48);
		} else if (x - beg_l <= ((tot-beg_l)>>1) + ((tot-beg_l)>>3)) { // forward
			z = beg_l; p = block + (*beg);
			memcpy(cnt, bc, 48);
			while (z < x) {
				rle_dec1(p, c, l);
				z += l; cnt[c] += l;
			}
			for (q = p - 1; *q>>6 == 2; --q);
		} else { // backward
			memcpy(cnt, ec, 48);
			z = tot; p = end;
			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;
				}
			}
			q = p;
			rle_dec1(p, c, l);
			z += l; cnt[c] += l;
		}
		*beg = q - block;
		memcpy(bc, cnt, 48);
		bc[c] -= l;
		n_bytes = p - q;
		if (x == z && a != c && p < end) { // then try the next run
			int tc;
			int64_t tl;
			q = p;
			rle_dec1(q, tc, tl);
			if (a == tc)
				c = tc, n_bytes = q - p, l = tl, z += l, p = q, cnt[tc] += tl;
		}
		if (z != x) cnt[c] -= z - x;
		pre = x - (z - l); p -= n_bytes;
		if (a == c) { // insert to the same run
			n_bytes2 = rle_enc1(tmp, c, l + rl);
		} else if (x == z) { // at the end; append to the existing run
			p += n_bytes; n_bytes = 0;
			n_bytes2 = rle_enc1(tmp, a, rl);
		} else { // break the current run
			n_bytes2 = rle_enc1(tmp, c, pre);
			n_bytes2 += rle_enc1(tmp + n_bytes2, a, rl);
			n_bytes2 += rle_enc1(tmp + n_bytes2, c, l - pre);
		}
		if (n_bytes != n_bytes2 && end != p + n_bytes) // size changed
			memmove(p + n_bytes2, p + n_bytes, end - p - n_bytes);
		memcpy(p, tmp, n_bytes2);
		diff = n_bytes2 - n_bytes;
	}
	return (*nptr += diff);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x8(%rbp)
movq -0x38(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0x23582
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2110
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x23ea0
movl %eax, -0x3c(%rbp)
jmp 0x23e85
movq -0x8(%rbp), %rax
movq -0x38(%rbp), %rcx
movzwl (%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x70(%rbp)
movl $0xffffffff, -0x84(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x88(%rbp)
movl $0x0, -0x90(%rbp)
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rbp), %rcx
addq 0x8(%rcx), %rax
movq 0x18(%rbp), %rcx
addq 0x10(%rcx), %rax
movq 0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
movq 0x18(%rbp), %rcx
addq 0x20(%rcx), %rax
movq 0x18(%rbp), %rcx
addq 0x28(%rcx), %rax
movq %rax, -0x80(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
addq 0x8(%rcx), %rax
movq -0x30(%rbp), %rcx
addq 0x10(%rcx), %rax
movq -0x30(%rbp), %rcx
addq 0x18(%rcx), %rax
movq -0x30(%rbp), %rcx
addq 0x20(%rcx), %rax
movq -0x30(%rbp), %rcx
addq 0x28(%rcx), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x80(%rbp), %rax
jge 0x2364f
movq $0x0, -0x80(%rbp)
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
movq 0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2110
movq -0x10(%rbp), %rax
cmpq -0x80(%rbp), %rax
jne 0x2368e
movq -0x8(%rbp), %rax
movq 0x10(%rbp), %rcx
movslq (%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq %rax, -0x48(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
movq 0x18(%rbp), %rsi
movl $0x30, %edx
callq 0x2190
jmp 0x23ac0
movq -0x10(%rbp), %rax
subq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
subq -0x80(%rbp), %rcx
sarq %rcx
movq -0x78(%rbp), %rdx
subq -0x80(%rbp), %rdx
sarq $0x3, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jg 0x2385e
movq -0x80(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rbp), %rcx
movslq (%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq 0x18(%rbp), %rsi
movl $0x30, %edx
callq 0x2190
movq -0x68(%rbp), %rax
cmpq -0x10(%rbp), %rax
jge 0x2382e
jmp 0x236f5
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x7, %eax
movl %eax, -0x84(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x23744
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movzbl (%rax), %eax
sarl $0x3, %eax
cltq
movq %rax, -0x70(%rbp)
jmp 0x23804
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x5, %eax
cmpl $0x6, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x23791
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andq $0x18, %rax
shlq $0x3, %rax
movq -0x48(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
andq $0x3f, %rcx
orq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x23802
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x10, %eax
sarl $0x2, %eax
addl $0x4, %eax
movl %eax, -0xb4(%rbp)
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movzbl (%rax), %eax
sarl $0x3, %eax
andl $0x1, %eax
cltq
movq %rax, -0x70(%rbp)
movl -0xb4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb4(%rbp)
cmpl $0x0, %eax
je 0x23800
movq -0x70(%rbp), %rax
shlq $0x6, %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movzbl (%rcx), %ecx
andq $0x3f, %rcx
orq %rcx, %rax
movq %rax, -0x70(%rbp)
jmp 0x237c5
jmp 0x23802
jmp 0x23804
jmp 0x23806
movq -0x70(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x84(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x236e5
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
sarl $0x6, %eax
cmpl $0x2, %eax
jne 0x23859
jmp 0x2384b
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x2383a
jmp 0x23abe
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x30, %edx
callq 0x2190
movq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x10(%rbp), %rax
jl 0x23982
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x6, %eax
cmpl $0x2, %eax
je 0x23952
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x7, %eax
cmpl $0x0, %eax
je 0x238ed
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x3, %eax
andl $0x7, %eax
movslq %eax, %rcx
leaq 0x25e6(%rip), %rax      # 0x25eb9
movzbl (%rax,%rcx), %eax
sarq $0x4, %rax
movl -0x90(%rbp), %ecx
shlq %cl, %rax
movq %rax, -0xd8(%rbp)
jmp 0x23900
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x3, %eax
cltq
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
orq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rsi
movq -0x28(%rbp), %rax
movq -0x48(%rbp), %rcx
movzbl (%rcx), %ecx
andl $0x7, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x90(%rbp)
jmp 0x2397d
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andq $0x3f, %rax
movl -0x90(%rbp), %ecx
shlq %cl, %rax
orq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x90(%rbp), %eax
addl $0x6, %eax
movl %eax, -0x90(%rbp)
jmp 0x23880
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x7, %eax
movl %eax, -0x84(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x239d9
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movzbl (%rax), %eax
sarl $0x3, %eax
cltq
movq %rax, -0x70(%rbp)
jmp 0x23a99
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
sarl $0x5, %eax
cmpl $0x6, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x23a26
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andq $0x18, %rax
shlq $0x3, %rax
movq -0x48(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
andq $0x3f, %rcx
orq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x23a97
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0x10, %eax
sarl $0x2, %eax
addl $0x4, %eax
movl %eax, -0xb8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movzbl (%rax), %eax
sarl $0x3, %eax
andl $0x1, %eax
cltq
movq %rax, -0x70(%rbp)
movl -0xb8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xb8(%rbp)
cmpl $0x0, %eax
je 0x23a95
movq -0x70(%rbp), %rax
shlq $0x6, %rax
movq -0x48(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movzbl (%rcx), %ecx
andq $0x3f, %rcx
orq %rcx, %rax
movq %rax, -0x70(%rbp)
jmp 0x23a5a
jmp 0x23a97
jmp 0x23a99
jmp 0x23a9b
movq -0x70(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x70(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x84(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x23ac0
movq -0x58(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movq 0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x30, %edx
callq 0x2190
movq -0x70(%rbp), %rsi
movq 0x18(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x88(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x23cc6
movl -0x14(%rbp), %eax
cmpl -0x84(%rbp), %eax
je 0x23cc6
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x23cc6
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
andl $0x7, %eax
movl %eax, -0xbc(%rbp)
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x23b95
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movzbl (%rax), %eax
sarl $0x3, %eax
cltq
movq %rax, -0xc8(%rbp)
jmp 0x23c61
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
sarl $0x5, %eax
cmpl $0x6, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x23be5
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
andq $0x18, %rax
shlq $0x3, %rax
movq -0x58(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
andq $0x3f, %rcx
orq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x58(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
jmp 0x23c5f
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
andl $0x10, %eax
sarl $0x2, %eax
addl $0x4, %eax
movl %eax, -0xcc(%rbp)
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movzbl (%rax), %eax
sarl $0x3, %eax
andl $0x1, %eax
cltq
movq %rax, -0xc8(%rbp)
movl -0xcc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xcc(%rbp)
cmpl $0x0, %eax
je 0x23c5d
movq -0xc8(%rbp), %rax
shlq $0x6, %rax
movq -0x58(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rbp)
movzbl (%rcx), %ecx
andq $0x3f, %rcx
orq %rcx, %rax
movq %rax, -0xc8(%rbp)
jmp 0x23c1c
jmp 0x23c5f
jmp 0x23c61
jmp 0x23c63
movl -0x14(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jne 0x23cc4
movl -0xbc(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x88(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0xc8(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0xbc(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x23cc6
movq -0x68(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x23cee
movq -0x68(%rbp), %rsi
subq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq -0x68(%rbp), %rcx
subq -0x70(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x88(%rbp), %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x84(%rbp), %eax
jne 0x23d4a
leaq -0xb0(%rbp), %rdi
movl -0x84(%rbp), %esi
movq -0x70(%rbp), %rdx
addq -0x20(%rbp), %rdx
callq 0x23ea0
movl %eax, -0x8c(%rbp)
jmp 0x23e04
movq -0x10(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x23d8d
movl -0x88(%rbp), %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x88(%rbp)
leaq -0xb0(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x23ea0
movl %eax, -0x8c(%rbp)
jmp 0x23e02
leaq -0xb0(%rbp), %rdi
movl -0x84(%rbp), %esi
movq -0x60(%rbp), %rdx
callq 0x23ea0
movl %eax, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
movslq -0x8c(%rbp), %rax
addq %rax, %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
callq 0x23ea0
addl -0x8c(%rbp), %eax
movl %eax, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
movslq -0x8c(%rbp), %rax
addq %rax, %rdi
movl -0x84(%rbp), %esi
movq -0x70(%rbp), %rdx
subq -0x60(%rbp), %rdx
callq 0x23ea0
addl -0x8c(%rbp), %eax
movl %eax, -0x8c(%rbp)
jmp 0x23e04
movl -0x88(%rbp), %eax
cmpl -0x8c(%rbp), %eax
je 0x23e5f
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq -0x88(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x23e5f
movq -0x48(%rbp), %rdi
movslq -0x8c(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movslq -0x88(%rbp), %rax
addq %rax, %rsi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rax
subq %rax, %rdx
movslq -0x88(%rbp), %rax
subq %rax, %rdx
callq 0x2220
movq -0x48(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movslq -0x8c(%rbp), %rdx
callq 0x2190
movl -0x8c(%rbp), %eax
subl -0x88(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edx
movq -0x38(%rbp), %rcx
movzwl (%rcx), %eax
addl %edx, %eax
movw %ax, (%rcx)
movzwl %ax, %eax
addq $0xe0, %rsp
popq %rbp
retq