// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_video_decode_picture
void plm_video_decode_picture(plm_video_t *self) {
	plm_buffer_skip(self->buffer, 10); // skip temporalReference
	self->picture_type = plm_buffer_read(self->buffer, 3);
	plm_buffer_skip(self->buffer, 16); // skip vbv_delay

	// D frames or unknown coding type
	if (self->picture_type <= 0 || self->picture_type > PLM_VIDEO_PICTURE_TYPE_B) {
		return;
	}

	// Forward full_px, f_code
	if (
		self->picture_type == PLM_VIDEO_PICTURE_TYPE_PREDICTIVE ||
		self->picture_type == PLM_VIDEO_PICTURE_TYPE_B
	) {
		self->motion_forward.full_px = plm_buffer_read(self->buffer, 1);
		int f_code = plm_buffer_read(self->buffer, 3);
		if (f_code == 0) {
			// Ignore picture with zero f_code
			return;
		}
		self->motion_forward.r_size = f_code - 1;
	}

	// Backward full_px, f_code
	if (self->picture_type == PLM_VIDEO_PICTURE_TYPE_B) {
		self->motion_backward.full_px = plm_buffer_read(self->buffer, 1);
		int f_code = plm_buffer_read(self->buffer, 3);
		if (f_code == 0) {
			// Ignore picture with zero f_code
			return;
		}
		self->motion_backward.r_size = f_code - 1;
	}

	plm_frame_t frame_temp = self->frame_forward;
	if (
		self->picture_type == PLM_VIDEO_PICTURE_TYPE_INTRA ||
		self->picture_type == PLM_VIDEO_PICTURE_TYPE_PREDICTIVE
	) {
		self->frame_forward = self->frame_backward;
	}


	// Find first slice start code; skip extension and user data
	do {
		self->start_code = plm_buffer_next_start_code(self->buffer);
	} while (
		self->start_code == PLM_START_EXTENSION || 
		self->start_code == PLM_START_USER_DATA
	);

	// Decode all slices
	while (PLM_START_IS_SLICE(self->start_code)) {
		plm_video_decode_slice(self, self->start_code & 0x000000FF);
		if (self->macroblock_address >= self->mb_size - 2) {
			break;
		}
		self->start_code = plm_buffer_next_start_code(self->buffer);
	}

	// If this is a reference picture rotate the prediction pointers
	if (
		self->picture_type == PLM_VIDEO_PICTURE_TYPE_INTRA ||
		self->picture_type == PLM_VIDEO_PICTURE_TYPE_PREDICTIVE
	) {
		self->frame_backward = self->frame_current;
		self->frame_current = frame_temp;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0xa, %esi
callq 0x5450
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x3, %esi
callq 0x5320
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x44(%rax)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x10, %esi
callq 0x5450
movq -0x8(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jle 0x5fa8
movq -0x8(%rbp), %rax
cmpl $0x3, 0x44(%rax)
jle 0x5fad
jmp 0x61b9
movq -0x8(%rbp), %rax
cmpl $0x2, 0x44(%rax)
je 0x5fc1
movq -0x8(%rbp), %rax
cmpl $0x3, 0x44(%rax)
jne 0x600f
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x1, %esi
callq 0x5320
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x3, %esi
callq 0x5320
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x6002
jmp 0x61b9
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x8(%rbp), %rax
cmpl $0x3, 0x44(%rax)
jne 0x6067
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x1, %esi
callq 0x5320
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
movl $0x3, %esi
callq 0x5320
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x605a
jmp 0x61b9
movl -0x10(%rbp), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x8(%rbp), %rsi
addq $0xf0, %rsi
leaq -0x50(%rbp), %rdi
movl $0x40, %edx
callq 0x2130
movq -0x8(%rbp), %rax
cmpl $0x1, 0x44(%rax)
je 0x6094
movq -0x8(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x60b4
movq -0x8(%rbp), %rdi
addq $0xf0, %rdi
movq -0x8(%rbp), %rsi
addq $0x130, %rsi            # imm = 0x130
movl $0x40, %edx
callq 0x2130
jmp 0x60b6
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
callq 0x5520
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x8(%rbp), %rcx
movb $0x1, %al
cmpl $0xb5, 0x40(%rcx)
movb %al, -0x51(%rbp)
je 0x60f2
movq -0x8(%rbp), %rax
cmpl $0xb2, 0x40(%rax)
sete %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x60b6
jmp 0x60fb
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1, 0x40(%rcx)
movb %al, -0x52(%rbp)
jl 0x611b
movq -0x8(%rbp), %rax
cmpl $0xaf, 0x40(%rax)
setle %al
movb %al, -0x52(%rbp)
movb -0x52(%rbp), %al
testb $0x1, %al
jne 0x6124
jmp 0x616c
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x40(%rax), %esi
andl $0xff, %esi
callq 0x62a0
movq -0x8(%rbp), %rax
movl 0x7c(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x2c(%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jl 0x6151
jmp 0x616c
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rdi
callq 0x5520
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x40(%rax)
jmp 0x60fb
movq -0x8(%rbp), %rax
cmpl $0x1, 0x44(%rax)
je 0x6180
movq -0x8(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x61b9
movq -0x8(%rbp), %rdi
addq $0x130, %rdi            # imm = 0x130
movq -0x8(%rbp), %rsi
addq $0xb0, %rsi
movl $0x40, %edx
callq 0x2130
movq -0x8(%rbp), %rdi
addq $0xb0, %rdi
leaq -0x50(%rbp), %rsi
movl $0x40, %edx
callq 0x2130
addq $0x60, %rsp
popq %rbp
retq
nop