// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x20(%rbp)
movl %esi, -0x24(%rbp)
movl %edx, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movswl 0x1a12(%rax), %esi
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl 0x1a20(%rax,%rcx), %eax
addl %eax, %esi
callq 0x4b0e0
cmpl $0x0, %eax
je 0x4d7e2
movl -0x34(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
orq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movswl 0x1a14(%rax), %esi
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movsbl 0x1a60(%rax,%rcx), %eax
addl %eax, %esi
callq 0x4b0e0
cmpl $0x0, %eax
je 0x4d7e0
jmp 0x4d7f2
jmp 0x4d7e2
jmp 0x4d7e4
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl -0x28(%rbp), %eax
jl 0x4d773
movl -0x34(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
orq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movswl 0x1a16(%rax), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movswl 0x1a16(%rax), %eax
addl $0x5, %eax
movl %eax, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x4b0e0
cmpl $0x0, %eax
jne 0x4d898
movq -0x20(%rbp), %rax
movswl 0x1a16(%rax), %eax
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rdx
movswl 0x1a16(%rdx), %edx
subl %edx, %ecx
movslq %ecx, %rdx
leaq 0x7f7fa(%rip), %rcx     # 0xcd060
movsbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4ce70
cmpl $0x0, %eax
je 0x4d887
xorl %eax, %eax
subl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x4d88d
movl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x4db09
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
xorl %eax, %eax
cmpl $0xf, -0x40(%rbp)
movb %al, -0x69(%rbp)
jge 0x4d8c1
movq -0x20(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x4b0e0
cmpl $0x0, %eax
setne %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x4d8ca
jmp 0x4d8d5
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4d8a1
movq -0x20(%rbp), %rax
movswl 0x1a16(%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x20(%rbp), %rcx
movl -0x3c(%rbp), %edx
subl -0x38(%rbp), %edx
subl $0x5, %edx
movslq %edx, %rdx
movsbl 0x1a18(%rcx,%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
cmpl $0xf, -0x40(%rbp)
jl 0x4dada
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
lzcntq %rax, %rax
movl %eax, -0x44(%rbp)
cmpl $0xd, -0x44(%rbp)
jle 0x4d990
movq -0x20(%rbp), %rdi
movl -0x44(%rbp), %esi
sarl $0x3, %esi
callq 0x4c850
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0x44(%rbp), %eax
andl $-0x8, %eax
movq %rdx, -0x8(%rbp)
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
movl -0x14(%rbp), %ecx
shldq %cl, %rdx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x44(%rbp), %ecx
andl $-0x8, %ecx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
movl -0x44(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x44(%rbp)
movl $0x37, %ecx
subl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shrq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
xorl %edx, %edx
divq 0x10(%rcx)
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
xorl %edx, %edx
divq 0x10(%rcx)
movq %rdx, -0x58(%rbp)
movq -0x50(%rbp), %rax
xorq $-0x1, %rax
movl -0x44(%rbp), %ecx
addl $0x9, %ecx
movl %ecx, %ecx
shlq %cl, %rax
movabsq $0x80000000000, %rcx    # imm = 0x80000000000
orq %rcx, %rax
lzcntq %rax, %rax
movl %eax, -0x5c(%rbp)
movl $0x37, %eax
subl -0x44(%rbp), %eax
movl -0x5c(%rbp), %ecx
shll %ecx
subl %ecx, %eax
subl $0x2, %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq -0x50(%rbp), %rdx
movl -0x60(%rbp), %ecx
shrq %cl, %rdx
movq %rdx, %rcx
shrq %rcx
movq %rcx, -0x78(%rbp)
movl -0x5c(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq -0x78(%rbp), %rcx
subq $0x1, %rdx
andq %rdx, %rcx
orq %rcx, %rax
addq $0xe, %rax
movl %eax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movl -0x60(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x4da7a
xorl %eax, %eax
subl -0x40(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x4da80
movl -0x40(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x60(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq -0x88(%rbp), %rcx
subq $0x1, %rax
andq %rax, %rcx
movq -0x20(%rbp), %rax
imulq 0x10(%rax), %rcx
addq -0x58(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x60(%rbp), %ecx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
jmp 0x4db07
movq -0x20(%rbp), %rdi
callq 0x4ce70
cmpl $0x0, %eax
je 0x4daf5
xorl %eax, %eax
subl -0x40(%rbp), %eax
movl %eax, -0x8c(%rbp)
jmp 0x4dafe
movl -0x40(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x4db09
movq -0x30(%rbp), %rax
lzcntq %rax, %rax
movl %eax, %ecx
movl $0x3f, %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x40(%rbp), %edx
movq -0x20(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x64(%rbp), %rsi
movsbq 0x1aa0(%rcx,%rsi), %rcx
movl %edx, 0x1b60(%rax,%rcx,4)
movl -0x64(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
xorq $-0x1, %rax
andq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x4d829
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)