// File: /workspace/github_c_makefile_star2_O0/phoboslab[P]pl_mpeg/pl_mpeg_player_sdl.c
// Function: app_update
void app_update(app_t *self) {
	double seek_to = -1;

	SDL_Event ev;
	while (SDL_PollEvent(&ev)) {
		if (
			ev.type == SDL_QUIT || 
			(ev.type == SDL_KEYUP && ev.key.keysym.sym == SDLK_ESCAPE)
		) {
			self->wants_to_quit = TRUE;
		}
		// Seek 3sec forward/backward using arrow keys
		if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_RIGHT) {
			seek_to = plm_get_time(self->plm) + 3;
		}
		else if (ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_LEFT) {
			seek_to = plm_get_time(self->plm) - 3;
		}
	}


	// Clear renderer, copy texture and present
	SDL_RenderClear(self->renderer);
        
	SDL_RenderCopy(self->renderer, self->texture, NULL, &self->rectangle);

	SDL_RenderPresent(self->renderer);

	// Compute the delta time since the last app_update(), limit max step to 
	// 1/30th of a second
	double current_time = (double)SDL_GetTicks() / 1000.0;
	double elapsed_time = current_time - self->last_time;
	if (elapsed_time > 1.0 / 30.0) {
		elapsed_time = 1.0 / 30.0;
	}
	self->last_time = current_time;

	// Seek using mouse position
	int mouse_x, mouse_y;
	if (SDL_GetMouseState(&mouse_x, &mouse_y) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
		int sx, sy;
		SDL_GetWindowSize(self->window, &sx, &sy);
		seek_to = plm_get_duration(self->plm) * ((float)mouse_x / (float)sx);
	}
	
	// Seek or advance decode
	if (seek_to != -1) {
		SDL_ClearQueuedAudio(self->audio_device);
		plm_seek(self->plm, seek_to, FALSE);
	}
	else {
		plm_decode(self->plm, elapsed_time);
	}

	if (plm_has_ended(self->plm)) {
		self->wants_to_quit = TRUE;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movsd 0xaf4(%rip), %xmm0      # 0xd008
movsd %xmm0, -0x10(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x20f0
cmpl $0x0, %eax
je 0xc5b5
cmpl $0x100, -0x48(%rbp)     # imm = 0x100
je 0xc543
cmpl $0x301, -0x48(%rbp)     # imm = 0x301
jne 0xc54e
cmpl $0x1b, -0x34(%rbp)
jne 0xc54e
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
cmpl $0x300, -0x48(%rbp)     # imm = 0x300
jne 0xc57f
cmpl $0x4000004f, -0x34(%rbp) # imm = 0x4000004F
jne 0xc57f
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x36b0
movsd 0xac4(%rip), %xmm1      # 0xd038
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xc5b0
cmpl $0x300, -0x48(%rbp)     # imm = 0x300
jne 0xc5ae
cmpl $0x40000050, -0x34(%rbp) # imm = 0x40000050
jne 0xc5ae
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x36b0
movsd 0xa93(%rip), %xmm1      # 0xd038
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xc5b0
jmp 0xc519
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2150
movq -0x8(%rbp), %rcx
movq 0x20(%rcx), %rdi
movq 0x28(%rcx), %rsi
addq $0x30, %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x2190
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2080
callq 0x2170
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd 0xa34(%rip), %xmm1      # 0xd030
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
movq -0x8(%rbp), %rax
subsd 0x8(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movsd 0xa03(%rip), %xmm1      # 0xd028
ucomisd %xmm1, %xmm0
jbe 0xc638
movsd 0x9f5(%rip), %xmm0      # 0xd028
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x8(%rax)
leaq -0x5c(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2230
andl $0x1, %eax
cmpl $0x0, %eax
je 0xc697
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x64(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x20a0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x36d0
cvtsi2ssl -0x5c(%rbp), %xmm1
cvtsi2ssl -0x64(%rbp), %xmm2
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x964(%rip), %xmm1      # 0xd008
ucomisd %xmm1, %xmm0
jne 0xc6ae
jp 0xc6ae
jmp 0xc6cf
movq -0x8(%rbp), %rax
movl 0x40(%rax), %edi
callq 0x2220
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movsd -0x10(%rbp), %xmm0
xorl %esi, %esi
callq 0x4c20
jmp 0xc6e0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movsd -0x58(%rbp), %xmm0
callq 0x3af0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3a70
cmpl $0x0, %eax
je 0xc6fc
movq -0x8(%rbp), %rax
movl $0x1, 0x10(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)