// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4c8, %rsp            # imm = 0x4C8
movabsq $0x1e000000280, %rax    # imm = 0x1E000000280
movq %rax, 0x30(%rsp)
movl $0x1, 0x40(%rsp)
xorl %eax, %eax
movb %al, 0x44(%rsp)
movl $0x1010101, 0x45(%rsp)  # imm = 0x1010101
movb %al, 0x4c(%rsp)
movl $0x40, 0x50(%rsp)
leaq 0x1499(%rip), %rax      # 0x65ac
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x30(%rsp), %xmm0
movups 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x58(%rsp), %rdi
callq 0x3dc3
leaq 0x1479(%rip), %rdi      # 0x65bf
callq 0x2911
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x5286
leaq 0x58(%rsp), %rbx
pushq $-0x1
popq %r12
movq %rbx, %rdi
callq 0x4858
testb %al, %al
je 0x5278
movq 0x90(%rsp), %r13
movq %r13, %rdi
movl $0xff0000ff, %esi       # imm = 0xFF0000FF
callq 0x2c56
movq 0xa0(%rsp), %rbp
movl (%r13), %eax
movl 0x4(%r13), %ecx
cltd
pushq $0x2
popq %rsi
idivl %esi
movl %eax, %r14d
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %ebx
andl $0x0, 0x18(%r13)
leal -0x20(%rbx), %ecx
movq %r13, %rdi
leaq 0x141e(%rip), %rsi      # 0x65d7
movl %r14d, %edx
pushq $0x1
popq %r8
movl %r12d, %r9d
callq 0x38fd
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
movl 0x8(%rbp), %r8d
movl 0xc(%rbp), %r9d
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
leaq 0x13fb(%rip), %rsi      # 0x65e3
xorl %eax, %eax
callq 0x25f2
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %edx
movl %ebx, %ecx
pushq $0x1
popq %r8
movl %r12d, %r9d
callq 0x38fd
movl 0x10(%rbp), %r8d
movl %r8d, %edx
andl $0x1, %edx
movl %r8d, %ecx
shrl $0x2, %ecx
andl $0x1, %ecx
shrl %r8d
andl $0x1, %r8d
movq %r15, %rdi
leaq 0x13dc(%rip), %rsi      # 0x6606
xorl %eax, %eax
callq 0x25f2
addl $0x10, %ebx
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %edx
movl %ebx, %ecx
leaq 0x58(%rsp), %rbx
pushq $0x1
popq %r8
movl %r12d, %r9d
callq 0x38fd
movl $0x2, 0x18(%r13)
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
movq %r13, %rdi
movq 0x28(%rsp), %rsi
callq 0x2c75
movq %rbx, %rdi
callq 0x491f
jmp 0x5162
leaq 0x58(%rsp), %rdi
callq 0x4bf7
xorl %eax, %eax
jmp 0x5289
pushq $-0x1
popq %rax
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq