// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/mouse.c
// Function: main
int main(int arcg, char *argv[]) {
    scg_config_t config = scg_config_new_default();
    config.video.title = "SCG Example: Mouse";

    scg_app_t app;
    scg_app_init(&app, config);

    scg_image_t *cursor = scg_image_new_from_bmp("assets/mouse_cursor.bmp");
    if (cursor == NULL) {
        return -1;
    }

    while (scg_app_process_events(&app)) {
        scg_image_clear(app.draw_target, SCG_COLOR_BLUE);

        scg_image_t *draw_target = app.draw_target;
        scg_mouse_t *mouse = app.mouse;

        int w = draw_target->width;
        int h = draw_target->height;
        int half_w = w / 2;
        int half_h = h / 2;
        scg_pixel_t text_color = SCG_COLOR_WHITE;

        scg_image_set_blend_mode(draw_target, SCG_BLEND_MODE_NONE);
        scg_image_draw_string(draw_target, "Mouse State", half_w,
                              half_h - SCG_FONT_SIZE * 4, true, text_color);

        {
            char str[1024];
            scg_sprintf(str, "X: %d, Y: %d, Win X: %d, Win Y: %d", mouse->x,
                        mouse->y, mouse->window_x, mouse->window_y);
            scg_image_draw_string(app.draw_target, str, half_w, half_h, true,
                                  text_color);
        }

        {
            bool left_down =
                scg_mouse_is_button_down(mouse, SCG_MOUSE_BUTTON_LEFT);
            bool right_down =
                scg_mouse_is_button_down(mouse, SCG_MOUSE_BUTTON_RIGHT);
            bool middle_down =
                scg_mouse_is_button_down(mouse, SCG_MOUSE_BUTTON_MIDDLE);

            char str[1024];
            scg_sprintf(str,
                        "Left Button: %d, Right Button: %d, Middle Button: %d",
                        left_down, right_down, middle_down);
            scg_image_draw_string(draw_target, str, half_w,
                                  half_h + SCG_FONT_SIZE * 2, true, text_color);
        }

        scg_image_set_blend_mode(draw_target, SCG_BLEND_MODE_ALPHA);
        scg_image_draw_image(draw_target, cursor, mouse->x, mouse->y);

        scg_app_present(&app);
    }

    scg_app_free(&app);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x920, %rsp            # imm = 0x920
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x49e0
leaq 0xe83(%rip), %rax       # 0x758c
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x20(%rax)
movups -0x38(%rbp), %xmm0
movups -0x28(%rbp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0xa0(%rbp), %rdi
callq 0x4a30
leaq 0xe65(%rip), %rdi       # 0x759f
callq 0x2c10
movq %rax, -0xa8(%rbp)
cmpq $0x0, -0xa8(%rbp)
jne 0x675c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x69b7
jmp 0x675e
leaq -0xa0(%rbp), %rdi
callq 0x56b0
testb $0x1, %al
jne 0x6773
jmp 0x69a4
movq -0x68(%rbp), %rdi
movb $-0x1, -0xac(%rbp)
movb $0x0, -0xab(%rbp)
movb $0x0, -0xaa(%rbp)
movb $-0x1, -0xa9(%rbp)
movl -0xac(%rbp), %esi
callq 0x3100
movq -0x68(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xc8(%rbp)
movl -0xc4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xcc(%rbp)
movl -0xc8(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xd0(%rbp)
movl 0x83b(%rip), %eax       # 0x703c
movl %eax, -0xd4(%rbp)
movq -0xb8(%rbp), %rdi
xorl %esi, %esi
callq 0x2ec0
movq -0xb8(%rbp), %rdi
movl -0xcc(%rbp), %edx
movl -0xd0(%rbp), %ecx
subl $0x20, %ecx
movl -0xd4(%rbp), %r9d
leaq 0xd7e(%rip), %rsi       # 0x75b7
movl $0x1, %r8d
callq 0x4190
leaq -0x4e0(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl (%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %r8d
movq -0xc0(%rbp), %rax
movl 0xc(%rax), %r9d
leaq 0xd48(%rip), %rsi       # 0x75c3
movb $0x0, %al
callq 0x27a0
movq -0x68(%rbp), %rdi
leaq -0x4e0(%rbp), %rsi
movl -0xcc(%rbp), %edx
movl -0xd0(%rbp), %ecx
movl -0xd4(%rbp), %r9d
movl $0x1, %r8d
callq 0x4190
movq -0xc0(%rbp), %rdi
movl $0x1, %esi
callq 0x4750
andb $0x1, %al
movb %al, -0x4e1(%rbp)
movq -0xc0(%rbp), %rdi
movl $0x3, %esi
callq 0x4750
andb $0x1, %al
movb %al, -0x4e2(%rbp)
movq -0xc0(%rbp), %rdi
movl $0x2, %esi
callq 0x4750
andb $0x1, %al
movb %al, -0x4e3(%rbp)
leaq -0x8f0(%rbp), %rdi
movb -0x4e1(%rbp), %al
andb $0x1, %al
movzbl %al, %edx
movb -0x4e2(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x4e3(%rbp), %al
andb $0x1, %al
movzbl %al, %r8d
leaq 0xcc0(%rip), %rsi       # 0x75e6
movb $0x0, %al
callq 0x27a0
movq -0xb8(%rbp), %rdi
leaq -0x8f0(%rbp), %rsi
movl -0xcc(%rbp), %edx
movl -0xd0(%rbp), %ecx
addl $0x10, %ecx
movl -0xd4(%rbp), %r9d
movl $0x1, %r8d
callq 0x4190
movq -0xb8(%rbp), %rdi
movl $0x2, %esi
callq 0x2ec0
movq -0xb8(%rbp), %rdi
movq -0xa8(%rbp), %rsi
movq -0xc0(%rbp), %rax
movl (%rax), %edx
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %ecx
callq 0x3150
leaq -0xa0(%rbp), %rdi
callq 0x5800
jmp 0x675e
leaq -0xa0(%rbp), %rdi
callq 0x5cb0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x920, %rsp            # imm = 0x920
popq %rbp
retq
nopw %cs:(%rax,%rax)