// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_video_decode_macroblock
void plm_video_decode_macroblock(plm_video_t *self) {
	// Decode increment
	int increment = 0;
	int t = plm_buffer_read_vlc(self->buffer, PLM_VIDEO_MACROBLOCK_ADDRESS_INCREMENT);

	while (t == 34) {
		// macroblock_stuffing
		t = plm_buffer_read_vlc(self->buffer, PLM_VIDEO_MACROBLOCK_ADDRESS_INCREMENT);
	}
	while (t == 35) {
		// macroblock_escape
		increment += 33;
		t = plm_buffer_read_vlc(self->buffer, PLM_VIDEO_MACROBLOCK_ADDRESS_INCREMENT);
	}
	increment += t;

	// Process any skipped macroblocks
	if (self->slice_begin) {
		// The first increment of each slice is relative to beginning of the
		// previous row, not the previous macroblock
		self->slice_begin = FALSE;
		self->macroblock_address += increment;
	}
	else {
		if (self->macroblock_address + increment >= self->mb_size) {
			return; // invalid
		}
		if (increment > 1) {
			// Skipped macroblocks reset DC predictors
			self->dc_predictor[0] = 128;
			self->dc_predictor[1] = 128;
			self->dc_predictor[2] = 128;

			// Skipped macroblocks in P-pictures reset motion vectors
			if (self->picture_type == PLM_VIDEO_PICTURE_TYPE_PREDICTIVE) {
				self->motion_forward.h = 0;
				self->motion_forward.v = 0;
			}
		}

		// Predict skipped macroblocks
		while (increment > 1) {
			self->macroblock_address++;
			self->mb_row = self->macroblock_address / self->mb_width;
			self->mb_col = self->macroblock_address % self->mb_width;

			plm_video_predict_macroblock(self);
			increment--;
		}
		self->macroblock_address++;
	}

	self->mb_row = self->macroblock_address / self->mb_width;
	self->mb_col = self->macroblock_address % self->mb_width;

	if (self->mb_col >= self->mb_width || self->mb_row >= self->mb_height) {
		return; // corrupt stream;
	}

	// Process the current macroblock
	const plm_vlc_t *table = PLM_VIDEO_MACROBLOCK_TYPE[self->picture_type];
	self->macroblock_type = plm_buffer_read_vlc(self->buffer, table);

	self->macroblock_intra = (self->macroblock_type & 0x01);
	self->motion_forward.is_set = (self->macroblock_type & 0x08);
	self->motion_backward.is_set = (self->macroblock_type & 0x04);

	// Quantizer scale
	if ((self->macroblock_type & 0x10) != 0) {
		self->quantizer_scale = plm_buffer_read(self->buffer, 5);
	}

	if (self->macroblock_intra) {
		// Intra-coded macroblocks reset motion vectors
		self->motion_backward.h = self->motion_forward.h = 0;
		self->motion_backward.v = self->motion_forward.v = 0;
	}
	else {
		// Non-intra macroblocks reset DC predictors
		self->dc_predictor[0] = 128;
		self->dc_predictor[1] = 128;
		self->dc_predictor[2] = 128;

		plm_video_decode_motion_vectors(self);
		plm_video_predict_macroblock(self);
	}

	// Decode blocks
	int cbp = ((self->macroblock_type & 0x02) != 0)
		? plm_buffer_read_vlc(self->buffer, PLM_VIDEO_CODE_BLOCK_PATTERN)
		: (self->macroblock_intra ? 0x3f : 0);

	for (int block = 0, mask = 0x20; block < 6; block++) {
		if ((cbp & mask) != 0) {
			plm_video_decode_block(self, block);
		}
		mask >>= 1;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
leaq 0x6dfb(%rip), %rsi      # 0xd1f0
callq 0x5700
cwtl
movl %eax, -0x10(%rbp)
cmpl $0x22, -0x10(%rbp)
jne 0x6421
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
leaq 0x6dda(%rip), %rsi      # 0xd1f0
callq 0x5700
cwtl
movl %eax, -0x10(%rbp)
jmp 0x63fe
jmp 0x6423
cmpl $0x23, -0x10(%rbp)
jne 0x644f
movl -0xc(%rbp), %eax
addl $0x21, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
leaq 0x6dac(%rip), %rsi      # 0xd1f0
callq 0x5700
cwtl
movl %eax, -0x10(%rbp)
jmp 0x6423
movl -0x10(%rbp), %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x78(%rax)
je 0x647f
movq -0x8(%rbp), %rax
movl $0x0, 0x78(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
addl 0x7c(%rax), %ecx
movl %ecx, 0x7c(%rax)
jmp 0x6553
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
addl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jl 0x6497
jmp 0x675d
cmpl $0x1, -0xc(%rbp)
jle 0x64e9
movq -0x8(%rbp), %rax
movl $0x80, 0x90(%rax)
movq -0x8(%rbp), %rax
movl $0x80, 0x94(%rax)
movq -0x8(%rbp), %rax
movl $0x80, 0x98(%rax)
movq -0x8(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x64e7
movq -0x8(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x58(%rax)
jmp 0x64e9
jmp 0x64eb
cmpl $0x1, -0xc(%rbp)
jle 0x6546
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x7c(%rax)
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x8(%rbp), %rcx
cltd
idivl 0x24(%rcx)
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x8(%rbp), %rcx
cltd
idivl 0x24(%rcx)
movq -0x8(%rbp), %rax
movl %edx, 0x84(%rax)
movq -0x8(%rbp), %rdi
callq 0x6770
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x64eb
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x7c(%rax)
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x8(%rbp), %rcx
cltd
idivl 0x24(%rcx)
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x8(%rbp), %rcx
cltd
idivl 0x24(%rcx)
movq -0x8(%rbp), %rax
movl %edx, 0x84(%rax)
movq -0x8(%rbp), %rax
movl 0x84(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x24(%rcx), %eax
jge 0x65ad
movq -0x8(%rbp), %rax
movl 0x80(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jl 0x65b2
jmp 0x675d
movq -0x8(%rbp), %rax
movslq 0x44(%rax), %rcx
leaq 0xab9f(%rip), %rax      # 0x11160
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x5700
movswl %ax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x8(%rbp), %rax
movl 0x88(%rax), %ecx
andl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8c(%rax)
movq -0x8(%rbp), %rax
movl 0x88(%rax), %ecx
andl $0x8, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x8(%rbp), %rax
movl 0x88(%rax), %ecx
andl $0x4, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x8(%rbp), %rax
movl 0x88(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x6659
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x5, %esi
callq 0x5320
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x74(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8c(%rax)
je 0x6694
movq -0x8(%rbp), %rax
movl $0x0, 0x54(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x68(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0x6c(%rax)
jmp 0x66d0
movq -0x8(%rbp), %rax
movl $0x80, 0x90(%rax)
movq -0x8(%rbp), %rax
movl $0x80, 0x94(%rax)
movq -0x8(%rbp), %rax
movl $0x80, 0x98(%rax)
movq -0x8(%rbp), %rdi
callq 0x6870
movq -0x8(%rbp), %rdi
callq 0x6770
movq -0x8(%rbp), %rax
movl 0x88(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x66ff
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
leaq 0x6c3c(%rip), %rsi      # 0xd330
callq 0x5700
cwtl
movl %eax, -0x28(%rbp)
jmp 0x6719
movq -0x8(%rbp), %rax
movl 0x8c(%rax), %edx
xorl %eax, %eax
movl $0x3f, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x20, -0x24(%rbp)
cmpl $0x6, -0x20(%rbp)
jge 0x675d
movl -0x1c(%rbp), %eax
andl -0x24(%rbp), %eax
cmpl $0x0, %eax
je 0x674a
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x6940
movl -0x24(%rbp), %eax
sarl %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x672d
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)