// File: /workspace/github_c_makefile_star2_O0/tvlabs[P]edge264/./edge264_slice.c
// Function: parse_residual_coeffs_cavlc
static noinline int parse_residual_coeffs_cavlc(Edge264Context *ctx, int startIdx, int endIdx, int token) {
		int TrailingOnes = token & 3;
		int TotalCoeff = token >> 2;
		
		// parse all level values from end to start
		int32_t level[16];
		size_t signs = ~ctx->t._gb.msb_cache;
		level[0] = (signs >> (SIZE_BIT - 2) & 2) - 1;
		level[1] = (signs >> (SIZE_BIT - 3) & 2) - 1;
		level[2] = (signs >> (SIZE_BIT - 4) & 2) - 1;
		ctx->t._gb.msb_cache = shld(ctx->t._gb.lsb_cache, ctx->t._gb.msb_cache, TrailingOnes);
		ctx->t._gb.lsb_cache <<= TrailingOnes;
		for (int i = TrailingOnes, suffixLength = 1, v, offset; i < TotalCoeff; i++) {
			int level_prefix = clz(ctx->t._gb.msb_cache | (size_t)1 << (SIZE_BIT - 26)); // limit given in 9.2.2.1
			if (level_prefix >= 15) {
				v = level_prefix * 2 - 2;
				offset = (15 << suffixLength) - 4096;
			} else if (i > TrailingOnes || (TotalCoeff > 10 && TrailingOnes < 3)) {
				v = level_prefix + suffixLength + 1;
				offset = (level_prefix - 1) << suffixLength;
			} else if (level_prefix < 14) {
				v = level_prefix + 1;
				offset = level_prefix - 1;
			} else {
				v = 19;
				offset = -2;
			}
			#if SIZE_BIT == 32
				v -= level_prefix;
				ctx->t._gb.msb_cache = shld(ctx->t._gb.lsb_cache, ctx->t._gb.msb_cache, level_prefix);
				if (!(ctx->t._gb.lsb_cache <<= level_prefix))
					refill(&ctx->t._gb, 0);
			#endif
			int levelCode = get_uv(&ctx->t._gb, v) + offset;
			levelCode += (i == TrailingOnes && TrailingOnes < 3) * 2;
			level[i] = (levelCode % 2) ? (-levelCode - 1) >> 1 : (levelCode + 2) >> 1;
			suffixLength = min(suffixLength + (levelCode >= (3 << suffixLength)), 6);
		}
		
		// store level values at proper positions in memory
		int zerosLeft = 0;
		if (TotalCoeff <= endIdx - startIdx)
			zerosLeft = parse_total_zeros(ctx, endIdx, TotalCoeff);
		int8_t *scan = ctx->scan + startIdx + zerosLeft + TotalCoeff - 1;
		ctx->c[*scan] = level[0];
		for (int i = 1, v, run_before; i < TotalCoeff; i++) {
			scan--;
			if (zerosLeft > 0) {
				int threeBits = ctx->t._gb.msb_cache >> (SIZE_BIT - 3);
				if (zerosLeft <= 6 || threeBits > 0) {
					static int8_t run_before_codes[7][8] = {
						{9, 9, 9, 9, 8, 8, 8, 8},
						{18, 18, 17, 17, 8, 8, 8, 8},
						{19, 19, 18, 18, 17, 17, 16, 16},
						{28, 27, 18, 18, 17, 17, 16, 16},
						{29, 28, 27, 26, 17, 17, 16, 16},
						{25, 26, 28, 27, 30, 29, 16, 16},
						{0, 30, 29, 28, 27, 26, 25, 24}};
					int code = run_before_codes[min(zerosLeft, 7) - 1][threeBits];
					v = code >> 3;
					run_before = code & 7;
				} else {
					v = clz(ctx->t._gb.msb_cache) + 1;
					run_before = min(v + 3, zerosLeft);
				}
				scan -= run_before;
				zerosLeft -= run_before;
				ctx->t._gb.msb_cache = shld(ctx->t._gb.lsb_cache, ctx->t._gb.msb_cache, v);
				ctx->t._gb.lsb_cache <<= v;
			}
			ctx->c[*scan] = level[i];
		}
		for (int i = startIdx; i <= endIdx; i++)
			log_mb(ctx, (i < endIdx) ? "%d," : "%d]}\n", ctx->c[ctx->scan[i]]);
		
		// trailing_ones_sign_flags+total_zeros+run_before consumed at most 31 bits, so we can delay refill here
		return ctx->t._gb.lsb_cache ? 1 : refill(&ctx->t._gb, 1);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x50(%rbp)
movl %esi, -0x54(%rbp)
movl %edx, -0x58(%rbp)
movl %ecx, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
sarl $0x2, %eax
movl %eax, -0x64(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
xorq $-0x1, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
shrq $0x3e, %rax
andq $0x2, %rax
subq $0x1, %rax
movl %eax, -0xb0(%rbp)
movq -0xb8(%rbp), %rax
shrq $0x3d, %rax
andq $0x2, %rax
subq $0x1, %rax
movl %eax, -0xac(%rbp)
movq -0xb8(%rbp), %rax
shrq $0x3c, %rax
andq $0x2, %rax
subq $0x1, %rax
movl %eax, -0xa8(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0x60(%rbp), %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 -0x50(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x60(%rbp), %ecx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
movl -0x60(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl $0x1, -0xc0(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x3d8f1
movq -0x50(%rbp), %rcx
movabsq $0x4000000000, %rax     # imm = 0x4000000000
orq 0x18(%rcx), %rax
lzcntq %rax, %rax
movl %eax, -0xcc(%rbp)
cmpl $0xf, -0xcc(%rbp)
jl 0x3d752
movl -0xcc(%rbp), %eax
shll %eax
subl $0x2, %eax
movl %eax, -0xc4(%rbp)
movl -0xc0(%rbp), %ecx
movl $0xf, %eax
shll %cl, %eax
subl $0x1000, %eax           # imm = 0x1000
movl %eax, -0xc8(%rbp)
jmp 0x3d7d8
movl -0xbc(%rbp), %eax
cmpl -0x60(%rbp), %eax
jg 0x3d769
cmpl $0xa, -0x64(%rbp)
jle 0x3d797
cmpl $0x3, -0x60(%rbp)
jge 0x3d797
movl -0xcc(%rbp), %eax
addl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
movl -0xcc(%rbp), %eax
subl $0x1, %eax
movl -0xc0(%rbp), %ecx
shll %cl, %eax
movl %eax, -0xc8(%rbp)
jmp 0x3d7d6
cmpl $0xe, -0xcc(%rbp)
jge 0x3d7c0
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
movl -0xcc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x3d7d4
movl $0x13, -0xc4(%rbp)
movl $0xfffffffe, -0xc8(%rbp) # imm = 0xFFFFFFFE
jmp 0x3d7d6
jmp 0x3d7d8
movq -0x50(%rbp), %rdi
movl -0xc4(%rbp), %esi
callq 0x17b30
addl -0xc8(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xbc(%rbp), %ecx
xorl %eax, %eax
cmpl -0x60(%rbp), %ecx
movb %al, -0xf9(%rbp)
jne 0x3d813
cmpl $0x3, -0x60(%rbp)
setl %al
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
shll %eax
addl -0xd0(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x3d854
xorl %eax, %eax
subl -0xd0(%rbp), %eax
subl $0x1, %eax
sarl %eax
movl %eax, -0x100(%rbp)
jmp 0x3d865
movl -0xd0(%rbp), %eax
addl $0x2, %eax
sarl %eax
movl %eax, -0x100(%rbp)
movl -0x100(%rbp), %ecx
movslq -0xbc(%rbp), %rax
movl %ecx, -0xb0(%rbp,%rax,4)
movl -0xc0(%rbp), %eax
movl -0xd0(%rbp), %ecx
movl %ecx, -0x104(%rbp)
movl -0xc0(%rbp), %ecx
movl $0x3, %edx
shll %cl, %edx
movl -0x104(%rbp), %ecx
cmpl %edx, %ecx
setge %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0x6, -0x34(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x3d8c8
movl -0x30(%rbp), %eax
movl %eax, -0x108(%rbp)
jmp 0x3d8d1
movl -0x34(%rbp), %eax
movl %eax, -0x108(%rbp)
movl -0x108(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x3d6ef
movl $0x0, -0xd4(%rbp)
movl -0x64(%rbp), %eax
movl -0x58(%rbp), %ecx
subl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jg 0x3d91d
movq -0x50(%rbp), %rdi
movl -0x58(%rbp), %esi
movl -0x64(%rbp), %edx
callq 0x3dbc0
movl %eax, -0xd4(%rbp)
movq -0x50(%rbp), %rax
addq $0x1aa0, %rax           # imm = 0x1AA0
movslq -0x54(%rbp), %rcx
addq %rcx, %rax
movslq -0xd4(%rbp), %rcx
addq %rcx, %rax
movslq -0x64(%rbp), %rcx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, -0xe0(%rbp)
movl -0xb0(%rbp), %edx
movq -0x50(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsbq (%rcx), %rcx
movl %edx, 0x1b60(%rax,%rcx,4)
movl $0x1, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x3db51
movq -0xe0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xe0(%rbp)
cmpl $0x0, -0xd4(%rbp)
jle 0x3db19
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3d, %rax
movl %eax, -0xf0(%rbp)
cmpl $0x6, -0xd4(%rbp)
jle 0x3d9c2
cmpl $0x0, -0xf0(%rbp)
jle 0x3da39
movl -0xd4(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x7, -0x3c(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x3d9e5
movl -0x38(%rbp), %eax
movl %eax, -0x10c(%rbp)
jmp 0x3d9ee
movl -0x3c(%rbp), %eax
movl %eax, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x9984f(%rip), %rax     # 0xd7250
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xf0(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
sarl $0x3, %eax
movl %eax, -0xe8(%rbp)
movl -0xf4(%rbp), %eax
andl $0x7, %eax
movl %eax, -0xec(%rbp)
jmp 0x3da8c
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
lzcntq %rax, %rax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
movl -0xe8(%rbp), %ecx
addl $0x3, %ecx
movl -0xd4(%rbp), %eax
movl %ecx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x3da77
movl -0x40(%rbp), %eax
movl %eax, -0x110(%rbp)
jmp 0x3da80
movl -0x44(%rbp), %eax
movl %eax, -0x110(%rbp)
movl -0x110(%rbp), %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %ecx
movq -0xe0(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movl -0xec(%rbp), %ecx
movl -0xd4(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xd4(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0xe8(%rbp), %eax
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rdx
movl -0x2c(%rbp), %ecx
shldq %cl, %rdx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0xe8(%rbp), %ecx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
movslq -0xe4(%rbp), %rax
movl -0xb0(%rbp,%rax,4), %edx
movq -0x50(%rbp), %rax
movq -0xe0(%rbp), %rcx
movsbq (%rcx), %rcx
movl %edx, 0x1b60(%rax,%rcx,4)
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x3d970
movl -0x54(%rbp), %eax
movl %eax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
cmpl -0x58(%rbp), %eax
jg 0x3db78
jmp 0x3db67
movl -0xf8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf8(%rbp)
jmp 0x3db5a
movq -0x50(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x3db90
movl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x3dba4
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x1ca60
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopw %cs:(%rax,%rax)