// File: /workspace/github_c_makefile_star2_O3/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 0x1738a
movq %rbx, %rdi
callq 0x17719
jmp 0x17391
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 %r14d, %r14d
movq 0x680(%rbx), %rax
cmpb $0x0, 0x24(%rax)
je 0x1757a
movq %r14, %rax
shlq $0x4, %rax
leaq 0x1fe4e(%rip), %rcx     # 0x37240
vmovsd (%rax,%rcx), %xmm0
vunpcklpd 0x30(%rsp), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0]
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x1c5e3(%rip), %xmm0    # 0x339f0
vmovaps %xmm0, 0x1a20(%rbx)
vmovaps 0x1c5e3(%rip), %xmm0    # 0x33a00
vmovaps %xmm0, 0x1a60(%rbx)
vmovdqa 0x1c5e3(%rip), %xmm0    # 0x33a10
vmovdqa %xmm0, 0x1aa0(%rbx)
leaq (,%r14,4), %rax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
movq 0x20(%rsp), %r12
xorl %r13d, %r13d
movzwl 0x34(%rbx,%r14,2), %edx
leaq 0x1c607(%rip), %rax     # 0x33a60
movsbq (%rbp,%rax), %rax
imulq %rdx, %rax
addq 0x668(%rbx,%r14,8), %rax
leaq 0x1c5de(%rip), %rcx     # 0x33a50
movsbq (%rbp,%rcx), %r15
addq %rax, %r15
movq 0x680(%rbx), %rax
cmpb $0x0, 0x2(%rax)
jne 0x174b4
movsbq 0x31(%rax,%r13,4), %rax
movsbq (%r12), %rcx
shlq $0x4, %rax
leaq 0x1fce2(%rip), %rsi     # 0x37180
addq %rsi, %rax
movsbl (%rcx,%rax), %edi
movq %r15, %rsi
callq 0x134a3
movq 0x680(%rbx), %rax
movl 0x8(%rax), %ecx
leaq 0x1f072(%rip), %rdx     # 0x36530
movzbl (%r13,%rdx), %edx
btl %edx, %ecx
jae 0x17560
cmpb $0x2, 0x2a(%rbx)
jg 0x174dd
movq 0x8(%rsp), %rcx
addq %r13, %rcx
jmp 0x1751d
movswl 0x1a10(%rbx), %ecx
movq 0x8(%rsp), %rdx
addq %r13, %rdx
leaq 0x1fbed(%rip), %rsi     # 0x370e0
movb (%rsi,%rdx), %dl
shrxl %edx, 0xc(%rax), %esi
andl $0x3, %esi
addl %ecx, %esi
movq %rbx, %rdi
callq 0x16bee
testl %eax, %eax
je 0x17560
movq 0x28(%rsp), %rax
leaq (%rax,%r13), %rcx
movq 0x680(%rbx), %rax
leaq 0x1f00c(%rip), %rdx     # 0x36530
movb (%rcx,%rdx), %dl
movl $0x1, %esi
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
movl $0x3f, %edx
callq 0x177dc
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x13d47
incq %r13
addq $0x5, %r12
addq $0x4, %rbp
cmpq $0x4, %r13
jne 0x1744c
jmp 0x176cf
movq %r14, %r12
shlq $0x4, %r12
leaq 0x1fc88(%rip), %rax     # 0x37210
vmovsd (%r12,%rax), %xmm0
vunpcklpd 0x30(%rsp), %xmm0, %xmm0 # xmm0 = xmm0[0],mem[0]
vmovaps %xmm0, 0x1a10(%rbx)
vmovaps 0x1c43c(%rip), %xmm0    # 0x339e0
vmovaps %xmm0, 0x1a60(%rbx)
vmovaps %xmm0, 0x1a20(%rbx)
vmovdqa 0x1c084(%rip), %xmm0    # 0x33640
vmovdqa %xmm0, 0x1aa0(%rbx)
xorl %r13d, %r13d
movzwl 0x34(%rbx,%r14,2), %edx
leaq 0x1c48c(%rip), %rax     # 0x33a60
movsbq (%r13,%rax), %rax
imulq %rdx, %rax
addq 0x668(%rbx,%r14,8), %rax
leaq 0x1c463(%rip), %rcx     # 0x33a50
movsbq (%r13,%rcx), %r15
addq %rax, %r15
movq 0x680(%rbx), %rax
cmpb $0x0, 0x2(%rax)
jne 0x17633
movsbq 0x30(%rax,%r13), %rax
movsbq 0x6d0(%rbx,%r13), %rcx
shlq $0x4, %rax
leaq 0x1fad3(%rip), %rsi     # 0x370f0
addq %rsi, %rax
movsbl (%rcx,%rax), %edi
movq %r15, %rsi
callq 0x12f43
movq 0x680(%rbx), %rax
movl 0x8(%rax), %ecx
movl %r13d, %edx
shrl $0x2, %edx
leaq 0x1eeed(%rip), %rsi     # 0x36530
movzbl (%rdx,%rsi), %edx
btl %edx, %ecx
jae 0x176c2
addq %r12, %rax
movswq 0xb40(%rbx,%r13,2), %rcx
movsbl 0x40(%rcx,%rax), %ecx
movslq 0xb80(%rbx,%r13,4), %rdx
movsbl 0x40(%rdx,%rax), %eax
movswl 0x1a10(%rbx), %edx
addl %ecx, %edx
movq 0x18(%rsp), %rcx
movsbl (%rcx,%r13), %ecx
leal (%rdx,%rax,2), %esi
addl %ecx, %esi
movq %rbx, %rdi
callq 0x16bee
testl %eax, %eax
je 0x176c2
movq 0x680(%rbx), %rax
addq 0x10(%rsp), %rax
movb $0x1, 0x40(%r13,%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0xf, %edx
callq 0x177dc
movq %rbx, %rdi
movl %r14d, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r15, %rcx
callq 0x13280
incq %r13
cmpq $0x10, %r13
jne 0x175c7
cmpb $0x2, 0x2a(%rbx)
jle 0x17703
incq %r14
addq $0x4, 0x8(%rsp)
addq $0x10, 0x18(%rsp)
addq $0x10, 0x10(%rsp)
cmpq $0x3, %r14
jne 0x173d3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x17df4