// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movsd %xmm0, (%rsp)
movq %rdi, %rbx
callq 0x25e1
testl %eax, %eax
je 0x33c5
cmpq $0x0, 0x60(%rbx)
je 0x32b2
cmpl $0x0, 0x20(%rbx)
setne %bpl
jmp 0x32b4
xorl %ebp, %ebp
cmpq $0x0, 0x70(%rbx)
je 0x32c5
cmpl $0x0, 0x40(%rbx)
setne %r14b
jmp 0x32c8
xorl %r14d, %r14d
movl %ebp, %eax
orb %r14b, %al
testb $0x1, %al
je 0x33c5
movsd 0x8(%rbx), %xmm0
addsd (%rsp), %xmm0
movsd 0x48(%rbx), %xmm1
movsd %xmm0, 0x10(%rsp)
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
testb %bpl, %bpl
je 0x3335
movq 0x30(%rbx), %rdi
movsd 0x10(%rsp), %xmm0
ucomisd 0x10(%rdi), %xmm0
jbe 0x3335
callq 0x33e3
testq %rax, %rax
je 0x332f
movq 0x68(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x60(%rbx)
movl $0x1, %r13d
jmp 0x3338
movl $0x1, %r12d
xorl %r13d, %r13d
testb %r14b, %r14b
je 0x3372
movq 0x58(%rbx), %rdi
movsd 0x8(%rsp), %xmm0
ucomisd (%rdi), %xmm0
jbe 0x3372
callq 0x3520
testq %rax, %rax
je 0x336c
movq 0x78(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x70(%rbx)
movl $0x1, %r13d
jmp 0x3372
movl $0x1, %r15d
testl %r13d, %r13d
jne 0x32fa
testl %r12d, %r12d
sete %al
andb %al, %bpl
testl %r15d, %r15d
sete %al
andb %al, %r14b
orb %bpl, %r14b
jne 0x33b6
movq (%rbx), %rax
movq (%rax), %rax
cmpl $0x0, 0x24(%rax)
je 0x33b6
cmpl $0x0, 0x14(%rbx)
je 0x33d4
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3135
movsd (%rsp), %xmm0
addsd 0x8(%rbx), %xmm0
movsd %xmm0, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, 0x10(%rbx)
jmp 0x33c5