// File: /workspace/github_c_makefile_star2_O0/tvlabs[P]edge264/./edge264_slice.c
// Function: parse_mvd_pair_cabac
static i16x8 CAFUNC(parse_mvd_pair, const uint8_t *absMvd_lx, int i4x4) {
	#if !CABAC
		int x = get_se32(&ctx->t._gb, -32768, 32767);
		int y = get_se32(&ctx->t._gb, -32768, 32767);
		log_mb(ctx, "[%d,%d],", x, y);
		return (i16x8){x, y};
	#else
		i16x8 res;
		for (int ctxBase = 40, i = 0;;) {
			int sum = absMvd_lx[ctx->absMvd_A[i4x4] + i] + absMvd_lx[ctx->absMvd_B[i4x4] + i];
			int ctxIdx = ctxBase + (sum >= 3) + (sum > 32);
			int mvd = 0;
			ctxBase += 3;
			while (mvd < 9 && get_ae(ctx, ctxIdx))
				ctxIdx = ctxBase + min(mvd++, 3);
			if (mvd >= 9) {
				// we need at least 35 (or 21) bits in codIOffset to get 26 (or 12) bypass bits
				int zeros = clz(ctx->t._gb.codIRange);
				if (zeros > (SIZE_BIT == 64 ? 64 - 35 : 32 - 21)) {
					ctx->t._gb.codIOffset = shld(get_bytes(&ctx->t._gb, zeros >> 3), ctx->t._gb.codIOffset, zeros & -8);
					ctx->t._gb.codIRange <<= zeros & -8;
					zeros &= 7;
				}
				// for 64-bit we could shift codIOffset down to 37 bits to help iterative hardware dividers, but that would make the code harder to maintain
				ctx->t._gb.codIRange >>= SIZE_BIT - 9 - zeros;
				size_t quo = ctx->t._gb.codIOffset / ctx->t._gb.codIRange; // requested bits are in lsb and zeros+9 empty bits above
				size_t rem = ctx->t._gb.codIOffset % ctx->t._gb.codIRange;
				int k = 3 + clz(~quo << (zeros + 9) | (size_t)1 << (SIZE_BIT - 12));
				int unused = SIZE_BIT - 9 - zeros - k * 2 + 1;
				#if SIZE_BIT == 32
					if (__builtin_expect(unused < 0, 0)) { // FIXME needs testing
						// refill codIOffset with 16 bits then make a new division
						ctx->t._gb.codIOffset = shld(get_bytes(&ctx->t._gb, 2), rem, 16);
						quo = shld((ctx->t._gb.codIOffset / ctx->t._gb.codIRange) << (SIZE_BIT - 16), quo, 16);
						rem = ctx->t._gb.codIOffset % ctx->t._gb.codIRange;
						unused += 16;
					}
				#endif
				mvd = 1 + (1 << k | (quo >> unused >> 1 & (((size_t)1 << k) - 1)));
				mvd = (quo & (size_t)1 << unused) ? -mvd : mvd;
				ctx->t._gb.codIOffset = (quo & (((size_t)1 << unused) - 1)) * ctx->t._gb.codIRange + rem;
				ctx->t._gb.codIRange <<= unused;
			} else if (mvd > 0) {
				mvd = get_bypass(ctx) ? -mvd : mvd;
			}
			
			if (++i == 2) {
				res[1] = mvd;
				log_mb(ctx, "    \"%lu\": [%d,%d]\n", absMvd_lx - mb->absMvd + i4x4, res[0], mvd);
				return res;
			}
			ctxBase = 47;
			res = (i16x8){mvd};
		}
	#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movl %edx, -0x34(%rbp)
movl $0x28, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movswl 0xc40(%rcx,%rdx,2), %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rdx
movslq -0x34(%rbp), %rsi
movl 0xc80(%rdx,%rsi,4), %edx
addl -0x58(%rbp), %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x54(%rbp), %eax
cmpl $0x3, -0x5c(%rbp)
setge %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
cmpl $0x20, -0x5c(%rbp)
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movl %eax, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x54(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x54(%rbp)
xorl %eax, %eax
cmpl $0x9, -0x64(%rbp)
movb %al, -0x91(%rbp)
jge 0xafd2e
movq -0x28(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0xae5c0
cmpl $0x0, %eax
setne %al
movb %al, -0x91(%rbp)
movb -0x91(%rbp), %al
testb $0x1, %al
jne 0xafd3a
jmp 0xafd87
movl -0x54(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x64(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x64(%rbp)
movl %eax, -0x18(%rbp)
movl $0x3, -0x1c(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xafd6b
movl -0x18(%rbp), %eax
movl %eax, -0x9c(%rbp)
jmp 0xafd74
movl -0x1c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl -0x98(%rbp), %eax
movl -0x9c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x60(%rbp)
jmp 0xafd08
cmpl $0x9, -0x64(%rbp)
jl 0xaff70
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
lzcntq %rax, %rax
movl %eax, -0x68(%rbp)
cmpl $0x1d, -0x68(%rbp)
jle 0xafe14
movq -0x28(%rbp), %rdi
movl -0x68(%rbp), %esi
sarl $0x3, %esi
callq 0x7d7f0
movq %rax, %rdx
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rcx
movl -0x68(%rbp), %eax
andl $-0x8, %eax
movq %rdx, -0x8(%rbp)
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
movl -0x14(%rbp), %ecx
shldq %cl, %rdx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x68(%rbp), %ecx
andl $-0x8, %ecx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
movl -0x68(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x68(%rbp)
movl $0x37, %ecx
subl -0x68(%rbp), %ecx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shrq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
xorl %edx, %edx
divq 0x10(%rcx)
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
xorl %edx, %edx
divq 0x10(%rcx)
movq %rdx, -0x78(%rbp)
movq -0x70(%rbp), %rax
xorq $-0x1, %rax
movl -0x68(%rbp), %ecx
addl $0x9, %ecx
movl %ecx, %ecx
shlq %cl, %rax
movabsq $0x10000000000000, %rcx # imm = 0x10000000000000
orq %rcx, %rax
lzcntq %rax, %rax
addl $0x3, %eax
movl %eax, -0x7c(%rbp)
movl $0x37, %eax
subl -0x68(%rbp), %eax
movl -0x7c(%rbp), %ecx
shll %ecx
subl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movl -0x7c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
cltq
movq -0x70(%rbp), %rdx
movl -0x80(%rbp), %ecx
shrq %cl, %rdx
movq %rdx, %rcx
shrq %rcx
movq %rcx, -0xa8(%rbp)
movl -0x7c(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq -0xa8(%rbp), %rcx
subq $0x1, %rdx
andq %rdx, %rcx
orq %rcx, %rax
addq $0x1, %rax
movl %eax, -0x64(%rbp)
movq -0x70(%rbp), %rax
movl -0x80(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0xaff0a
xorl %eax, %eax
subl -0x64(%rbp), %eax
movl %eax, -0xac(%rbp)
jmp 0xaff13
movl -0x64(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x80(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq -0xb8(%rbp), %rcx
subq $0x1, %rax
andq %rax, %rcx
movq -0x28(%rbp), %rax
imulq 0x10(%rax), %rcx
addq -0x78(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x80(%rbp), %ecx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
movq %rcx, 0x10(%rax)
jmp 0xaffa5
cmpl $0x0, -0x64(%rbp)
jle 0xaffa3
movq -0x28(%rbp), %rdi
callq 0xb01b0
cmpl $0x0, %eax
je 0xaff91
xorl %eax, %eax
subl -0x64(%rbp), %eax
movl %eax, -0xbc(%rbp)
jmp 0xaff9a
movl -0x64(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0xaffa5
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x2, %eax
jne 0xb004d
vmovdqa -0x50(%rbp), %xmm0
movl -0x64(%rbp), %eax
vpinsrw $0x1, %eax, %xmm0, %xmm0
vmovdqa %xmm0, -0x50(%rbp)
movq -0x28(%rbp), %rax
movswq 0x1cd0(%rax), %rax
cmpq $0x1000, %rax           # imm = 0x1000
jae 0xb003f
movq -0x28(%rbp), %rcx
movswq 0x1cd0(%rcx), %rax
leaq 0x1cd2(%rcx,%rax), %rdi
movl $0x1000, %esi           # imm = 0x1000
subq %rax, %rsi
movq -0x30(%rbp), %rax
movq 0x680(%rcx), %rcx
subq %rcx, %rax
movslq -0x34(%rbp), %rcx
leaq -0x70(%rax,%rcx), %rcx
movl -0x50(%rbp), %eax
movswl %ax, %r8d
movl -0x64(%rbp), %r9d
leaq 0x20b7e(%rip), %rdx     # 0xd0ba0
movb $0x0, %al
callq 0x7070
movl %eax, %edx
movq -0x28(%rbp), %rax
movswl 0x1cd0(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x1cd0(%rax)
vmovdqa -0x50(%rbp), %xmm0
addq $0xc0, %rsp
popq %rbp
retq
movl $0x2f, -0x54(%rbp)
movzwl -0x64(%rbp), %eax
vmovd %eax, %xmm0
vmovdqa %xmm0, -0x90(%rbp)
vmovdqa -0x90(%rbp), %xmm0
vmovdqa %xmm0, -0x50(%rbp)
jmp 0xafc94
nopw %cs:(%rax,%rax)