// File: /workspace/github_c_makefile_star2_O2/phoboslab[P]pl_mpeg/./pl_mpeg.h
// Function: plm_decode
void plm_decode(plm_t *self, double tick) {
	if (!plm_init_decoders(self)) {
		return;
	}

	int decode_video = (self->video_decode_callback && self->video_packet_type);
	int decode_audio = (self->audio_decode_callback && self->audio_packet_type);

	if (!decode_video && !decode_audio) {
		// Nothing to do here
		return;
	}

	int did_decode = FALSE;
	int decode_video_failed = FALSE;
	int decode_audio_failed = FALSE;

	double video_target_time = self->time + tick;
	double audio_target_time = self->time + tick + self->audio_lead_time;

	do {
		did_decode = FALSE;
		
		if (decode_video && plm_video_get_time(self->video_decoder) < video_target_time) {
			plm_frame_t *frame = plm_video_decode(self->video_decoder);
			if (frame) {
				self->video_decode_callback(self, frame, self->video_decode_callback_user_data);
				did_decode = TRUE;
			}
			else {
				decode_video_failed = TRUE;
			}
		}

		if (decode_audio && plm_audio_get_time(self->audio_decoder) < audio_target_time) {
			plm_samples_t *samples = plm_audio_decode(self->audio_decoder);
			if (samples) {
				self->audio_decode_callback(self, samples, self->audio_decode_callback_user_data);
				did_decode = TRUE;
			}
			else {
				decode_audio_failed = TRUE;
			}
		}
	} while (did_decode);
	
	// Did all sources we wanted to decode fail and the demuxer is at the end?
	if (
		(!decode_video || decode_video_failed) && 
		(!decode_audio || decode_audio_failed) &&
		plm_demux_has_ended(self->demux)
	) {
		plm_handle_end(self);
		return;
	}

	self->time += tick;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x10(%rsp)
movq %rdi, %rbx
callq 0x253e
testl %eax, %eax
je 0x2ff3
cmpq $0x0, 0x60(%rbx)
je 0x2ec9
cmpl $0x0, 0x20(%rbx)
setne %al
movl %eax, 0xc(%rsp)
jmp 0x2ed1
movl $0x0, 0xc(%rsp)
cmpq $0x0, 0x70(%rbx)
je 0x2ee2
cmpl $0x0, 0x40(%rbx)
setne %r14b
jmp 0x2ee5
xorl %r14d, %r14d
movl 0xc(%rsp), %eax
orb %r14b, %al
testb $0x1, %al
je 0x2ff3
movsd 0x8(%rbx), %xmm0
addsd 0x10(%rsp), %xmm0
movsd 0x48(%rbx), %xmm1
movsd %xmm0, 0x20(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
xorl %ecx, %ecx
xorl %ebp, %ebp
movl %ebp, %r13d
movl %ecx, %r12d
cmpb $0x0, 0xc(%rsp)
je 0x2f5f
movq 0x30(%rbx), %rdi
movsd 0x20(%rsp), %xmm0
ucomisd 0x10(%rdi), %xmm0
jbe 0x2f5f
callq 0x3008
pushq $0x1
popq %rbp
movl $0x0, %r15d
testq %rax, %rax
je 0x2f65
movq 0x68(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x60(%rbx)
movl %r13d, %ebp
pushq $0x1
popq %r15
jmp 0x2f65
movl %r13d, %ebp
xorl %r15d, %r15d
testb %r14b, %r14b
je 0x2f9d
movq 0x58(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
ucomisd (%rdi), %xmm0
jbe 0x2f9d
callq 0x310b
pushq $0x1
popq %rcx
testq %rax, %rax
je 0x2fa0
movq 0x78(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x70(%rbx)
movl %r12d, %ecx
pushq $0x1
popq %r15
jmp 0x2fa0
movl %r12d, %ecx
testl %r15d, %r15d
jne 0x2f18
testl %ebp, %ebp
sete %al
movl 0xc(%rsp), %edx
andb %al, %dl
testl %ecx, %ecx
sete %al
andb %al, %r14b
orb %dl, %r14b
jne 0x2fe3
movq (%rbx), %rax
movq (%rax), %rax
cmpl $0x0, 0x24(%rax)
je 0x2fe3
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x319e
movsd 0x10(%rsp), %xmm0
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq