// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_seek_frame
plm_frame_t *plm_seek_frame(plm_t *self, double time, int seek_exact) {
	if (!plm_init_decoders(self)) {
		return NULL;
	}

	if (!self->video_packet_type) {
		return NULL;
	}

	int type = self->video_packet_type;

	double start_time = plm_demux_get_start_time(self->demux, type);
	double duration = plm_demux_get_duration(self->demux, type);

	if (time < 0) {
		time = 0;
	}
	else if (time > duration) {
		time = duration;
	}
	
	plm_packet_t *packet = plm_demux_seek(self->demux, time, type, TRUE);
	if (!packet) {
		return NULL;
	}

	// Disable writing to the audio buffer while decoding video
	int previous_audio_packet_type = self->audio_packet_type;
	self->audio_packet_type = 0;

	// Clear video buffer and decode the found packet
	plm_video_rewind(self->video_decoder);
	plm_video_set_time(self->video_decoder, packet->pts - start_time);
	plm_buffer_write(self->video_buffer, packet->data, packet->length);
	plm_frame_t *frame = plm_video_decode(self->video_decoder);	

	// If we want to seek to an exact frame, we have to decode all frames
	// on top of the intra frame we just jumped to.
	if (seek_exact) {
		while (frame && frame->time < time) {
			frame = plm_video_decode(self->video_decoder);
		}
	}

	// Enable writing to the audio buffer again?
	self->audio_packet_type = previous_audio_packet_type;

	if (frame) {
		self->time = frame->time;
	}

	self->has_ended = FALSE;
	return frame;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2720
cmpl $0x0, %eax
jne 0x453f
movq $0x0, -0x8(%rbp)
jmp 0x46ce
movq -0x10(%rbp), %rax
cmpl $0x0, 0x20(%rax)
jne 0x4556
movq $0x0, -0x8(%rbp)
jmp 0x46ce
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x20(%rbp), %esi
callq 0x46e0
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x20(%rbp), %esi
callq 0x3700
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x459c
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x45b4
movsd -0x18(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x45b2
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x45b4
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movsd -0x18(%rbp), %xmm0
movl -0x20(%rbp), %esi
movl $0x1, %edx
callq 0x47c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x45e5
movq $0x0, -0x8(%rbp)
jmp 0x46ce
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3940
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
subsd -0x28(%rbp), %xmm0
callq 0x4be0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x43e0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3d10
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x4699
jmp 0x4658
xorl %eax, %eax
cmpq $0x0, -0x48(%rbp)
movb %al, -0x49(%rbp)
je 0x467b
movq -0x48(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x4684
jmp 0x4697
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3d10
movq %rax, -0x48(%rbp)
jmp 0x4658
jmp 0x4699
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x40(%rax)
cmpq $0x0, -0x48(%rbp)
je 0x46bb
movq -0x48(%rbp), %rax
movsd (%rax), %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)