// File: /workspace/github_c_makefile_star2_O2/tvlabs[P]edge264/./edge264_slice.c
// Function: parse_NxN_residual_cabac
static void CAFUNC(parse_NxN_residual)
{
	static const int8_t Intra4x4Modes[9][16] = {
		{I4x4_V_8  , I4x4_V_8   , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_V_8   , I4x4_V_8   , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_V_8   , I4x4_V_8   , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_V_8   , I4x4_V_8   , I4x4_DCAB_8, I4x4_DCAB_8},
		{I4x4_H_8  , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8, I4x4_H_8   , I4x4_DCAB_8},
		{I4x4_DC_8 , I4x4_DCA_8 , I4x4_DCB_8 , I4x4_DCAB_8, I4x4_DC_8  , I4x4_DCA_8 , I4x4_DCB_8 , I4x4_DCAB_8, I4x4_DC_8  , I4x4_DCA_8 , I4x4_DCB_8 , I4x4_DCAB_8, I4x4_DC_8  , I4x4_DCA_8 , I4x4_DCB_8 , I4x4_DCAB_8},
		{I4x4_DDL_8, I4x4_DDL_8 , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DDLC_8, I4x4_DDLC_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DDL_8 , I4x4_DDL_8 , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DDLC_8, I4x4_DDLC_8, I4x4_DCAB_8, I4x4_DCAB_8},
		{I4x4_DDR_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DDR_8 , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8},
		{I4x4_VR_8 , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_VR_8  , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8},
		{I4x4_HD_8 , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_HD_8  , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8, I4x4_DCAB_8},
		{I4x4_VL_8 , I4x4_VL_8  , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_VLC_8 , I4x4_VLC_8 , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_VL_8  , I4x4_VL_8  , I4x4_DCAB_8, I4x4_DCAB_8, I4x4_VLC_8 , I4x4_VLC_8 , I4x4_DCAB_8, I4x4_DCAB_8},
		{I4x4_HU_8 , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8, I4x4_HU_8  , I4x4_DCAB_8},
	};
	static const int8_t Intra8x8Modes[9][16] = {
		{I8x8_V_8  , I8x8_V_8    , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_V_C_8  , I8x8_V_C_8  , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_V_D_8  , I8x8_V_D_8  , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_V_CD_8  , I8x8_V_CD_8  , I8x8_DC_AB_8, I8x8_DC_AB_8},
		{I8x8_H_8  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_8},
		{I8x8_HD_8 , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_HD_8   , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_DC_AB_8 , I8x8_DC_AB_8 , I8x8_DC_AB_8, I8x8_DC_AB_8},
		{I8x8_VL_8 , I8x8_VL_8   , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_VL_C_8 , I8x8_VL_C_8 , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_VL_D_8 , I8x8_VL_D_8 , I8x8_DC_AB_8, I8x8_DC_AB_8, I8x8_VL_CD_8 , I8x8_VL_CD_8 , I8x8_DC_AB_8, I8x8_DC_AB_8},
		{I8x8_HU_8 , I8x8_DC_AB_8, I8x8_HU_8   , I8x8_DC_AB_8, I8x8_HU_8   , I8x8_DC_AB_8, I8x8_HU_8   , I8x8_DC_AB_8, I8x8_HU_D_8 , I8x8_DC_AB_8, I8x8_HU_D_8 , I8x8_DC_AB_8, I8x8_HU_D_8  , I8x8_DC_AB_8 , I8x8_HU_D_8 , I8x8_DC_AB_8},
	};
	
	if (mb->f.CodedBlockPatternChromaDC | (mb->bits[0] & 0xac)) {
		CACALL(parse_mb_qp_delta);
		log_mb(ctx, "    coeffLevels:\n");
	}
	#if CABAC
		else
			ctx->mb_qp_delta_nz = 0;
	#endif
	
	// next few blocks will share many parameters, so we cache them
	for (int iYCbCr = 0; iYCbCr < 3; iYCbCr++) {
		if (!mb->f.transform_size_8x8_flag) {
			#if CABAC
				ctx->ctxIdxOffsets_l = ctxIdxOffsets_4x4[iYCbCr][0];
				ctx->coeff_abs_inc_l = (i8x8){6, 7, 8, 9, 9};
				ctx->sig_inc_v[0] = ctx->last_inc_v[0] = sig_inc_4x4;
			#endif
			ctx->scan_v[0] = scan_4x4[0];
			
			// Decoding directly follows parsing to avoid duplicate loops.
			for (int i4x4 = 0; i4x4 < 16; i4x4++) {
				size_t stride = ctx->t.stride[iYCbCr];
				uint8_t *samples = ctx->samples_mb[iYCbCr] + y444[i4x4] * stride + x444[i4x4];
				if (!mb->mbIsInterFlag)
					decode_intra4x4(Intra4x4Modes[mb->Intra4x4PredMode[i4x4]][ctx->unavail4x4[i4x4]], samples, stride, ctx->t.samples_clip_v[iYCbCr]);
				if (mb->bits[0] & 1 << bit8x8[i4x4 >> 2]) {
					int nA = *((int8_t *)mb->nC + iYCbCr * 16 + ctx->A4x4_int8[i4x4]);
					int nB = *((int8_t *)mb->nC + iYCbCr * 16 + ctx->B4x4_int8[i4x4]);
					// DC blocks are marginal here (about 16%) so we do not handle them separately
					#if !CABAC
						if (parse_residual_block_4x4_cavlc(ctx, iYCbCr * 16 + i4x4, nA, nB, 0))
							add_idct4x4(ctx, iYCbCr, -1, samples); // FIXME 4:4:4
					#else
						if (get_ae(ctx, ctx->ctxIdxOffsets[0] + ctx->nC_inc[iYCbCr][i4x4] + nA + nB * 2)) {
							mb->nC[iYCbCr * 16 + i4x4] = 1;
							parse_residual_coeffs_cabac(ctx, 0, 15);
							add_idct4x4(ctx, iYCbCr, -1, samples); // FIXME 4:4:4
						}
					#endif
				}
			}
		} else {
			#if CABAC
				ctx->ctxIdxOffsets_l = ctxIdxOffsets_8x8[iYCbCr][0];
				ctx->coeff_abs_inc_l = (i8x8){6, 7, 8, 9, 9};
				ctx->sig_inc_v[0] = sig_inc_8x8[0][0];
				ctx->last_inc_v[0] = last_inc_8x8[0];
				ctx->scan_v[0] = scan_8x8_cabac[0][0];
			#endif
			
			for (int i8x8 = 0; i8x8 < 4; i8x8++) {
				size_t stride = ctx->t.stride[iYCbCr];
				uint8_t *samples = ctx->samples_mb[iYCbCr] + y444[i8x8 * 4] * stride + x444[i8x8 * 4];
				if (!mb->mbIsInterFlag)
					decode_intra8x8(Intra8x8Modes[mb->Intra4x4PredMode[i8x8 * 4 + 1]][ctx->unavail4x4[i8x8 * 5]], samples, stride, ctx->t.samples_clip_v[iYCbCr]);
				if (mb->bits[0] & 1 << bit8x8[i8x8]) {
					#if !CABAC
						for (int i4x4 = 0; i4x4 < 4; i4x4++) {
							ctx->scan_v[0] = scan_8x8_cavlc[0][i4x4];
							int nA = *((int8_t *)mb->nC + iYCbCr * 16 + ctx->A4x4_int8[i8x8 * 4 + i4x4]);
							int nB = *((int8_t *)mb->nC + iYCbCr * 16 + ctx->B4x4_int8[i8x8 * 4 + i4x4]);
							parse_residual_block_4x4_cavlc(ctx, iYCbCr * 16 + i8x8 * 4 + i4x4, nA, nB, 0);
						}
						add_idct8x8(ctx, iYCbCr, samples);
					#else
						if (ctx->t.ChromaArrayType < 3 || get_ae(ctx, ctx->ctxIdxOffsets[0] + (mb->bits[1] >> inc8x8[iYCbCr * 4 + i8x8] & 3))) {
							mb->bits[1] |= 1 << bit8x8[iYCbCr * 4 + i8x8];
							mb->nC_s[iYCbCr * 4 + i8x8] = 0x01010101;
							parse_residual_coeffs_cabac(ctx, 0, 63);
							add_idct8x8(ctx, iYCbCr, samples);
						}
					#endif
				}
			}
		}
		
		// nice optimisation for 4:4:4 modes
		if (ctx->t.ChromaArrayType <3)
			CAJUMP(parse_chroma_residual);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq 0x680(%rdi), %rax
movsbl 0x26(%rax), %ecx
movl $0xac, %edx
andl 0x8(%rax), %edx
orl %ecx, %edx
je 0x1411f
movq %rbx, %rdi
callq 0x144a8
jmp 0x14126
movb $0x0, 0x651(%rbx)
leaq 0x6d0(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x700(%rbx), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movabsq $0x909080706, %rax      # imm = 0x909080706
vmovq %rax, %xmm0
vmovdqa %xmm0, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0x14499
movq 0x680(%rbx), %rax
cmpb $0x0, 0x24(%rax)
je 0x14310
movq %r12, %rax
shlq $0x4, %rax
leaq 0x1cf9f(%rip), %rcx     # 0x31130
vmovsd (%rax,%rcx), %xmm0
vunpcklpd 0x30(%rsp), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0]
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x19734(%rip), %xmm0    # 0x2d8e0
vmovaps %xmm0, 0x1a20(%rbx)
vmovaps 0x19734(%rip), %xmm0    # 0x2d8f0
vmovaps %xmm0, 0x1a60(%rbx)
vmovdqa 0x19734(%rip), %xmm0    # 0x2d900
vmovdqa %xmm0, 0x1aa0(%rbx)
leaq (,%r12,4), %rax
movq %rax, 0x28(%rsp)
movq 0x20(%rsp), %r14
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq $0x4, %rbp
je 0x14464
movzwl 0x34(%rbx,%r12,2), %edx
leaq 0x1974e(%rip), %rax     # 0x2d950
movsbq (%r15,%rax), %rax
imulq %rdx, %rax
addq 0x668(%rbx,%r12,8), %rax
leaq 0x19726(%rip), %rcx     # 0x2d940
movsbq (%r15,%rcx), %r13
addq %rax, %r13
movq 0x680(%rbx), %rax
cmpb $0x0, 0x2(%rax)
jne 0x1425a
movsbq 0x31(%rax,%rbp,4), %rax
movsbq (%r14), %rcx
shlq $0x4, %rax
leaq 0x1ce2c(%rip), %rsi     # 0x31070
addq %rsi, %rax
movsbl (%rcx,%rax), %edi
movq %r13, %rsi
callq 0x10401
movq 0x680(%rbx), %rax
movl 0x8(%rax), %ecx
leaq 0x1c1bc(%rip), %rdx     # 0x30420
movzbl (%rbp,%rdx), %edx
btl %edx, %ecx
jae 0x14300
cmpb $0x2, 0x2a(%rbx)
jg 0x14282
movq 0x8(%rsp), %rcx
addq %rbp, %rcx
jmp 0x142c1
movswl 0x1a10(%rbx), %ecx
movq 0x8(%rsp), %rdx
addq %rbp, %rdx
leaq 0x1cd38(%rip), %rsi     # 0x30fd0
movb (%rsi,%rdx), %dl
shrxl %edx, 0xc(%rax), %esi
andl $0x3, %esi
addl %ecx, %esi
movq %rbx, %rdi
callq 0x13a0c
testl %eax, %eax
je 0x14300
movq %rbp, %rcx
orq 0x28(%rsp), %rcx
movq 0x680(%rbx), %rax
leaq 0x1c158(%rip), %rdx     # 0x30420
movb (%rcx,%rdx), %dl
pushq $0x1
popq %rsi
shlxl %edx, %esi, %edx
orl %edx, 0xc(%rax)
movq 0x680(%rbx), %rax
movl $0x1010101, 0x40(%rax,%rcx,4) # imm = 0x1010101
movq %rbx, %rdi
xorl %esi, %esi
pushq $0x3f
popq %rdx
callq 0x1454a
movq %rbx, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0x10ca5
incq %rbp
addq $0x4, %r15
addq $0x5, %r14
jmp 0x141eb
movq %r12, %r14
shlq $0x4, %r14
leaq 0x1cde2(%rip), %rax     # 0x31100
vmovsd (%r14,%rax), %xmm0
vunpcklpd 0x30(%rsp), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0]
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x19596(%rip), %xmm0    # 0x2d8d0
vmovaps %xmm0, 0x1a60(%rbx)
vmovaps %xmm0, 0x1a20(%rbx)
vmovdqa 0x191ae(%rip), %xmm0    # 0x2d500
vmovdqa %xmm0, 0x1aa0(%rbx)
xorl %r15d, %r15d
cmpq $0x10, %r15
je 0x14464
movzwl 0x34(%rbx,%r12,2), %edx
leaq 0x195dc(%rip), %rax     # 0x2d950
movsbq (%r15,%rax), %rax
imulq %rdx, %rax
addq 0x668(%rbx,%r12,8), %rax
leaq 0x195b4(%rip), %rcx     # 0x2d940
movsbq (%r15,%rcx), %r13
addq %rax, %r13
movq 0x680(%rbx), %rax
cmpb $0x0, 0x2(%rax)
jne 0x143d1
movsbq 0x30(%rax,%r15), %rax
movsbq 0x6d0(%rbx,%r15), %rcx
shlq $0x4, %rax
leaq 0x1cc25(%rip), %rsi     # 0x30fe0
addq %rsi, %rax
movsbl (%rcx,%rax), %edi
movq %r13, %rsi
callq 0xfeb1
movq 0x680(%rbx), %rax
movl 0x8(%rax), %ecx
movl %r15d, %edx
shrl $0x2, %edx
leaq 0x1c03f(%rip), %rsi     # 0x30420
movzbl (%rdx,%rsi), %edx
btl %edx, %ecx
jae 0x1445c
addq %r14, %rax
movswq 0xb40(%rbx,%r15,2), %rcx
movsbl 0x40(%rcx,%rax), %ecx
movslq 0xb80(%rbx,%r15,4), %rdx
movsbl 0x40(%rdx,%rax), %eax
movswl 0x1a10(%rbx), %edx
addl %ecx, %edx
movq 0x18(%rsp), %rcx
movsbl (%rcx,%r15), %ecx
leal (%rdx,%rax,2), %esi
addl %ecx, %esi
movq %rbx, %rdi
callq 0x13a0c
testl %eax, %eax
je 0x1445c
movq 0x680(%rbx), %rax
addq 0x10(%rsp), %rax
movb $0x1, 0x40(%r15,%rax)
movq %rbx, %rdi
xorl %esi, %esi
pushq $0xf
popq %rdx
callq 0x1454a
movq %rbx, %rdi
movl %r12d, %esi
pushq $-0x1
popq %rdx
movq %r13, %rcx
callq 0x101ea
incq %r15
jmp 0x1435d
incq %r12
addq $0x4, 0x8(%rsp)
addq $0x10, 0x10(%rsp)
addq $0x10, 0x18(%rsp)
cmpb $0x2, 0x2a(%rbx)
jg 0x14168
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1475b
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq