// File: /workspace/github_c_makefile_star2_O2/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 0x1494e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
vmovaps 0x1918e(%rip), %xmm0    # 0x2d910
vmovaps %xmm0, 0x1a10(%rdi)
vmovsd 0x1918e(%rip), %xmm0    # 0x2d920
vmovaps %xmm0, 0x1a60(%rdi)
vmovaps %xmm0, 0x1a20(%rdi)
movsbl 0x6c9(%rdi), %esi
addl $0x61, %esi
callq 0x13a0c
testl %eax, %eax
je 0x147d7
movq 0x680(%rbx), %rax
movb $0x1, 0x29(%rax)
movl $0x6020400, 0x1aa0(%rbx) # imm = 0x6020400
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1454a
movswl 0x1a10(%rbx), %eax
movsbl 0x6ca(%rbx), %esi
addl %eax, %esi
movq %rbx, %rdi
callq 0x13a0c
testl %eax, %eax
je 0x14815
movq 0x680(%rbx), %rax
movb $0x1, 0x2a(%rax)
movl $0x7030501, 0x1aa0(%rbx) # imm = 0x7030501
pushq $0x3
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1454a
movq %rbx, %rdi
callq 0x11701
movq 0x680(%rbx), %rax
cmpb $0x0, 0x27(%rax)
je 0x14934
vmovaps 0x1909a(%rip), %xmm0    # 0x2d8d0
vmovaps %xmm0, 0x1a60(%rbx)
vmovaps %xmm0, 0x1a20(%rbx)
vmovaps 0x190e2(%rip), %xmm0    # 0x2d930
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x18ca2(%rip), %xmm0    # 0x2d500
vmovaps %xmm0, 0x1aa0(%rbx)
xorl %r14d, %r14d
leaq 0x1c9f0(%rip), %rbp     # 0x31260
leaq 0x1c9f1(%rip), %r15     # 0x31268
cmpq $0x8, %r14
je 0x14934
movl %r14d, %eax
shrl $0x2, %eax
leal 0x1(%rax), %r12d
movsbq (%r14,%rbp), %rcx
movzwl 0x36(%rbx), %edx
imulq %rcx, %rdx
addq 0x670(%rbx,%rax,8), %rdx
movsbq (%r14,%r15), %r13
addq %rdx, %r13
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 0x13a0c
testl %eax, %eax
je 0x1491b
movq 0x680(%rbx), %rax
movb $0x1, 0x50(%rax,%r14)
movq %rbx, %rdi
pushq $0x1
popq %rsi
pushq $0xf
popq %rdx
callq 0x1454a
movq %rbx, %rdi
movl %r12d, %esi
movl %r14d, %edx
movq %r13, %rcx
callq 0x101ea
jmp 0x1492c
movq %rbx, %rdi
movl %r12d, %esi
movl %r14d, %edx
movq %r13, %rcx
callq 0x1197f
incq %r14
jmp 0x14877
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