// File: /workspace/github_c_makefile_star2_O1/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 0x17c5d
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
vmovaps 0x1be65(%rip), %xmm0    # 0x338f0
vmovaps %xmm0, 0x1a10(%rdi)
vmovsd 0x1be65(%rip), %xmm0    # 0x33900
vmovaps %xmm0, 0x1a60(%rdi)
vmovaps %xmm0, 0x1a20(%rdi)
movswl 0x1a10(%rdi), %eax
movsbl 0x6c9(%rdi), %esi
addl %eax, %esi
callq 0x1680d
testl %eax, %eax
je 0x17ae8
movq 0x680(%rbx), %rax
movb $0x1, 0x29(%rax)
movl $0x6020400, 0x1aa0(%rbx) # imm = 0x6020400
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x17435
movswl 0x1a10(%rbx), %eax
movsbl 0x6ca(%rbx), %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x1680d
testl %eax, %eax
je 0x17b28
movq 0x680(%rbx), %rax
movb $0x1, 0x2a(%rax)
movl $0x7030501, 0x1aa0(%rbx) # imm = 0x7030501
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x17435
movq %rbx, %rdi
callq 0x14449
movq 0x680(%rbx), %rax
cmpb $0x0, 0x27(%rax)
je 0x17c43
vmovaps 0x1bd67(%rip), %xmm0    # 0x338b0
vmovaps %xmm0, 0x1a60(%rbx)
vmovaps %xmm0, 0x1a20(%rbx)
vmovaps 0x1bdaf(%rip), %xmm0    # 0x33910
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x1b9bf(%rip), %xmm0    # 0x33530
vmovaps %xmm0, 0x1aa0(%rbx)
xorl %r14d, %r14d
leaq 0x1f6dd(%rip), %r12     # 0x37260
leaq 0x1f6de(%rip), %r13     # 0x37268
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 0x1680d
testl %eax, %eax
je 0x17c26
movq 0x680(%rbx), %rax
movb $0x1, 0x50(%rax,%r14)
movq %rbx, %rdi
movl $0x1, %esi
movl $0xf, %edx
callq 0x17435
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r15, %rcx
callq 0x12ece
jmp 0x17c36
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
movq %r15, %rcx
callq 0x146e0
incq %r14
cmpq $0x8, %r14
jne 0x17b8a
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