// File: /workspace/github_c_makefile_star2_O3/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 0x16bee
testl %eax, %eax
je 0x1783f
btsq %r12, %r15
movswl 0x1a14(%rbx), %eax
movsbl 0x1a60(%rbx,%r12), %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x16bee
testl %eax, %eax
jne 0x17849
incq %r12
cmpq %r13, %r12
jl 0x177ff
jmp 0x1784c
movl %r12d, %r14d
btsq %r14, %r15
movswl 0x1a16(%rbx), %r14d
leal 0x1(%r14), %ebp
addl $0x5, %r14d
leaq 0x1fa09(%rip), %r12     # 0x37270
movq %rbx, %rdi
movl %ebp, %esi
callq 0x16bee
testl %eax, %eax
je 0x17967
movl $0x2, %r13d
movq %rbx, %rdi
movl %r14d, %esi
callq 0x16bee
testl %eax, %eax
je 0x1789d
incl %r13d
cmpl $0xf, %r13d
jne 0x1787f
movl $0xf, %r13d
movswl 0x1a16(%rbx), %ebp
subl %ebp, %r14d
addl $-0x5, %r14d
movslq %r14d, %rax
movsbl 0x1a18(%rbx,%rax), %r14d
addl %ebp, %r14d
movq 0x10(%rbx), %rcx
cmpl $0xf, %r13d
jb 0x179f9
lzcntq %rcx, %rsi
movq %rcx, %rax
shrq $0x32, %rax
jne 0x17ac8
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 0x17bf6
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 0x1c3b5(%rip), %xmm3 # 0x33ccd
vpcmpltub %xmm3, %xmm0, %k1
vptestnmb %xmm1, %xmm1, %k0 {%k1}
vpmovb2m %xmm2, %k1
ktestw %k1, %k0
jne 0x17c23
addq %rax, %rcx
movq %rcx, (%rbx)
vmovq %xmm0, %rdx
bswapq %rdx
movq 0x18(%rbx), %rax
movl %esi, %ecx
andl $0x38, %ecx
movq %rax, (%rsp)
shldq %cl, %rdx, %rax
movl %esi, %ecx
andb $0x38, %cl
shlxq %rcx, 0x10(%rbx), %rcx
andl $0x7, %esi
jmp 0x17acc
movq 0x10(%rbx), %rcx
cmpq $0x200, %rcx            # imm = 0x200
jae 0x17a87
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %rax, %rcx
subq %rdx, %rcx
cmpq $-0xe, %rcx
jg 0x17b93
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 0x1c31e(%rip), %xmm3 # 0x33ccd
vpcmpltub %xmm3, %xmm0, %k1
vptestnmb %xmm1, %xmm1, %k0 {%k1}
vpmovb2m %xmm2, %k1
ktestw %k1, %k0
jne 0x17baa
addq $0x6, %rax
movq %rax, (%rbx)
vmovq %xmm0, %rdx
bswapq %rdx
movq 0x18(%rbx), %rax
movq %rax, (%rsp)
movl $0x30, %ecx
shldq %cl, %rdx, %rax
movq 0x10(%rbx), %rcx
shlq $0x30, %rcx
jmp 0x17a8b
cmpq $0x200, %rcx            # imm = 0x200
jae 0x17b40
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %rax, %rcx
subq %rdx, %rcx
cmpq $-0xe, %rcx
jg 0x17c0c
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 0x1c290(%rip), %xmm3 # 0x33ccd
vpcmpltub %xmm3, %xmm0, %k1
vptestnmb %xmm1, %xmm1, %k0 {%k1}
vpmovb2m %xmm2, %k1
ktestw %k1, %k0
jne 0x17c84
addq $0x6, %rax
movq %rax, (%rbx)
vmovq %xmm0, %rdx
bswapq %rdx
movq 0x18(%rbx), %rax
movq %rax, (%rsp)
movl $0x30, %ecx
shldq %cl, %rdx, %rax
movq 0x10(%rbx), %rcx
shlq $0x30, %rcx
jmp 0x17b44
movq 0x18(%rbx), %rax
movswl 0x1a16(%rbx), %edx
subl %edx, %ebp
movslq %ebp, %rsi
movsbl (%rsi,%r12), %ebp
addl %edx, %ebp
shrq %rcx
movq %rcx, 0x10(%rbx)
cmpq %rcx, %rax
movl $0x0, %edx
cmovaeq %rcx, %rdx
movl $0x0, %esi
adcl $-0x1, %esi
subq %rdx, %rax
movq %rax, 0x18(%rbx)
orl $0x1, %esi
jmp 0x17b67
movq 0x18(%rbx), %rax
movb $0x37, %dl
subb %sil, %dl
shrxq %rdx, %rcx, %rcx
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 0x17b67
movq 0x18(%rbx), %rax
shrq %rcx
movq %rcx, 0x10(%rbx)
movl %r13d, %esi
negl %esi
cmpq %rcx, %rax
movl $0x0, %edx
cmovaeq %rcx, %rdx
cmovbl %r13d, %esi
subq %rdx, %rax
movq %rax, 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 0x17867
jmp 0x17de5
testq %rcx, %rcx
js 0x17cd0
addq $0x6, %rax
movq %rax, (%rbx)
xorl %edx, %edx
jmp 0x179db
kandw %k1, %k0, %k0
kmovd %k0, %ecx
movzwl %cx, %ecx
testb $0x3f, %cl
je 0x179cc
tzcntl %ecx, %edx
cmpb $0x2, (%rax,%rdx)
jbe 0x17d03
leal 0x7fffffff(%rcx), %esi
andl %ecx, %esi
movl %esi, %ecx
shrl %ecx
shll $0x4, %edx
leaq 0x1f47e(%rip), %rdi     # 0x37060
vpshufb (%rdx,%rdi), %xmm0, %xmm0
incq %rax
testb $0x7e, %sil
jne 0x17bbe
jmp 0x179cc
testq %rdi, %rdi
js 0x17d2c
addq %rcx, %rax
movq %rax, (%rbx)
xorl %edx, %edx
jmp 0x17943
testq %rcx, %rcx
js 0x17d60
addq $0x6, %rax
movq %rax, (%rbx)
xorl %edx, %edx
jmp 0x17a69
kandw %k1, %k0, %k0
kmovd %k0, %edi
movzwl %di, %edi
bzhil %edx, %edi, %r8d
je 0x17935
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
shlxl %edx, %r8d, %edx
notl %edx
tzcntl %edi, %r8d
cmpb $0x2, (%rax,%r8)
jbe 0x17d93
leal 0x7fffffff(%rdi), %r9d
andl %edi, %r9d
shrl %r9d
shll $0x4, %r8d
leaq 0x1f3f2(%rip), %rdi     # 0x37060
vpshufb (%r8,%rdi), %xmm0, %xmm0
incq %rax
movl %r9d, %edi
testl %edx, %r9d
jne 0x17c46
jmp 0x17935
kandw %k1, %k0, %k0
kmovd %k0, %ecx
movzwl %cx, %ecx
testb $0x3f, %cl
je 0x17a5a
tzcntl %ecx, %edx
cmpb $0x2, (%rax,%rdx)
jbe 0x17dbc
leal 0x7fffffff(%rcx), %esi
andl %ecx, %esi
movl %esi, %ecx
shrl %ecx
shll $0x4, %edx
leaq 0x1f3a4(%rip), %rdi     # 0x37060
vpshufb (%rdx,%rdi), %xmm0, %xmm0
incq %rax
testb $0x7e, %sil
jne 0x17c98
jmp 0x17a5a
leaq -0x2(%rax), %rsi
leaq -0x1(%rdx), %rdi
andq $-0x10, %rdi
cmpq %rdi, %rsi
cmovsq %rsi, %rdi
vmovdqu (%rdi), %xmm0
subq %rdi, %rdx
leaq 0x1c56f(%rip), %rsi     # 0x34260
vpshufb (%rdx,%rsi), %xmm0, %xmm0
vpshufb 0x1e(%rcx,%rsi), %xmm0, %xmm1
jmp 0x17994
leaq (%rax,%rdx), %rcx
addq $-0x2, %rcx
movq %rcx, 0x8(%rbx)
leaq 0x1c54a(%rip), %rcx     # 0x34260
subq %rdx, %rcx
vpcmpeqd %xmm1, %xmm1, %xmm1
vpshufb 0x10(%rcx), %xmm1, %xmm1
vpandn %xmm0, %xmm1, %xmm0
jmp 0x179cc
leaq -0x2(%rax), %r9
leaq -0x1(%r8), %r10
andq $-0x10, %r10
cmpq %r10, %r9
cmovsq %r9, %r10
vmovdqu (%r10), %xmm0
subq %r10, %r8
leaq 0x1c512(%rip), %r9      # 0x34260
vpshufb (%r8,%r9), %xmm0, %xmm0
vpshufb 0x1e(%rdi,%r9), %xmm0, %xmm1
jmp 0x178fd
leaq -0x2(%rax), %rsi
leaq -0x1(%rdx), %rdi
andq $-0x10, %rdi
cmpq %rdi, %rsi
cmovsq %rsi, %rdi
vmovdqu (%rdi), %xmm0
subq %rdi, %rdx
leaq 0x1c4df(%rip), %rsi     # 0x34260
vpshufb (%rdx,%rsi), %xmm0, %xmm0
vpshufb 0x1e(%rcx,%rsi), %xmm0, %xmm1
jmp 0x17a22
leaq (%rax,%r8), %rdx
addq $-0x2, %rdx
movq %rdx, 0x8(%rbx)
leaq 0x1c4ba(%rip), %rdx     # 0x34260
subq %r8, %rdx
vpcmpeqd %xmm1, %xmm1, %xmm1
vpshufb 0x10(%rdx), %xmm1, %xmm1
vpandn %xmm0, %xmm1, %xmm0
jmp 0x17935
leaq (%rax,%rdx), %rcx
addq $-0x2, %rcx
movq %rcx, 0x8(%rbx)
leaq 0x1c491(%rip), %rcx     # 0x34260
subq %rdx, %rcx
vpcmpeqd %xmm1, %xmm1, %xmm1
vpshufb 0x10(%rcx), %xmm1, %xmm1
vpandn %xmm0, %xmm1, %xmm0
jmp 0x17a5a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq