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

    scg_app_t app;
    scg_app_init(&app, config);

    terrain_t terrain;
    camera_t camera;
    bool success = init(&terrain, &camera);
    if (!success) {
        return -1;
    }

    while (scg_app_process_events(&app)) {
        float32_t delta_time = app.delta_time;

        if (scg_keyboard_is_key_down(app.keyboard, SCG_KEY_UP)) {
            camera.x += -120.0f * sinf(camera.angle) * delta_time;
            camera.y += -120.0f * cosf(camera.angle) * delta_time;
        }
        if (scg_keyboard_is_key_down(app.keyboard, SCG_KEY_DOWN)) {
            camera.x += 120.0f * sinf(camera.angle) * delta_time;
            camera.y += 120.0f * cosf(camera.angle) * delta_time;
        }
        if (scg_keyboard_is_key_down(app.keyboard, SCG_KEY_LEFT)) {
            camera.angle += 1.0f * delta_time;
        }
        if (scg_keyboard_is_key_down(app.keyboard, SCG_KEY_RIGHT)) {
            camera.angle += -1.0f * delta_time;
        }
        if (scg_keyboard_is_key_down(app.keyboard, SCG_KEY_X)) {
            camera.height += -120.0f * delta_time;
        }
        if (scg_keyboard_is_key_down(app.keyboard, SCG_KEY_Z)) {
            camera.height += 120.0f * delta_time;
        }

        int map_w_period = terrain.map_w - 1;
        int map_h_period = terrain.map_h - 1;
        int map_offset = (((int)camera.y & map_w_period) << 10) +
                         ((int)camera.x & map_h_period);
        int map_height =
            scg_pixel_new_uint32(terrain.height_map->pixels[map_offset])
                .packed +
            10;
        if (map_height > camera.height) {
            camera.height = map_height;
        }

        draw(app.draw_target, terrain, camera);

        scg_app_present(&app);
    }

    scg_image_free(terrain.height_map);
    scg_image_free(terrain.color_map);
    scg_app_free(&app);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x49f0
leaq 0x1ea3(%rip), %rax      # 0x85bc
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 0x4a40
leaq -0xb8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x6ab0
andb $0x1, %al
movb %al, -0xd1(%rbp)
testb $0x1, -0xd1(%rbp)
jne 0x6773
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6aa0
jmp 0x6775
leaq -0xa0(%rbp), %rdi
callq 0x56c0
testb $0x1, %al
jne 0x678a
jmp 0x6a75
movss -0x9c(%rbp), %xmm0
movss %xmm0, -0xd8(%rbp)
movq -0x60(%rbp), %rdi
movl $0x52, %esi
callq 0x46b0
testb $0x1, %al
jne 0x67ae
jmp 0x6826
movss -0xc8(%rbp), %xmm0
callq 0x21d0
movaps %xmm0, %xmm1
movss 0x1872(%rip), %xmm0     # 0x8038
mulss %xmm1, %xmm0
movss -0xd8(%rbp), %xmm2
movss -0xd0(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xd0(%rbp)
movss -0xc8(%rbp), %xmm0
callq 0x2180
movaps %xmm0, %xmm1
movss 0x1836(%rip), %xmm0     # 0x8038
mulss %xmm1, %xmm0
movss -0xd8(%rbp), %xmm2
movss -0xcc(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xcc(%rbp)
movq -0x60(%rbp), %rdi
movl $0x51, %esi
callq 0x46b0
testb $0x1, %al
jne 0x683a
jmp 0x68b2
movss -0xc8(%rbp), %xmm0
callq 0x21d0
movaps %xmm0, %xmm1
movss 0x17ea(%rip), %xmm0     # 0x803c
mulss %xmm1, %xmm0
movss -0xd8(%rbp), %xmm2
movss -0xd0(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xd0(%rbp)
movss -0xc8(%rbp), %xmm0
callq 0x2180
movaps %xmm0, %xmm1
movss 0x17ae(%rip), %xmm0     # 0x803c
mulss %xmm1, %xmm0
movss -0xd8(%rbp), %xmm2
movss -0xcc(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xcc(%rbp)
movq -0x60(%rbp), %rdi
movl $0x50, %esi
callq 0x46b0
testb $0x1, %al
jne 0x68c6
jmp 0x68e2
movss -0xd8(%rbp), %xmm0
movss -0xc8(%rbp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0xc8(%rbp)
movq -0x60(%rbp), %rdi
movl $0x4f, %esi
callq 0x46b0
testb $0x1, %al
jne 0x68f6
jmp 0x6912
movss -0xd8(%rbp), %xmm1
movss -0xc8(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0xc8(%rbp)
movq -0x60(%rbp), %rdi
movl $0x1b, %esi
callq 0x46b0
testb $0x1, %al
jne 0x6926
jmp 0x694e
movss -0xd8(%rbp), %xmm0
movss -0xc4(%rbp), %xmm1
movss 0x16fa(%rip), %xmm2     # 0x8038
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xc4(%rbp)
movq -0x60(%rbp), %rdi
movl $0x1d, %esi
callq 0x46b0
testb $0x1, %al
jne 0x6962
jmp 0x698a
movss -0xd8(%rbp), %xmm0
movss -0xc4(%rbp), %xmm1
movss 0x16c2(%rip), %xmm2     # 0x803c
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0xc4(%rbp)
movl -0xb8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xdc(%rbp)
movl -0xb4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xe0(%rbp)
cvttss2si -0xcc(%rbp), %eax
andl -0xdc(%rbp), %eax
shll $0xa, %eax
cvttss2si -0xd0(%rbp), %ecx
andl -0xe0(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xe4(%rbp)
movq -0xa8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xe4(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %eax
addl $0xa, %eax
movl %eax, -0xe8(%rbp)
cvtsi2ssl -0xe8(%rbp), %xmm0
ucomiss -0xc4(%rbp), %xmm0
jbe 0x6a1a
cvtsi2ssl -0xe8(%rbp), %xmm0
movss %xmm0, -0xc4(%rbp)
movq -0x68(%rbp), %rdi
leaq -0xb8(%rbp), %rcx
leaq -0xd0(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0x6c70
leaq -0xa0(%rbp), %rdi
callq 0x5810
jmp 0x6775
movq -0xa8(%rbp), %rdi
callq 0x4680
movq -0xb0(%rbp), %rdi
callq 0x4680
leaq -0xa0(%rbp), %rdi
callq 0x5cc0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)