// File: /workspace/github_c_makefile_star2_O2/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_video_process_macroblock
void plm_video_process_macroblock(
	plm_video_t *self, uint8_t *s, uint8_t *d,
	int motion_h, int motion_v, int block_size, int interpolate
) {
	int dw = self->mb_width * block_size;

	int hp = motion_h >> 1;
	int vp = motion_v >> 1;
	int odd_h = (motion_h & 1) == 1;
	int odd_v = (motion_v & 1) == 1;

	unsigned int si = ((self->mb_row * block_size) + vp) * dw + (self->mb_col * block_size) + hp;
	unsigned int di = (self->mb_row * dw + self->mb_col) * block_size;
	
	unsigned int max_address = (dw * (self->mb_height * block_size - block_size + 1) - block_size);
	if (si > max_address || di > max_address) {
		return; // corrupt video
	}

	#define PLM_MB_CASE(INTERPOLATE, ODD_H, ODD_V, OP) \
		case ((INTERPOLATE << 2) | (ODD_H << 1) | (ODD_V)): \
			PLM_BLOCK_SET(d, di, dw, si, dw, block_size, OP); \
			break

	switch ((interpolate << 2) | (odd_h << 1) | (odd_v)) {
		PLM_MB_CASE(0, 0, 0, (s[si]));
		PLM_MB_CASE(0, 0, 1, (s[si] + s[si + dw] + 1) >> 1);
		PLM_MB_CASE(0, 1, 0, (s[si] + s[si + 1] + 1) >> 1);
		PLM_MB_CASE(0, 1, 1, (s[si] + s[si + 1] + s[si + dw] + s[si + dw + 1] + 2) >> 2);

		PLM_MB_CASE(1, 0, 0, (d[di] + (s[si]) + 1) >> 1);
		PLM_MB_CASE(1, 0, 1, (d[di] + ((s[si] + s[si + dw] + 1) >> 1) + 1) >> 1);
		PLM_MB_CASE(1, 1, 0, (d[di] + ((s[si] + s[si + 1] + 1) >> 1) + 1) >> 1);
		PLM_MB_CASE(1, 1, 1, (d[di] + ((s[si] + s[si + 1] + s[si + dw] + s[si + dw + 1] + 2) >> 2) + 1) >> 1);
	}

	#undef PLM_MB_CASE
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x24(%rdi), %eax
imull %r9d, %eax
movl %ecx, %ebp
sarl %ebp
movl %r8d, %ebx
sarl %ebx
movl 0x28(%rdi), %r11d
movl 0x80(%rdi), %r10d
movl %r10d, %r14d
imull %r9d, %r14d
addl %ebx, %r14d
imull %eax, %r14d
movl 0x84(%rdi), %ebx
movl %ebx, %edi
imull %r9d, %edi
addl %ebp, %edi
addl %r14d, %edi
decl %r11d
imull %r9d, %r11d
incl %r11d
imull %eax, %r11d
subl %r9d, %r11d
cmpl %r11d, %edi
ja 0x52b6
imull %eax, %r10d
addl %ebx, %r10d
imull %r9d, %r10d
cmpl %r11d, %r10d
ja 0x52b6
movl 0x38(%rsp), %r11d
andl $0x1, %r8d
andl $0x1, %ecx
addl %ecx, %ecx
leal (%rcx,%r11,4), %ecx
orl %r8d, %ecx
cmpl $0x7, %ecx
ja 0x52b6
leaq 0x32f6(%rip), %r8       # 0x8220
movslq (%r8,%rcx,4), %rcx
addq %r8, %rcx
jmpq *%rcx
subl %r9d, %eax
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %r8d
cmovgl %r9d, %r8d
negl %r9d
cmpl %r8d, %ecx
je 0x52b6
xorl %r11d, %r11d
movl %r10d, %ebx
movl %edi, %ebp
cmpl %r11d, %r9d
je 0x4f75
movl %ebp, %r14d
movb (%rsi,%r14), %r14b
movl %ebx, %r15d
movb %r14b, (%rdx,%r15)
incl %ebp
incl %ebx
decl %r11d
jmp 0x4f59
addl %eax, %edi
subl %r11d, %edi
addl %eax, %r10d
subl %r11d, %r10d
incl %ecx
jmp 0x4f48
subl %r9d, %eax
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %r8d
cmovgl %r9d, %r8d
negl %r9d
cmpl %r8d, %ecx
je 0x52b6
xorl %r11d, %r11d
movl %r10d, %ebx
movl %edi, %ebp
cmpl %r11d, %r9d
je 0x4fd5
movl %ebx, %r14d
movzbl (%rdx,%r14), %r15d
movl %ebp, %r12d
movzbl (%rsi,%r12), %r12d
addl %r12d, %r15d
incl %r15d
shrl %r15d
movb %r15b, (%rdx,%r14)
incl %ebp
incl %ebx
decl %r11d
jmp 0x4faa
addl %eax, %edi
subl %r11d, %edi
addl %eax, %r10d
subl %r11d, %r10d
incl %ecx
jmp 0x4f99
subl %r9d, %eax
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %r8d
cmovgl %r9d, %r8d
negl %r9d
cmpl %r8d, %ecx
je 0x52b6
xorl %r11d, %r11d
movl %r10d, %ebx
movl %edi, %r14d
cmpl %r11d, %r9d
je 0x5036
movl %r14d, %r15d
movzbl (%rsi,%r15), %r15d
incl %r14d
movzbl (%rsi,%r14), %r12d
leal (%r15,%r12), %ebp
incl %ebp
shrl %ebp
movl %ebx, %r15d
movb %bpl, (%rdx,%r15)
incl %ebx
decl %r11d
jmp 0x500b
addl %eax, %edi
subl %r11d, %edi
addl %eax, %r10d
subl %r11d, %r10d
incl %ecx
jmp 0x4ff9
movl %eax, %ecx
subl %r9d, %ecx
xorl %r8d, %r8d
testl %r9d, %r9d
movl $0x0, %r11d
cmovgl %r9d, %r11d
cmpl %r11d, %r8d
je 0x52b6
leal (%rax,%rdi), %r14d
xorl %ebx, %ebx
cmpl %ebx, %r9d
je 0x50bb
leal (%r10,%rbx), %ebp
leal (%rdi,%rbx), %r15d
movl %r15d, %r15d
movzbl (%rsi,%r15), %r15d
leal (%rbx,%rdi), %r12d
incl %r12d
movzbl (%rsi,%r12), %r12d
leal (%r14,%rbx), %r13d
movzbl (%rsi,%r13), %r13d
addl %r12d, %r13d
addl %r15d, %r13d
leal (%r14,%rbx), %r15d
incl %r15d
movzbl (%rsi,%r15), %r15d
addl %r13d, %r15d
addl $0x2, %r15d
shrl $0x2, %r15d
movl %ebp, %r12d
movb %r15b, (%rdx,%r12)
incl %ebx
jmp 0x5069
addl %ecx, %edi
addl %ebx, %edi
addl %ecx, %r10d
addl %ebx, %r10d
incl %r8d
jmp 0x505a
movl %eax, %ecx
subl %r9d, %ecx
xorl %r8d, %r8d
testl %r9d, %r9d
movl $0x0, %r11d
cmovgl %r9d, %r11d
movl %r11d, -0x4(%rsp)
cmpl -0x4(%rsp), %r8d
je 0x52b6
leal (%rax,%rdi), %r14d
xorl %ebx, %ebx
cmpl %ebx, %r9d
je 0x5153
leal (%r10,%rbx), %ebp
leal (%rdi,%rbx), %r12d
movl %ebp, %r15d
movzbl (%rdx,%r15), %r13d
movl %r12d, %r12d
movzbl (%rsi,%r12), %ebp
leal 0x1(%rbx,%rdi), %r12d
movzbl (%rsi,%r12), %r12d
leal (%r14,%rbx), %r11d
movzbl (%rsi,%r11), %r11d
addl %r12d, %r11d
addl %ebp, %r11d
leal (%r14,%rbx), %r12d
incl %r12d
movzbl (%rsi,%r12), %r12d
addl %r12d, %r11d
addl $0x2, %r11d
shrl $0x2, %r11d
addl %r13d, %r11d
incl %r11d
shrl %r11d
movb %r11b, (%rdx,%r15)
incl %ebx
jmp 0x50f5
addl %ecx, %edi
addl %ebx, %edi
addl %ecx, %r10d
addl %ebx, %r10d
incl %r8d
jmp 0x50e4
movl %eax, %ecx
subl %r9d, %ecx
xorl %r8d, %r8d
testl %r9d, %r9d
movl $0x0, %r11d
cmovgl %r9d, %r11d
negl %r9d
cmpl %r11d, %r8d
je 0x52b6
xorl %ebx, %ebx
movl %r10d, %ebp
movl %edi, %r14d
cmpl %ebx, %r9d
je 0x51ba
movl %r14d, %r15d
movzbl (%rsi,%r15), %r15d
leal (%rax,%r14), %r12d
movzbl (%rsi,%r12), %r12d
addl %r12d, %r15d
incl %r15d
shrl %r15d
movl %ebp, %r12d
movb %r15b, (%rdx,%r12)
incl %r14d
incl %ebp
decl %ebx
jmp 0x518b
addl %ecx, %edi
subl %ebx, %edi
addl %ecx, %r10d
subl %ebx, %r10d
incl %r8d
jmp 0x517a
movl %eax, %ecx
subl %r9d, %ecx
xorl %r8d, %r8d
testl %r9d, %r9d
movl $0x0, %r11d
cmovgl %r9d, %r11d
movl %r11d, -0x4(%rsp)
negl %r9d
cmpl -0x4(%rsp), %r8d
je 0x52b6
xorl %ebx, %ebx
movl %r10d, %ebp
movl %edi, %r14d
cmpl %ebx, %r9d
je 0x523a
movl %ebp, %r15d
movzbl (%rdx,%r15), %r12d
movl %r14d, %r13d
movzbl (%rsi,%r13), %r13d
leal (%rax,%r14), %r11d
movzbl (%rsi,%r11), %r11d
addl %r13d, %r11d
incl %r11d
shrl %r11d
movzbl %r11b, %r11d
addl %r12d, %r11d
incl %r11d
shrl %r11d
movb %r11b, (%rdx,%r15)
incl %r14d
incl %ebp
decl %ebx
jmp 0x51f9
addl %ecx, %edi
subl %ebx, %edi
addl %ecx, %r10d
subl %ebx, %r10d
incl %r8d
jmp 0x51e6
subl %r9d, %eax
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %r8d
cmovgl %r9d, %r8d
negl %r9d
cmpl %r8d, %ecx
je 0x52b6
xorl %r11d, %r11d
movl %r10d, %ebx
movl %edi, %r14d
cmpl %r11d, %r9d
je 0x52a7
movl %ebx, %r15d
movzbl (%rdx,%r15), %r12d
movl %r14d, %r13d
movzbl (%rsi,%r13), %r13d
incl %r14d
movzbl (%rsi,%r14), %ebp
addl %r13d, %ebp
incl %ebp
shrl %ebp
movzbl %bpl, %r13d
leal (%r12,%r13), %ebp
incl %ebp
shrl %ebp
movb %bpl, (%rdx,%r15)
incl %ebx
decl %r11d
jmp 0x526c
addl %eax, %edi
subl %r11d, %edi
addl %eax, %r10d
subl %r11d, %r10d
incl %ecx
jmp 0x525e
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq