// File: /workspace/github_c_makefile_star2_O1/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 0x107e(%rip), %rax      # 0x659c
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 0x3e81
leaq 0x105e(%rip), %rdi      # 0x65af
callq 0x2925
testq %rax, %rax
je 0x56c6
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x49dc
testb %al, %al
je 0x56b8
leaq 0xc0(%rsp), %r12
movq 0x90(%rsp), %r14
movl 0x4(%r14), %ecx
imull (%r14), %ecx
testl %ecx, %ecx
jle 0x55a7
movq 0x10(%r14), %rax
movl %ecx, %ecx
xorl %edx, %edx
movl $0xff0000ff, (%rax,%rdx,4) # imm = 0xFF0000FF
incq %rdx
cmpq %rdx, %rcx
jne 0x5598
movq 0xa0(%rsp), %rbp
movl (%r14), %eax
movl 0x4(%r14), %ecx
movl %eax, %r15d
shrl $0x1f, %r15d
addl %eax, %r15d
sarl %r15d
movl %ecx, %r13d
shrl $0x1f, %r13d
addl %ecx, %r13d
sarl %r13d
movl $0x0, 0x18(%r14)
leal -0x20(%r13), %ecx
movq %r14, %rdi
leaq 0xfe1(%rip), %rsi       # 0x65c7
movl %r15d, %edx
movl $0x1, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x3977
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
movl 0x8(%rbp), %r8d
movl 0xc(%rbp), %r9d
movq %r12, %rdi
leaq 0xfc1(%rip), %rsi       # 0x65d3
xorl %eax, %eax
callq 0x25f2
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movl %r13d, %ecx
movl $0x1, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x3977
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 %r12, %rdi
leaq 0xf9c(%rip), %rsi       # 0x65f6
xorl %eax, %eax
callq 0x25f2
addl $0x10, %r13d
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
movl %r13d, %ecx
movl $0x1, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x3977
movl $0x2, 0x18(%r14)
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2cb0
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x4b28
movq %r14, %rdi
callq 0x49dc
testb %al, %al
jne 0x557c
leaq 0x58(%rsp), %rdi
callq 0x4ff7
xorl %eax, %eax
jmp 0x56cb
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq