// File: /workspace/github_c_makefile_star2_O1/tvlabs[P]edge264/./edge264_slice.c
// Function: parse_residual_coeffs_cabac
static noinline void parse_residual_coeffs_cabac(Edge264Context *ctx, int startIdx, int endIdx) {
		// significant_coeff_flags are stored as a bit mask
		uint64_t significant_coeff_flags = 0;
		int i = startIdx;
		do {
			if (get_ae(ctx, ctx->ctxIdxOffsets[1] + ctx->sig_inc[i])) {
				significant_coeff_flags |= (uint64_t)1 << i;
				if (get_ae(ctx, ctx->ctxIdxOffsets[2] + ctx->last_inc[i]))
					break;
			}
		} while (++i < endIdx);
		significant_coeff_flags |= (uint64_t)1 << i;
		
		// Now loop on set bits to parse all non-zero coefficients.
		int ctxIdx0 = ctx->ctxIdxOffsets[3] + 1;
		int ctxIdx1 = ctx->ctxIdxOffsets[3] + 5;
		do {
			int coeff_level = 1;
			if (!get_ae(ctx, ctxIdx0)) {
				static const int8_t trans[5] = {0, 2, 3, 4, 4};
				ctxIdx0 = ctx->ctxIdxOffsets[3] + trans[ctxIdx0 - ctx->ctxIdxOffsets[3]];
				coeff_level = get_bypass(ctx) ? -coeff_level : coeff_level;
			} else {
				coeff_level++;
				while (coeff_level < 15 && get_ae(ctx, ctxIdx1))
					coeff_level++;
				ctxIdx0 = ctx->ctxIdxOffsets[3];
				ctxIdx1 = ctxIdx0 + ctx->coeff_abs_inc[ctxIdx1 - ctxIdx0 - 5];
				#if SIZE_BIT == 32
					if (coeff_level >= 15) {
						// the biggest value to encode is 2^(14+7)-14, for which k=20 (see 9.3.2.3)
						int k = 0;
						while (get_bypass(ctx) && k < 20)
							k++;
						coeff_level = 1;
						while (k--)
							coeff_level += coeff_level + get_bypass(ctx);
						coeff_level += 14;
					}
					coeff_level = get_bypass(ctx) ? -coeff_level : coeff_level;
				#elif SIZE_BIT == 64
					if (coeff_level >= 15) {
						// we need at least 51 bits in codIOffset to get 42 bits with a division by 9 bits
						int zeros = clz(ctx->t._gb.codIRange);
						if (zeros > 64 - 51) {
							ctx->t._gb.codIOffset = shld(get_bytes(&ctx->t._gb, zeros >> 3), ctx->t._gb.codIOffset, zeros & -8);
							ctx->t._gb.codIRange <<= zeros & -8;
							zeros &= 7;
						}
						ctx->t._gb.codIRange >>= 64 - 9 - zeros;
						size_t quo = ctx->t._gb.codIOffset / ctx->t._gb.codIRange; // requested bits are in lsb and zeros+9 empty bits above
						size_t rem = ctx->t._gb.codIOffset % ctx->t._gb.codIRange;
						int k = clz(~quo << (zeros + 9) | (size_t)1 << (SIZE_BIT - 21));
						int unused = 64 - 9 - zeros - k * 2 - 2;
						coeff_level = 14 + (1 << k | (quo >> unused >> 1 & (((size_t)1 << k) - 1)));
						coeff_level = (quo & (size_t)1 << unused) ? -coeff_level : coeff_level;
						ctx->t._gb.codIOffset = (quo & (((size_t)1 << unused) - 1)) * ctx->t._gb.codIRange + rem;
						ctx->t._gb.codIRange <<= unused;
					} else {
						coeff_level = get_bypass(ctx) ? -coeff_level : coeff_level;
					}
				#endif
			}
		
			// scale and store
			int i = 63 - __builtin_clzll(significant_coeff_flags);
			ctx->c[ctx->scan[i]] = coeff_level; // beware, scan is transposed already
			significant_coeff_flags &= ~((uint64_t)1 << i);
		} while (significant_coeff_flags != 0);
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movslq %esi, %r12
movslq %edx, %r13
leal 0x1(%r12), %r14d
cmpl %r14d, %r13d
cmovgl %r13d, %r14d
xorl %r15d, %r15d
movswl 0x1a12(%rbx), %eax
movsbl 0x1a20(%rbx,%r12), %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x1680d
testl %eax, %eax
je 0x17498
btsq %r12, %r15
movswl 0x1a14(%rbx), %eax
movsbl 0x1a60(%rbx,%r12), %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x1680d
testl %eax, %eax
jne 0x174a2
incq %r12
cmpq %r13, %r12
jl 0x17458
jmp 0x174a5
movl %r12d, %r14d
btsq %r14, %r15
movswl 0x1a16(%rbx), %r14d
leal 0x1(%r14), %ebp
addl $0x5, %r14d
leaq 0x1fc80(%rip), %r12     # 0x37140
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1680d
testl %eax, %eax
je 0x17636
movl $0x2, %r13d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1680d
testl %eax, %eax
je 0x174f6
incl %r13d
cmpl $0xf, %r13d
jne 0x174d8
movl $0xf, %r13d
movswl 0x1a16(%rbx), %ebp
subl %ebp, %r14d
addl $-0x5, %r14d
movslq %r14d, %rax
movsbl 0x1a18(%rbx,%rax), %r14d
addl %ebp, %r14d
cmpl $0xf, %r13d
jb 0x17702
movq 0x10(%rbx), %rax
lzcntq %rax, %rsi
shrq $0x32, %rax
jne 0x175ba
movl %esi, %edx
shrl $0x3, %edx
movq (%rbx), %rax
movq 0x8(%rbx), %r8
movq %rax, %rdi
subq %r8, %rdi
movl %edx, %ecx
cmpq $-0xe, %rdi
jg 0x17866
vmovdqu -0x2(%rax), %xmm1
vpxor %xmm0, %xmm0, %xmm0
vpcmpeqb %xmm0, %xmm1, %xmm2
vpsrldq $0x2, %xmm1, %xmm0      # xmm0 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
vpsrldq $0x1, %xmm2, %xmm2      # xmm2 = xmm2[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero
vpbroadcastb 0x1c62f(%rip), %xmm3 # 0x33b9d
vpcmpltub %xmm3, %xmm0, %k1
vptestnmb %xmm1, %xmm1, %k0 {%k1}
vpmovb2m %xmm2, %k1
ktestw %k1, %k0
jne 0x17893
addq %rax, %rcx
movq %rcx, (%rbx)
vmovq %xmm0, %rax
bswapq %rax
movq 0x18(%rbx), %rdx
movl %esi, %ecx
andl $0x38, %ecx
movq %rdx, (%rsp)
shldq %cl, %rax, %rdx
movq %rdx, 0x18(%rbx)
movl %esi, %ecx
andb $0x38, %cl
shlq %cl, 0x10(%rbx)
andl $0x7, %esi
movb $0x37, %al
subb %sil, %al
shrxq %rax, 0x10(%rbx), %rcx
movq 0x18(%rbx), %rax
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
notq %rdi
leal 0x9(%rsi), %r8d
shlxq %r8, %rdi, %rdi
btsq $0x2b, %rdi
lzcntq %rdi, %rdi
leal (%rsi,%rdi,2), %esi
movb $0x35, %r8b
subb %sil, %r8b
shrxq %r8, %rax, %rsi
shrq %rsi
bzhil %edi, %esi, %esi
btsl %edi, %esi
movzbl %r8b, %edi
movl $0xfffffff2, %r9d       # imm = 0xFFFFFFF2
subl %esi, %r9d
addl $0xe, %esi
btq %rdi, %rax
cmovbl %r9d, %esi
bzhiq %rdi, %rax, %rax
imulq %rcx, %rax
addq %rdx, %rax
movq %rax, 0x18(%rbx)
shlxq %r8, %rcx, %rax
movq %rax, 0x10(%rbx)
jmp 0x177b4
cmpq $0x1ff, 0x10(%rbx)      # imm = 0x1FF
ja 0x176bd
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %rax, %rcx
subq %rdx, %rcx
cmpq $-0xe, %rcx
jg 0x177e0
vmovdqu -0x2(%rax), %xmm1
vpxor %xmm0, %xmm0, %xmm0
vpcmpeqb %xmm0, %xmm1, %xmm2
vpsrldq $0x2, %xmm1, %xmm0      # xmm0 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
vpsrldq $0x1, %xmm2, %xmm2      # xmm2 = xmm2[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero
vpbroadcastb 0x1c526(%rip), %xmm3 # 0x33b9d
vpcmpltub %xmm3, %xmm0, %k1
vptestnmb %xmm1, %xmm1, %k0 {%k1}
vpmovb2m %xmm2, %k1
ktestw %k1, %k0
jne 0x177f7
addq $0x6, %rax
movq %rax, (%rbx)
vmovq %xmm0, %rax
bswapq %rax
movq 0x18(%rbx), %rdx
movq %rdx, (%rsp)
movl $0x30, %ecx
shldq %cl, %rax, %rdx
movq %rdx, 0x18(%rbx)
shlq $0x30, 0x10(%rbx)
movswl 0x1a16(%rbx), %eax
subl %eax, %ebp
movslq %ebp, %rcx
movsbl (%rcx,%r12), %ebp
addl %eax, %ebp
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
shrq %rax
movq %rax, 0x10(%rbx)
cmpq %rax, %rcx
movl $0x0, %edx
cmovaeq %rax, %rdx
movl $0x0, %esi
adcl $-0x1, %esi
subq %rdx, %rcx
movq %rcx, 0x18(%rbx)
orl $0x1, %esi
jmp 0x177b4
cmpq $0x1ff, 0x10(%rbx)      # imm = 0x1FF
ja 0x17789
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %rax, %rcx
subq %rdx, %rcx
cmpq $-0xe, %rcx
jg 0x1787c
vmovdqu -0x2(%rax), %xmm1
vpxor %xmm0, %xmm0, %xmm0
vpcmpeqb %xmm0, %xmm1, %xmm2
vpsrldq $0x2, %xmm1, %xmm0      # xmm0 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
vpsrldq $0x1, %xmm2, %xmm2      # xmm2 = xmm2[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero
vpbroadcastb 0x1c45a(%rip), %xmm3 # 0x33b9d
vpcmpltub %xmm3, %xmm0, %k1
vptestnmb %xmm1, %xmm1, %k0 {%k1}
vpmovb2m %xmm2, %k1
ktestw %k1, %k0
jne 0x17917
addq $0x6, %rax
movq %rax, (%rbx)
vmovq %xmm0, %rax
bswapq %rax
movq 0x18(%rbx), %rdx
movq %rdx, (%rsp)
movl $0x30, %ecx
shldq %cl, %rax, %rdx
movq %rdx, 0x18(%rbx)
shlq $0x30, 0x10(%rbx)
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
shrq %rax
movq %rax, 0x10(%rbx)
movl %r13d, %esi
negl %esi
cmpq %rax, %rcx
movl $0x0, %edx
cmovaeq %rax, %rdx
cmovbl %r13d, %esi
subq %rdx, %rcx
movq %rcx, 0x18(%rbx)
bsrq %r15, %rcx
movsbq 0x1aa0(%rbx,%rcx), %rax
movl %esi, 0x1b60(%rbx,%rax,4)
movq $-0x2, %rax
rolq %cl, %rax
andq %rax, %r15
jne 0x174c0
jmp 0x17a55
testq %rcx, %rcx
js 0x17986
addq $0x6, %rax
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x176a3
kandw %k1, %k0, %k0
kmovd %k0, %ecx
movzwl %cx, %ecx
testb $0x3f, %cl
je 0x17694
tzcntl %ecx, %esi
movb (%rax,%rsi), %dl
cmpb $0x2, %dl
jbe 0x1782c
shll $0x4, %esi
leaq 0x1f70f(%rip), %rdi     # 0x36f30
vpshufb (%rsi,%rdi), %xmm0, %xmm0
incq %rax
jmp 0x17850
leaq (%rax,%rsi), %rdi
addq $-0x2, %rdi
movq %rdi, 0x8(%rbx)
leaq 0x1c8f1(%rip), %rdi     # 0x34130
subq %rsi, %rdi
vpcmpeqd %xmm1, %xmm1, %xmm1
vpshufb 0x10(%rdi), %xmm1, %xmm1
vpandn %xmm0, %xmm1, %xmm0
leal 0x7fffffff(%rcx), %esi
andl %ecx, %esi
shrl %esi
movl %esi, %ecx
cmpb $0x2, %dl
ja 0x17802
jmp 0x17694
testq %rdi, %rdi
js 0x179ca
addq %rcx, %rax
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x17599
testq %rcx, %rcx
js 0x17a11
addq $0x6, %rax
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x1776f
kandw %k1, %k0, %k0
kmovd %k0, %edi
movzwl %di, %edi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
shlxl %edx, %r8d, %edx
notl %edx
testl %edx, %edi
je 0x1758b
tzcntl %edi, %r9d
movb (%rax,%r9), %r8b
cmpb $0x2, %r8b
jbe 0x178d8
shll $0x4, %r9d
leaq 0x1f663(%rip), %r10     # 0x36f30
vpshufb (%r9,%r10), %xmm0, %xmm0
incq %rax
jmp 0x178fc
leaq (%rax,%r9), %r10
addq $-0x2, %r10
movq %r10, 0x8(%rbx)
leaq 0x1c845(%rip), %r10     # 0x34130
subq %r9, %r10
vpcmpeqd %xmm1, %xmm1, %xmm1
vpshufb 0x10(%r10), %xmm1, %xmm1
vpandn %xmm0, %xmm1, %xmm0
leal 0x7fffffff(%rdi), %r9d
andl %edi, %r9d
shrl %r9d
movl %r9d, %edi
cmpb $0x2, %r8b
ja 0x178ab
jmp 0x1758b
kandw %k1, %k0, %k0
kmovd %k0, %ecx
movzwl %cx, %ecx
testb $0x3f, %cl
je 0x17760
tzcntl %ecx, %esi
movb (%rax,%rsi), %dl
cmpb $0x2, %dl
jbe 0x1794c
shll $0x4, %esi
leaq 0x1f5ef(%rip), %rdi     # 0x36f30
vpshufb (%rsi,%rdi), %xmm0, %xmm0
incq %rax
jmp 0x17970
leaq (%rax,%rsi), %rdi
addq $-0x2, %rdi
movq %rdi, 0x8(%rbx)
leaq 0x1c7d1(%rip), %rdi     # 0x34130
subq %rsi, %rdi
vpcmpeqd %xmm1, %xmm1, %xmm1
vpshufb 0x10(%rdi), %xmm1, %xmm1
vpandn %xmm0, %xmm1, %xmm0
leal 0x7fffffff(%rcx), %esi
andl %ecx, %esi
shrl %esi
movl %esi, %ecx
cmpb $0x2, %dl
ja 0x17922
jmp 0x17760
leaq -0x2(%rax), %rsi
leaq -0x1(%rdx), %rdi
andq $-0x10, %rdi
cmpq %rdi, %rsi
cmovsq %rsi, %rdi
vmovdqu (%rdi), %xmm0
subq %rdi, %rdx
leaq 0x1c789(%rip), %rsi     # 0x34130
vpshufb (%rdx,%rsi), %xmm0, %xmm0
addl $0xe, %ecx
cmpl $0x10, %ecx
movl $0x10, %edx
cmovgel %edx, %ecx
movslq %ecx, %rcx
vpshufb 0x10(%rcx,%rsi), %xmm0, %xmm1
jmp 0x1765c
leaq -0x2(%rax), %r9
leaq -0x1(%r8), %r10
andq $-0x10, %r10
cmpq %r10, %r9
cmovsq %r9, %r10
vmovdqu (%r10), %xmm0
subq %r10, %r8
leaq 0x1c744(%rip), %r9      # 0x34130
vpshufb (%r8,%r9), %xmm0, %xmm0
addl $0xe, %edi
cmpl $0x10, %edi
movl $0x10, %r8d
cmovgel %r8d, %edi
movslq %edi, %rdi
vpshufb 0x10(%rdi,%r9), %xmm0, %xmm1
jmp 0x17553
leaq -0x2(%rax), %rsi
leaq -0x1(%rdx), %rdi
andq $-0x10, %rdi
cmpq %rdi, %rsi
cmovsq %rsi, %rdi
vmovdqu (%rdi), %xmm0
subq %rdi, %rdx
leaq 0x1c6fe(%rip), %rsi     # 0x34130
vpshufb (%rdx,%rsi), %xmm0, %xmm0
addl $0xe, %ecx
cmpl $0x10, %ecx
movl $0x10, %edx
cmovgel %edx, %ecx
movslq %ecx, %rcx
vpshufb 0x10(%rcx,%rsi), %xmm0, %xmm1
jmp 0x17728
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq