// File: /workspace/github_c_makefile_star2_O3/tvlabs[P]edge264/./edge264_slice.c
// Function: parse_chroma_residual_cabac
static void CAFUNC(parse_chroma_residual)
{
	// As in Intra16x16, DC blocks are parsed to ctx->c[0..15], then transformed to ctx->c[16..31]
	if (mb->f.CodedBlockPatternChromaDC) { // valid also for 4:0:0
		#if !CABAC
			ctx->scan_s = (i8x4){0, 4, 2, 6};
			parse_residual_block_2x2_cavlc(ctx);
			ctx->scan_s = (i8x4){1, 5, 3, 7};
			parse_residual_block_2x2_cavlc(ctx);
		#else
			ctx->ctxIdxOffsets_l = ctxIdxOffsets_chromaDC[0]; // FIXME 4:2:2
			ctx->sig_inc_v[0] = ctx->last_inc_v[0] = sig_inc_chromaDC[0];
			ctx->coeff_abs_inc_l = (i8x8){6, 7, 8, 8};
			if (get_ae(ctx, ctx->ctxIdxOffsets[0] + ctx->inc.coded_block_flags_16x16[1])) {
				mb->f.coded_block_flags_16x16[1] = 1;
				ctx->scan_s = (i8x4){0, 4, 2, 6};
				parse_residual_coeffs_cabac(ctx, 0, 3);
			}
			if (get_ae(ctx, ctx->ctxIdxOffsets[0] + ctx->inc.coded_block_flags_16x16[2])) {
				mb->f.coded_block_flags_16x16[2] = 1;
				ctx->scan_s = (i8x4){1, 5, 3, 7};
				parse_residual_coeffs_cabac(ctx, 0, 3);
			}
		#endif
		transform_dc2x2(ctx);
		
		// Eight or sixteen 4x4 AC blocks for the Cb/Cr components
		if (mb->f.CodedBlockPatternChromaAC) {
			#if CABAC
				ctx->sig_inc_v[0] = ctx->last_inc_v[0] = sig_inc_4x4;
				ctx->ctxIdxOffsets_l = ctxIdxOffsets_chromaAC[0];
				ctx->coeff_abs_inc_l = (i8x8){6, 7, 8, 9, 9};
			#endif
			ctx->scan_v[0] = scan_4x4[0];
			for (int i4x4 = 0; i4x4 < 8; i4x4++) {
				int iYCbCr = 1 + (i4x4 >> 2);
				uint8_t *samples = ctx->samples_mb[iYCbCr] + y420[i4x4] * ctx->t.stride[1] + x420[i4x4];
				int nA = *((int8_t *)mb->nC + 16 + ctx->ACbCr_int8[i4x4]);
				int nB = *((int8_t *)mb->nC + 16 + ctx->BCbCr_int8[i4x4]);
				#if !CABAC
					if (parse_residual_block_4x4_cavlc(ctx, 16 + i4x4, nA, nB, 1))
						add_idct4x4(ctx, iYCbCr, i4x4, samples);
					else
						add_dc4x4(ctx, iYCbCr, i4x4, samples);
				#else
					if (get_ae(ctx, ctx->ctxIdxOffsets[0] + ctx->nC_inc[1][i4x4] + nA + nB * 2)) {
						mb->nC[16 + i4x4] = 1;
						parse_residual_coeffs_cabac(ctx, 1, 15);
						add_idct4x4(ctx, iYCbCr, i4x4, samples);
					} else {
						add_dc4x4(ctx, iYCbCr, i4x4, samples);
					}
				#endif
			}
		}
		ctx->c_v[4] = ctx->c_v[5] = (i8x16){};
	}
}

// Assembly:
movq 0x680(%rdi), %rax
cmpb $0x0, 0x26(%rax)
je 0x17fe7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
vmovaps 0x1bc05(%rip), %xmm0    # 0x33a20
vmovaps %xmm0, 0x1a10(%rdi)
vmovsd 0x1bc05(%rip), %xmm0    # 0x33a30
vmovaps %xmm0, 0x1a60(%rdi)
vmovaps %xmm0, 0x1a20(%rdi)
movsbl 0x6c9(%rdi), %esi
addl $0x61, %esi
callq 0x16bee
testl %eax, %eax
je 0x17e72
movq 0x680(%rbx), %rax
movb $0x1, 0x29(%rax)
movl $0x6020400, 0x1aa0(%rbx) # imm = 0x6020400
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x177dc
movswl 0x1a10(%rbx), %eax
movsbl 0x6ca(%rbx), %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x16bee
testl %eax, %eax
je 0x17eb2
movq 0x680(%rbx), %rax
movb $0x1, 0x2a(%rax)
movl $0x7030501, 0x1aa0(%rbx) # imm = 0x7030501
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x177dc
movq %rbx, %rdi
callq 0x147fd
movq 0x680(%rbx), %rax
cmpb $0x0, 0x27(%rax)
je 0x17fcd
vmovaps 0x1bb0d(%rip), %xmm0    # 0x339e0
vmovaps %xmm0, 0x1a60(%rbx)
vmovaps %xmm0, 0x1a20(%rbx)
vmovaps 0x1bb55(%rip), %xmm0    # 0x33a40
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x1b745(%rip), %xmm0    # 0x33640
vmovaps %xmm0, 0x1aa0(%rbx)
xorl %r14d, %r14d
leaq 0x1f4c3(%rip), %r12     # 0x373d0
leaq 0x1f4c4(%rip), %r13     # 0x373d8
movl %r14d, %eax
shrl $0x2, %eax
leal 0x1(%rax), %ebp
movsbq (%r14,%r12), %rcx
movzwl 0x36(%rbx), %edx
imulq %rcx, %rdx
addq 0x670(%rbx,%rax,8), %rdx
movsbq (%r14,%r13), %r15
addq %rdx, %r15
movq 0x680(%rbx), %rax
movswq 0xbc0(%rbx,%r14,2), %rcx
movsbl 0x50(%rax,%rcx), %ecx
movslq 0xbe0(%rbx,%r14,4), %rdx
movsbl 0x50(%rax,%rdx), %eax
movswl 0x1a10(%rbx), %edx
addl %ecx, %edx
movsbl 0x710(%rbx,%r14), %ecx
leal (%rdx,%rax,2), %esi
addl %ecx, %esi
movq %rbx, %rdi
callq 0x16bee
testl %eax, %eax
je 0x17fb0
movq 0x680(%rbx), %rax
movb $0x1, 0x50(%rax,%r14)
movq %rbx, %rdi
movl $0x1, %esi
movl $0xf, %edx
callq 0x177dc
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r15, %rcx
callq 0x13280
jmp 0x17fc0
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r15, %rcx
callq 0x14a94
incq %r14
cmpq $0x8, %r14
jne 0x17f14
vxorps %xmm0, %xmm0, %xmm0
vmovaps %ymm0, 0x1ba0(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq