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

    scg_app_t app;
    scg_app_init(&app, config);

    const float32_t start_x = 10.0f;
    const float32_t end_x = app.draw_target->width - 64.0f;
    const float32_t duration = 3.0f;
    const bool loop = true;
    const bool yoyo = true;

    tween_example_t tween_examples[NUM_TWEENS] = {
        (tween_example_t){scg_tween_new(scg_tween_definition_new(
                              (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                              scg_tween_linear, duration, loop, yoyo)),
                          "Linear", SCG_COLOR_BLACK},
        (tween_example_t){
            scg_tween_new(scg_tween_definition_new(
                (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                scg_tween_exponential_ease_in, duration, loop, yoyo)),
            "Exponential Ease-In", SCG_COLOR_RED},
        (tween_example_t){
            scg_tween_new(scg_tween_definition_new(
                (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                scg_tween_exponential_ease_out, duration, loop, yoyo)),
            "Exponential Ease-Out", SCG_COLOR_GREEN},
        (tween_example_t){
            scg_tween_new(scg_tween_definition_new(
                (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                scg_tween_exponential_ease_in_out, duration, loop, yoyo)),
            "Exponential Ease-In-Out", SCG_COLOR_BLUE},
        (tween_example_t){scg_tween_new(scg_tween_definition_new(
                              (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                              scg_tween_elastic_ease_in, duration, loop, yoyo)),
                          "Elastic Ease-In", SCG_COLOR_BROWN},
        (tween_example_t){
            scg_tween_new(scg_tween_definition_new(
                (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                scg_tween_elastic_ease_out, duration, loop, yoyo)),
            "Elastic Ease-Out", SCG_COLOR_MAGENTA},
        (tween_example_t){
            scg_tween_new(scg_tween_definition_new(
                (scg_vec2f_t[]){scg_vec2f_new(start_x, end_x)}, 1,
                scg_tween_elastic_ease_in_out, duration, loop, yoyo)),
            "Elastic Ease-In-Out", SCG_COLOR_95_GREEN}};

    for (int i = 0; i < NUM_TWEENS; i++) {
        scg_tween_start(&tween_examples[i].tween, app.elapsed_time);
    }
    bool paused = false;

    while (scg_app_process_events(&app)) {
        if (scg_keyboard_is_key_triggered(app.keyboard, SCG_KEY_P)) {
            for (int i = 0; i < NUM_TWEENS; i++) {
                if (paused) {
                    scg_tween_resume(&tween_examples[i].tween,
                                     app.elapsed_time);
                } else {
                    for (int i = 0; i < NUM_TWEENS; i++) {
                        scg_tween_pause(&tween_examples[i].tween,
                                        app.elapsed_time);
                    }
                }
            }
            paused = !paused;
        }

        scg_image_clear(app.draw_target, SCG_COLOR_WHITE);

        const int window_size = (app.draw_target->height - 16) / NUM_TWEENS;
        int current_y = 16;
        float32_t values[1];

        for (int i = 0; i < NUM_TWEENS; i++) {
            tween_example_t *example = &tween_examples[i];

            scg_tween_update(&example->tween, values, app.elapsed_time);

            scg_image_fill_rect(app.draw_target, values[0],
                                current_y - 14 + window_size / 2, 32, 32,
                                example->color);
            scg_image_draw_string(app.draw_target, example->name, 10, current_y,
                                  false, example->color);
            scg_image_draw_line(app.draw_target, 0, current_y + 12,
                                app.draw_target->width, current_y + 12,
                                example->color);
            current_y += window_size;
        }

        const char *str = paused ? "Press P to resume" : "Press P to pause";
        int w = strlen(str) * SCG_FONT_SIZE;
        scg_image_draw_string(app.draw_target, str,
                              app.draw_target->width - w - 10, 10, false,
                              SCG_COLOR_BLACK);

        scg_app_present(&app);
    }

    scg_app_free(&app);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movabsq $0x1e000000280, %rax    # imm = 0x1E000000280
movq %rax, 0x48(%rsp)
movl $0x1, 0x58(%rsp)
xorl %eax, %eax
movb %al, 0x5c(%rsp)
movl $0x1000101, 0x5d(%rsp)  # imm = 0x1000101
movb %al, 0x64(%rsp)
movl $0x40, 0x68(%rsp)
leaq 0x1499(%rip), %rax      # 0x65ac
movq %rax, 0x50(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x48(%rsp), %xmm0
movups 0x58(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x2a0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3dc3
movq 0x38(%rbx), %rax
cvtsi2ssl (%rax), %xmm0
andl $0x0, 0x70(%rsp)
leaq 0x298(%rsp), %rsi
movq %rsi, 0x78(%rsp)
movabsq $0x140400000, %rax      # imm = 0x140400000
movq %rax, 0x80(%rsp)
movw $0x101, %cx             # imm = 0x101
movw %cx, 0x88(%rsp)
leaq -0x500(%rip), %rdx      # 0x4c84
movq %rdx, 0x90(%rsp)
andl $0x0, 0xa0(%rsp)
andl $0x0, 0x98(%rsp)
andl $0x0, 0x9b(%rsp)
leaq 0x1414(%rip), %rdx      # 0x65bf
movq %rdx, 0xa8(%rsp)
movl $0xff000000, 0xb0(%rsp) # imm = 0xFF000000
leaq 0x290(%rsp), %rdi
andl $0x0, 0xb8(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
movw %cx, 0xd0(%rsp)
leaq -0x568(%rip), %rdx      # 0x4c85
movq %rdx, 0xd8(%rsp)
andl $0x0, 0xe8(%rsp)
andl $0x0, 0xe3(%rsp)
andl $0x0, 0xe0(%rsp)
addss 0xe23(%rip), %xmm0      # 0x6038
leaq 0x13aa(%rip), %rdx      # 0x65c6
movq %rdx, 0xf0(%rsp)
movl $0xffff0000, 0xf8(%rsp) # imm = 0xFFFF0000
andl $0x0, 0x100(%rsp)
leaq 0x288(%rsp), %r8
movq %r8, 0x108(%rsp)
movq %rax, 0x110(%rsp)
movw %cx, 0x118(%rsp)
leaq -0x5b9(%rip), %rdx      # 0x4ca5
movq %rdx, 0x120(%rsp)
movl $0x41200000, %edx       # imm = 0x41200000
movl %edx, (%rsi)
andl $0x0, 0x130(%rsp)
movss %xmm0, 0x4(%rsi)
andl $0x0, 0x128(%rsp)
movl %edx, (%rdi)
andl $0x0, 0x12b(%rsp)
movss %xmm0, 0x4(%rdi)
leaq 0x1342(%rip), %rsi      # 0x65da
movq %rsi, 0x138(%rsp)
movl $0xff00ff00, 0x140(%rsp) # imm = 0xFF00FF00
leaq 0x280(%rsp), %rsi
andl $0x0, 0x148(%rsp)
movq %rsi, 0x150(%rsp)
movq %rax, 0x158(%rsp)
movw %cx, 0x160(%rsp)
leaq -0x5fd(%rip), %rdi      # 0x4cdd
movq %rdi, 0x168(%rsp)
andl $0x0, 0x178(%rsp)
movl %edx, (%r8)
andl $0x0, 0x170(%rsp)
movss %xmm0, 0x4(%r8)
andl $0x0, 0x173(%rsp)
leaq 0x12e5(%rip), %rdi      # 0x65ef
movq %rdi, 0x180(%rsp)
movl $0xff0000ff, 0x188(%rsp) # imm = 0xFF0000FF
leaq 0x278(%rsp), %rdi
andl $0x0, 0x190(%rsp)
movq %rdi, 0x198(%rsp)
movq %rax, 0x1a0(%rsp)
movw %cx, 0x1a8(%rsp)
leaq -0x606(%rip), %r8       # 0x4d46
movq %r8, 0x1b0(%rsp)
movl %edx, (%rsi)
andl $0x0, 0x1c0(%rsp)
movss %xmm0, 0x4(%rsi)
andl $0x0, 0x1bb(%rsp)
movl %edx, (%rdi)
andl $0x0, 0x1b8(%rsp)
movss %xmm0, 0x4(%rdi)
leaq 0x1286(%rip), %rsi      # 0x6607
movq %rsi, 0x1c8(%rsp)
movl $0xff964b00, 0x1d0(%rsp) # imm = 0xFF964B00
leaq 0x270(%rsp), %rsi
andl $0x0, 0x1d8(%rsp)
movq %rsi, 0x1e0(%rsp)
movq %rax, 0x1e8(%rsp)
movw %cx, 0x1f0(%rsp)
leaq -0x603(%rip), %rdi      # 0x4dc0
movq %rdi, 0x1f8(%rsp)
andl $0x0, 0x208(%rsp)
movl %edx, (%rsi)
andl $0x0, 0x203(%rsp)
movss %xmm0, 0x4(%rsi)
andl $0x0, 0x200(%rsp)
leaq 0x1226(%rip), %rsi      # 0x6617
movq %rsi, 0x210(%rsp)
movl $0xffff00ff, 0x218(%rsp) # imm = 0xFFFF00FF
leaq 0x268(%rsp), %rsi
movl %edx, (%rsi)
andl $0x0, 0x220(%rsp)
movq %rsi, 0x228(%rsp)
movq %rax, 0x230(%rsp)
movw %cx, 0x238(%rsp)
leaq -0x609(%rip), %rax      # 0x4e2c
movq %rax, 0x240(%rsp)
andl $0x0, 0x250(%rsp)
movss %xmm0, 0x4(%rsi)
andl $0x0, 0x24b(%rsp)
andl $0x0, 0x248(%rsp)
leaq 0x11c7(%rip), %rax      # 0x6628
movq %rax, 0x258(%rsp)
movl $0xff008080, 0x260(%rsp) # imm = 0xFF008080
pushq $0x30
popq %rax
movss 0x8(%rbx), %xmm0
cmpq $0x228, %rax            # imm = 0x228
je 0x54a8
cmpb $0x0, 0x6c(%rsp,%rax)
jne 0x54a2
movw $0x1, 0x6c(%rsp,%rax)
movss %xmm0, 0x68(%rsp,%rax)
andl $0x0, 0x70(%rsp,%rax)
movb $0x0, 0x6e(%rsp,%rax)
addq $0x48, %rax
jmp 0x547c
xorl %r14d, %r14d
leaq 0x2a0(%rsp), %rbx
movq %rbx, %rdi
callq 0x4858
testb %al, %al
je 0x5694
movq 0x2e0(%rsp), %rax
cmpb $0x0, 0x213(%rax)
je 0x54ed
movq %r14, 0x38(%rsp)
movss 0x2a8(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
jmp 0x5570
movss 0x2a8(%rsp), %xmm0
movss %xmm0, 0x34(%rsp)
cmpb $0x1, 0x13(%rax)
jne 0x556b
xorl %ebx, %ebx
cmpq $0x7, %rbx
je 0x5567
testb $0x1, %r14b
je 0x552c
imulq $0x48, %rbx, %rax
leaq (%rsp,%rax), %rdi
addq $0x70, %rdi
movss 0x34(%rsp), %xmm0
callq 0x50a6
incq %rbx
jmp 0x5504
xorl %eax, %eax
cmpq $0x1f8, %rax            # imm = 0x1F8
je 0x5527
cmpb $0x1, 0x9c(%rsp,%rax)
jne 0x5561
cmpb $0x0, 0x9d(%rsp,%rax)
jne 0x5561
movb $0x1, 0x9d(%rsp,%rax)
movss 0x34(%rsp), %xmm0
movss %xmm0, 0xa0(%rsp,%rax)
addq $0x48, %rax
jmp 0x552e
xorb $0x1, %r14b
movq %r14, 0x38(%rsp)
movq 0x2d8(%rsp), %r13
movq %r13, %rdi
pushq $-0x1
popq %rsi
callq 0x2c56
movl 0x4(%r13), %ecx
addl $-0x10, %ecx
movl %ecx, %eax
cltd
pushq $0x7
popq %rsi
idivl %esi
movl %eax, 0x40(%rsp)
movl %ecx, %eax
cltd
pushq $0xe
popq %rcx
idivl %ecx
movl %eax, %ebx
addl $0x2, %ebx
pushq $0x1c
popq %rax
movl %eax, %r15d
xorl %ebp, %ebp
cmpq $0x1f8, %rbp            # imm = 0x1F8
je 0x5638
leal -0xc(%r15), %r14d
leaq (%rsp,%rbp), %r12
addq $0x70, %r12
movq %r12, %rdi
leaq 0x44(%rsp), %rsi
movss 0x34(%rsp), %xmm0
callq 0x4f2c
cvttss2si 0x44(%rsp), %esi
movl 0x40(%r12), %r9d
movq %r13, %rdi
movl %ebx, %edx
pushq $0x20
popq %rcx
movl %ecx, %r8d
callq 0x3473
movq 0x38(%r12), %rsi
movl 0x40(%r12), %r9d
movq %r13, %rdi
pushq $0xa
popq %rdx
movl %r14d, %ecx
xorl %r8d, %r8d
callq 0x38fd
movl (%r13), %ecx
movl 0x40(%r12), %r9d
movq %r13, %rdi
xorl %esi, %esi
movl %r15d, %edx
movl %r15d, %r8d
callq 0x32b6
addq $0x48, %rbp
movl 0x40(%rsp), %eax
addl %eax, %ebx
addl %eax, %r15d
jmp 0x55ab
movq 0x38(%rsp), %r14
testb $0x1, %r14b
leaq 0x1006(%rip), %rsi      # 0x664e
leaq 0xfed(%rip), %rax       # 0x663c
cmovneq %rax, %rsi
movl (%r13), %eax
movl %r14d, %ecx
notb %cl
movzbl %cl, %ecx
andl $0x1, %ecx
leal (%rax,%rcx,8), %edx
addl $0xffffff6e, %edx       # imm = 0xFFFFFF6E
movq %r13, %rdi
pushq $0xa
popq %rcx
xorl %r8d, %r8d
movl $0xff000000, %r9d       # imm = 0xFF000000
callq 0x38fd
leaq 0x2a0(%rsp), %rbx
movq %rbx, %rdi
callq 0x491f
jmp 0x54b3
leaq 0x2a0(%rsp), %rdi
callq 0x4bf7
xorl %eax, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq