// File: /workspace/github_c_makefile_star2_O1/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 0x267c
testl %eax, %eax
je 0x34ea
cmpq $0x0, 0x60(%rbx)
je 0x33d7
cmpl $0x0, 0x20(%rbx)
setne %bpl
jmp 0x33d9
xorl %ebp, %ebp
cmpq $0x0, 0x70(%rbx)
je 0x33ea
cmpl $0x0, 0x40(%rbx)
setne %r14b
jmp 0x33ed
xorl %r14d, %r14d
movl %ebp, %eax
orb %r14b, %al
testb $0x1, %al
je 0x34ea
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 0x345a
movq 0x30(%rbx), %rdi
movsd 0x10(%rsp), %xmm0
ucomisd 0x10(%rdi), %xmm0
jbe 0x345a
callq 0x3508
testq %rax, %rax
je 0x3454
movq 0x68(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x60(%rbx)
movl $0x1, %r13d
jmp 0x345d
movl $0x1, %r12d
xorl %r13d, %r13d
testb %r14b, %r14b
je 0x3497
movq 0x58(%rbx), %rdi
movsd 0x8(%rsp), %xmm0
ucomisd (%rdi), %xmm0
jbe 0x3497
callq 0x367a
testq %rax, %rax
je 0x3491
movq 0x78(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq *0x70(%rbx)
movl $0x1, %r13d
jmp 0x3497
movl $0x1, %r15d
testl %r13d, %r13d
jne 0x341f
testl %r12d, %r12d
sete %al
andb %al, %bpl
testl %r15d, %r15d
sete %al
andb %al, %r14b
orb %bpl, %r14b
jne 0x34db
movq (%rbx), %rax
movq (%rax), %rax
cmpl $0x0, 0x24(%rax)
je 0x34db
cmpl $0x0, 0x14(%rbx)
je 0x34f9
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x325a
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 0x34ea