// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/../scg.h
// Function: scg__screen_new
static scg__screen_t *scg__screen_new(scg_image_t *draw_target,
                                      const char *title, int scale,
                                      bool fullscreen, bool vsync,
                                      bool lock_fps, bool hide_mouse_cursor) {
    SDL_DisplayMode display_mode;
    if (SDL_GetDesktopDisplayMode(0, &display_mode) != 0) {
        scg_log_errorf("Failed to get SDL desktop display mode. %s",
                       SDL_GetError());

        return NULL;
    }

    SDL_Window *sdl_window = NULL;
    SDL_Renderer *sdl_renderer = NULL;
    SDL_Texture *sdl_texture = NULL;

    int w = draw_target->width;
    int h = draw_target->height;
    int window_w = w * scale;
    int window_h = h * scale;

    // Setup the SDL window.
    {
        sdl_window = SDL_CreateWindow(
            title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_w,
            window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
        if (sdl_window == NULL) {
            scg_log_errorf("Failed to create SDL Window. %s", SDL_GetError());

            return NULL;
        }

        if (fullscreen) {
            SDL_SetWindowFullscreen(sdl_window, SDL_WINDOW_FULLSCREEN_DESKTOP);

            // Desktop fullscreen mode will take the current size of the users
            // desktop,
            SDL_GetWindowSize(sdl_window, &window_w, &window_h);
        }

        int toggle = hide_mouse_cursor ? SDL_DISABLE : SDL_ENABLE;
        SDL_ShowCursor(toggle);
    }

    // Setup the SDL renderer.
    {
        uint32_t sdl_renderer_flags = SDL_RENDERER_ACCELERATED;
        if (vsync) {
            sdl_renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
            SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1");
        }

        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");

        sdl_renderer = SDL_CreateRenderer(sdl_window, -1, sdl_renderer_flags);
        if (sdl_renderer == NULL) {
            scg_log_errorf("Failed to create SDL Renderer. %s", SDL_GetError());

            SDL_DestroyWindow(sdl_window);
            return NULL;
        }

        SDL_RenderSetLogicalSize(sdl_renderer, w, h);
    }

    // Setup the SDL texture which will represent our screen.
    {
        sdl_texture = SDL_CreateTexture(sdl_renderer, SCG__IMAGE_PIXEL_FORMAT,
                                        SDL_TEXTUREACCESS_STREAMING, w, h);
        if (sdl_texture == NULL) {
            scg_log_errorf("Failed to create SDL Texture. %s", SDL_GetError());

            SDL_DestroyRenderer(sdl_renderer);
            SDL_DestroyWindow(sdl_window);
            return NULL;
        }
    }

    scg__screen_t *screen = malloc(sizeof(*screen));
    if (screen == NULL) {
        scg_log_error("Failed to allocate memory for screen");

        SDL_DestroyTexture(sdl_texture);
        SDL_DestroyRenderer(sdl_renderer);
        SDL_DestroyWindow(sdl_window);
        return NULL;
    }

    screen->window_width = window_w;
    screen->window_height = window_h;
    screen->target_fps = scg__get_monitor_refresh_rate(display_mode);
    screen->target_frame_time_secs = 1.0 / (float64_t)screen->target_fps;
    screen->last_frame_counter = scg_get_performance_counter();
    screen->sdl_window = sdl_window;
    screen->sdl_renderer = sdl_renderer;
    screen->sdl_texture = sdl_texture;
    screen->vsync = vsync;
    screen->lock_fps = lock_fps;

    screen->frame_metrics.frame_time_secs = 0.0f;
    screen->frame_metrics.frame_time_millisecs = 0.0f;
    screen->frame_metrics.fps = 0;
    screen->frame_metrics_update_counter = scg_get_performance_counter();
    screen->frame_metrics.target_fps = screen->target_fps;

    return screen;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movl %r9d, -0x7c(%rbp)
movl %r8d, -0x78(%rbp)
movl %ecx, %eax
movl -0x7c(%rbp), %ecx
movl %edx, %r8d
movl -0x78(%rbp), %edx
movl %r8d, -0x74(%rbp)
movq %rsi, %r8
movq %rdi, %r9
movl -0x74(%rbp), %edi
movb %al, %sil
movb 0x10(%rbp), %al
movq %r9, -0x10(%rbp)
movq %r8, -0x18(%rbp)
movl %edi, -0x1c(%rbp)
andb $0x1, %sil
movb %sil, -0x1d(%rbp)
andb $0x1, %dl
movb %dl, -0x1e(%rbp)
andb $0x1, %cl
movb %cl, -0x1f(%rbp)
andb $0x1, %al
movb %al, -0x20(%rbp)
xorl %edi, %edi
leaq -0x38(%rbp), %rsi
callq 0x2370
cmpl $0x0, %eax
je 0x500e
callq 0x2190
movq %rax, %r9
xorl %edi, %edi
leaq 0x2635(%rip), %rsi      # 0x761b
leaq 0x266e(%rip), %rdx      # 0x765b
leaq 0x20c2(%rip), %rcx      # 0x70b6
movl $0x745, %r8d            # imm = 0x745
movb $0x0, %al
callq 0x22e0
movq $0x0, -0x8(%rbp)
jmp 0x5378
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
imull -0x1c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x58(%rbp), %eax
imull -0x1c(%rbp), %eax
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl -0x5c(%rbp), %ecx
movl -0x60(%rbp), %r8d
movl $0x2fff0000, %edx       # imm = 0x2FFF0000
movl $0x2004, %r9d           # imm = 0x2004
movl %edx, %esi
callq 0x2050
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x50ae
callq 0x2190
movq %rax, %r9
xorl %edi, %edi
leaq 0x25e5(%rip), %rsi      # 0x766b
leaq 0x25ce(%rip), %rdx      # 0x765b
leaq 0x2022(%rip), %rcx      # 0x70b6
movl $0x759, %r8d            # imm = 0x759
movb $0x0, %al
callq 0x22e0
movq $0x0, -0x8(%rbp)
jmp 0x5378
testb $0x1, -0x1d(%rbp)
je 0x50d3
movq -0x40(%rbp), %rdi
movl $0x1001, %esi           # imm = 0x1001
callq 0x2280
movq -0x40(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x20b0
movb -0x20(%rbp), %dl
movl $0x1, %eax
xorl %ecx, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %edi
callq 0x23d0
movl $0x2, -0x68(%rbp)
testb $0x1, -0x1e(%rbp)
je 0x5117
movl -0x68(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x68(%rbp)
leaq 0x2595(%rip), %rdi      # 0x76a0
leaq 0x259f(%rip), %rsi      # 0x76b1
callq 0x2380
leaq 0x2595(%rip), %rdi      # 0x76b3
leaq 0x25a7(%rip), %rsi      # 0x76cc
callq 0x2380
movq -0x40(%rbp), %rdi
movl -0x68(%rbp), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x2040
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5188
callq 0x2190
movq %rax, %r9
xorl %edi, %edi
leaq 0x257d(%rip), %rsi      # 0x76d4
leaq 0x24fd(%rip), %rdx      # 0x765b
leaq 0x1f51(%rip), %rcx      # 0x70b6
movl $0x776, %r8d            # imm = 0x776
movb $0x0, %al
callq 0x22e0
movq -0x40(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x5378
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
movl -0x58(%rbp), %edx
callq 0x2080
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %ecx
movl -0x58(%rbp), %r8d
movl $0x16362004, %esi       # imm = 0x16362004
movl $0x1, %edx
callq 0x23b0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5207
callq 0x2190
movq %rax, %r9
xorl %edi, %edi
leaq 0x253e(%rip), %rsi      # 0x770b
leaq 0x2487(%rip), %rdx      # 0x765b
leaq 0x1edb(%rip), %rcx      # 0x70b6
movl $0x784, %r8d            # imm = 0x784
movb $0x0, %al
callq 0x22e0
movq -0x48(%rbp), %rdi
callq 0x20c0
movq -0x40(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x5378
movl $0x68, %edi
callq 0x22f0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x526f
xorl %edi, %edi
leaq 0x1e6b(%rip), %rsi      # 0x7090
leaq 0x242f(%rip), %rdx      # 0x765b
leaq 0x1e83(%rip), %rcx      # 0x70b6
movl $0x78e, %r8d            # imm = 0x78E
leaq 0x2501(%rip), %r9       # 0x7741
movb $0x0, %al
callq 0x22e0
movq -0x50(%rbp), %rdi
callq 0x2160
movq -0x48(%rbp), %rdi
callq 0x20c0
movq -0x40(%rbp), %rdi
callq 0x2030
movq $0x0, -0x8(%rbp)
jmp 0x5378
movl -0x5c(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, (%rax)
movl -0x60(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x28(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups -0x38(%rbp), %xmm0
movups %xmm0, (%rax)
callq 0x69d0
movl %eax, %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x70(%rbp), %rax
cvtsi2sdl 0x8(%rax), %xmm1
movsd 0x1dbd(%rip), %xmm0     # 0x7070
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rax)
callq 0x2660
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x48(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x50(%rbp), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x60(%rax)
movb -0x1e(%rbp), %cl
movq -0x70(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x48(%rax)
movb -0x1f(%rbp), %cl
movq -0x70(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x49(%rax)
movq -0x70(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x70(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x70(%rbp), %rax
movl $0x0, 0x40(%rax)
callq 0x2660
movq %rax, %xmm0
movaps 0x1d02(%rip), %xmm1     # 0x7040
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1d06(%rip), %xmm1     # 0x7050
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq -0x70(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x70(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)