// File: /workspace/github_c_makefile_star2_O3/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 0x1067(%rip), %rax      # 0x65dc
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movdqu 0x30(%rsp), %xmm0
movdqu 0x40(%rsp), %xmm1
movdqu %xmm1, 0x10(%rsp)
movdqu %xmm0, (%rsp)
leaq 0x58(%rsp), %rdi
callq 0x3f6d
leaq 0x1043(%rip), %rdi      # 0x65ef
callq 0x2925
testq %rax, %rax
je 0x581e
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x4a46
testb %al, %al
je 0x5810
movdqa 0xaa9(%rip), %xmm6      # 0x6080
movdqa 0xab0(%rip), %xmm8      # 0x6090
leaq 0xc0(%rsp), %r12
movq 0x90(%rsp), %r14
movl (%r14), %edx
movl 0x4(%r14), %ecx
movl %ecx, %eax
imull %edx, %eax
testl %eax, %eax
jle 0x56f5
movq 0x10(%r14), %rcx
movl %eax, %edx
addl $0x3, %eax
andl $-0x4, %eax
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
pxor %xmm6, %xmm0
xorl %edx, %edx
movdqa 0xa45(%rip), %xmm1      # 0x6070
movdqa 0xa2d(%rip), %xmm2      # 0x6060
pcmpeqd %xmm7, %xmm7
movdqa %xmm1, %xmm3
pxor %xmm6, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm3
pshufd $0xf5, %xmm3, %xmm5     # xmm5 = xmm3[1,1,3,3]
pand %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm5, %xmm3
movd %xmm3, %esi
notl %esi
testb $0x1, %sil
je 0x5670
movl $0xff0000ff, (%rcx,%rdx,4) # imm = 0xFF0000FF
pxor %xmm7, %xmm3
pextrw $0x4, %xmm3, %esi
testb $0x1, %sil
je 0x5687
movl $0xff0000ff, 0x4(%rcx,%rdx,4) # imm = 0xFF0000FF
movdqa %xmm2, %xmm3
pxor %xmm6, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm3
pshufd $0xf5, %xmm3, %xmm5     # xmm5 = xmm3[1,1,3,3]
pand %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm5, %xmm3
pxor %xmm7, %xmm3
pextrw $0x0, %xmm3, %esi
testb $0x1, %sil
je 0x56c4
movl $0xff0000ff, 0x8(%rcx,%rdx,4) # imm = 0xFF0000FF
pextrw $0x4, %xmm3, %esi
testb $0x1, %sil
je 0x56d7
movl $0xff0000ff, 0xc(%rcx,%rdx,4) # imm = 0xFF0000FF
addq $0x4, %rdx
paddq %xmm8, %xmm1
paddq %xmm8, %xmm2
cmpq %rdx, %rax
jne 0x5637
movl (%r14), %edx
movl 0x4(%r14), %ecx
movq 0xa0(%rsp), %rbp
movl %edx, %r15d
shrl $0x1f, %r15d
addl %edx, %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 0xeda(%rip), %rsi       # 0x6607
movl %r15d, %edx
movl $0x1, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x3a63
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
movl 0x8(%rbp), %r8d
movl 0xc(%rbp), %r9d
movq %r12, %rdi
leaq 0xeba(%rip), %rsi       # 0x6613
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 0x3a63
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 0xe95(%rip), %rsi       # 0x6636
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 0x3a63
movl $0x2, 0x18(%r14)
movl (%rbp), %edx
movl 0x4(%rbp), %ecx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2d74
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x4b6f
movq %r14, %rdi
callq 0x4a46
movdqa 0x890(%rip), %xmm8      # 0x6090
movdqa 0x878(%rip), %xmm6      # 0x6080
testb %al, %al
jne 0x55e8
leaq 0x58(%rsp), %rdi
callq 0x5042
xorl %eax, %eax
jmp 0x5823
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq