// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_video_decode
plm_frame_t *plm_video_decode(plm_video_t *self) {
	if (!plm_video_has_header(self)) {
		return NULL;
	}
	
	plm_frame_t *frame = NULL;
	do {
		if (self->start_code != PLM_START_PICTURE) {
			self->start_code = plm_buffer_find_start_code(self->buffer, PLM_START_PICTURE);
			
			if (self->start_code == -1) {
				// If we reached the end of the file and the previously decoded
				// frame was a reference frame, we still have to return it.
				if (
					self->has_reference_frame &&
					!self->assume_no_b_frames &&
					plm_buffer_has_ended(self->buffer) && (
						self->picture_type == PLM_VIDEO_PICTURE_TYPE_INTRA ||
						self->picture_type == PLM_VIDEO_PICTURE_TYPE_PREDICTIVE
					)
				) {
					self->has_reference_frame = FALSE;
					frame = &self->frame_backward;
					break;
				}

				return NULL;
			}
		}

		// Make sure we have a full picture in the buffer before attempting to
		// decode it. Sadly, this can only be done by seeking for the start code
		// of the next picture. Also, if we didn't find the start code for the
		// next picture, but the source has ended, we assume that this last
		// picture is in the buffer.
		if (
			plm_buffer_has_start_code(self->buffer, PLM_START_PICTURE) == -1 &&
			!plm_buffer_has_ended(self->buffer)
		) {
			return NULL;
		}
		plm_buffer_discard_read_bytes(self->buffer);
		
		plm_video_decode_picture(self);

		if (self->assume_no_b_frames) {
			frame = &self->frame_backward;
		}
		else if (self->picture_type == PLM_VIDEO_PICTURE_TYPE_B) {
			frame = &self->frame_current;
		}
		else if (self->has_reference_frame) {
			frame = &self->frame_forward;
		}
		else {
			self->has_reference_frame = TRUE;
		}
	} while (!frame);
	
	frame->time = self->time;
	self->frames_decoded++;
	self->time = (double)self->frames_decoded / self->framerate;
	
	return frame;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2f60
cmpl $0x0, %eax
jne 0x3d37
movq $0x0, -0x8(%rbp)
jmp 0x3ef1
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x3de5
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
xorl %esi, %esi
callq 0x55f0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x40(%rax)
jne 0x3de3
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2f8(%rax)
je 0x3dd6
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2fc(%rax)
jne 0x3dd6
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
callq 0x5250
cmpl $0x0, %eax
je 0x3dd6
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
je 0x3db5
movq -0x10(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x3dd6
movq -0x10(%rbp), %rax
movl $0x0, 0x2f8(%rax)
movq -0x10(%rbp), %rax
addq $0x130, %rax            # imm = 0x130
movq %rax, -0x18(%rbp)
jmp 0x3eb1
movq $0x0, -0x8(%rbp)
jmp 0x3ef1
jmp 0x3de5
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
xorl %esi, %esi
callq 0x5630
cmpl $-0x1, %eax
jne 0x3e1e
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
callq 0x5250
cmpl $0x0, %eax
jne 0x3e1e
movq $0x0, -0x8(%rbp)
jmp 0x3ef1
movq -0x10(%rbp), %rax
movq 0xa0(%rax), %rdi
callq 0x5060
movq -0x10(%rbp), %rdi
callq 0x5f40
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2fc(%rax)
je 0x3e54
movq -0x10(%rbp), %rax
addq $0x130, %rax            # imm = 0x130
movq %rax, -0x18(%rbp)
jmp 0x3e9d
movq -0x10(%rbp), %rax
cmpl $0x3, 0x44(%rax)
jne 0x3e6e
movq -0x10(%rbp), %rax
addq $0xb0, %rax
movq %rax, -0x18(%rbp)
jmp 0x3e9b
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2f8(%rax)
je 0x3e8b
movq -0x10(%rbp), %rax
addq $0xf0, %rax
movq %rax, -0x18(%rbp)
jmp 0x3e99
movq -0x10(%rbp), %rax
movl $0x1, 0x2f8(%rax)
jmp 0x3e9b
jmp 0x3e9d
jmp 0x3e9f
cmpq $0x0, -0x18(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3d3f
movq -0x10(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm0
movq -0x10(%rbp), %rax
divsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)