// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/../scg.h
// Function: scg__screen_present
static void scg__screen_present(scg__screen_t *screen,
                                scg_image_t *draw_target) {
    // Wait until we have reached the target amount of time per frame (e.g 60hz,
    // ~16ms).
    if (screen->lock_fps) {
        float64_t target_secs = screen->target_frame_time_secs;

        if (scg_get_elapsed_time_secs(scg_get_performance_counter(),
                                      screen->last_frame_counter) <
            target_secs) {
            float64_t elapsed_time = scg_get_elapsed_time_secs(
                scg_get_performance_counter(), screen->last_frame_counter);

            int32_t sleep_time = ((target_secs - elapsed_time) * 1000) - 1;
            if (sleep_time > 0) {
                SDL_Delay(sleep_time);
            }

            while (scg_get_elapsed_time_secs(scg_get_performance_counter(),
                                             screen->last_frame_counter) <
                   target_secs) {
            }
        }
    }

    uint64_t end_frame_counter = scg_get_performance_counter();

    // Update the texture and present it on screen.
    {
        SDL_UpdateTexture(screen->sdl_texture, NULL, draw_target->pixels,
                          draw_target->pitch);
        SDL_RenderClear(screen->sdl_renderer);
        SDL_RenderCopy(screen->sdl_renderer, screen->sdl_texture, NULL, NULL);
        SDL_RenderPresent(screen->sdl_renderer);
    }

    // Update the frame metrics every second.
    // TODO: Instead of capturing every second, average the metrics...
    {
        float64_t elapsed_time_secs =
            scg_get_elapsed_time_secs(scg_get_performance_counter(),
                                      screen->frame_metrics_update_counter);
        if (elapsed_time_secs >= 1.0f) {
            screen->frame_metrics.frame_time_secs = scg_get_elapsed_time_secs(
                end_frame_counter, screen->last_frame_counter);
            screen->frame_metrics.frame_time_millisecs =
                scg_get_elapsed_time_millisecs(end_frame_counter,
                                               screen->last_frame_counter);
            screen->frame_metrics.fps = roundf(
                (float64_t)scg_get_performance_frequency() /
                (float64_t)(end_frame_counter - screen->last_frame_counter));

            screen->frame_metrics_update_counter =
                scg_get_performance_counter();
        }
    }

    screen->last_frame_counter = end_frame_counter;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x49(%rax)
je 0x5aeb
movq -0x8(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
callq 0x2660
movq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2680
movaps %xmm0, %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5ae9
callq 0x2660
movq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2680
movsd %xmm0, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movsd 0x15dd(%rip), %xmm1     # 0x7078
mulsd %xmm1, %xmm0
movsd 0x15d9(%rip), %xmm1     # 0x7080
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x5ac0
movl -0x24(%rbp), %edi
callq 0x2170
jmp 0x5ac2
callq 0x2660
movq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2680
movaps %xmm0, %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x5ae7
jmp 0x5ac2
jmp 0x5ae9
jmp 0x5aeb
callq 0x2660
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
movl 0x8(%rax), %ecx
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0x40(%rbp)
callq 0x21a0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x2240
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
movq 0x60(%rax), %rsi
movq %rcx, %rdx
callq 0x2270
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x2070
callq 0x2660
movq %rax, %rdi
movq -0x8(%rbp), %rax
movsd 0x20(%rax), %xmm0
movsd 0x1529(%rip), %xmm2     # 0x7088
movaps %xmm0, %xmm1
subsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
cvttsd2si %xmm0, %rsi
movq %rsi, %rcx
sarq $0x3f, %rcx
andq %rcx, %rax
orq %rax, %rsi
callq 0x2680
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movsd 0x14dc(%rip), %xmm1     # 0x7070
ucomisd %xmm1, %xmm0
jb 0x5c77
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2680
movq -0x8(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2710
movq -0x8(%rbp), %rax
movsd %xmm0, 0x38(%rax)
callq 0x2670
movq %rax, %xmm0
movaps 0x145d(%rip), %xmm3     # 0x7040
movaps %xmm3, -0x60(%rbp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x145d(%rip), %xmm2     # 0x7050
movaps %xmm2, -0x50(%rbp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
callq 0x2250
movq -0x68(%rbp), %rax
cvttss2si %xmm0, %ecx
movl %ecx, 0x40(%rax)
callq 0x2660
movaps -0x60(%rbp), %xmm2
movaps -0x50(%rbp), %xmm1
movq %rax, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)