// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movabsq $0x1e000000280, %rax    # imm = 0x1E000000280
movq %rax, 0x80(%rsp)
movl $0x1, 0x90(%rsp)
xorl %eax, %eax
movb %al, 0x94(%rsp)
movl $0x1010101, 0x95(%rsp) # imm = 0x1010101
movb %al, 0x9c(%rsp)
movl $0x40, 0xa0(%rsp)
leaq 0x109e(%rip), %rax      # 0x65cc
movq %rax, 0x88(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0x80(%rsp), %xmm0
movups 0x90(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x3e81
leaq 0x1c68(%rip), %rdi      # 0x71d8
callq 0x2925
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x58e3
movq %rax, %rbx
leaq 0x1c60(%rip), %rdi      # 0x71ed
callq 0x2925
testq %rax, %rax
je 0x58e3
movl (%rax), %ecx
cmpl %ecx, (%rbx)
jne 0x58b8
movl 0x4(%rax), %edx
cmpl %edx, 0x4(%rbx)
jne 0x58b8
testl %edx, %edx
jle 0x55ed
leaq (,%rcx,4), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
testl %ecx, %ecx
jle 0x55e2
movq 0x10(%rax), %r9
addq %rdi, %r9
xorl %r10d, %r10d
movzbl 0x2(%r9,%r10,4), %r11d
movl %r11d, (%r9,%r10,4)
incq %r10
cmpq %r10, %rcx
jne 0x55d0
incq %r8
addq %rsi, %rdi
cmpq %rdx, %r8
jne 0x55c2
movl %ecx, 0x68(%rsp)
movl %edx, 0x6c(%rsp)
movq %rbx, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movaps 0xa8a(%rip), %xmm0      # 0x6090
movups %xmm0, 0x50(%rsp)
movabsq $0x43c8000042f00000, %rax # imm = 0x43C8000042F00000
movq %rax, 0x60(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x49dc
testb %al, %al
je 0x587b
movss 0xa01(%rip), %xmm0      # 0x6038
movss %xmm0, 0x44(%rsp)
movl $0x3fffff, %ebp         # imm = 0x3FFFFF
addl 0x68(%rsp), %ebp
movl 0x6c(%rsp), %r14d
decl %r14d
movq 0x78(%rsp), %r15
movss 0x54(%rsp), %xmm0
movss %xmm0, 0x40(%rsp)
movss 0x58(%rsp), %xmm0
movss %xmm0, 0x3c(%rsp)
movss 0x5c(%rsp), %xmm0
leaq 0xa8(%rsp), %rbx
movss 0xac(%rsp), %xmm2
movq 0xe8(%rsp), %r12
cmpb $0x1, 0x52(%r12)
movss %xmm0, 0x4c(%rsp)
movss %xmm2, 0x48(%rsp)
jne 0x5704
movss 0x3c(%rsp), %xmm0
callq 0x21d0
movss 0x98b(%rip), %xmm1      # 0x603c
mulss %xmm1, %xmm0
mulss 0x48(%rsp), %xmm0
movss 0x44(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x44(%rsp)
movss %xmm1, 0x50(%rsp)
movss 0x3c(%rsp), %xmm0
callq 0x2180
movss 0x48(%rsp), %xmm2
mulss 0x952(%rip), %xmm0      # 0x603c
mulss %xmm2, %xmm0
movss 0x40(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x40(%rsp)
movss %xmm1, 0x54(%rsp)
cmpb $0x1, 0x51(%r12)
jne 0x5772
movss 0x3c(%rsp), %xmm0
callq 0x21d0
movss 0x921(%rip), %xmm1      # 0x6040
mulss %xmm1, %xmm0
mulss 0x48(%rsp), %xmm0
movss 0x44(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x44(%rsp)
movss %xmm1, 0x50(%rsp)
movss 0x3c(%rsp), %xmm0
callq 0x2180
movss 0x48(%rsp), %xmm2
mulss 0x8e8(%rip), %xmm0      # 0x6040
mulss %xmm2, %xmm0
movss 0x40(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x40(%rsp)
movss %xmm1, 0x54(%rsp)
movss 0x4c(%rsp), %xmm1
cmpb $0x1, 0x50(%r12)
jne 0x5796
movss 0x3c(%rsp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0x3c(%rsp)
movss %xmm0, 0x58(%rsp)
cmpb $0x1, 0x4f(%r12)
jne 0x57b4
movss 0x3c(%rsp), %xmm0
subss %xmm2, %xmm0
movss %xmm0, 0x3c(%rsp)
movss %xmm0, 0x58(%rsp)
cmpb $0x1, 0x1b(%r12)
jne 0x57d1
movaps %xmm2, %xmm0
mulss 0x875(%rip), %xmm0      # 0x603c
addss %xmm0, %xmm1
movss %xmm1, 0x5c(%rsp)
cmpb $0x1, 0x1d(%r12)
jne 0x57eb
mulss 0x85f(%rip), %xmm2      # 0x6040
addss %xmm2, %xmm1
movss %xmm1, 0x5c(%rsp)
cvttss2si 0x40(%rsp), %eax
andl %ebp, %eax
shll $0xa, %eax
cvttss2si 0x44(%rsp), %ecx
andl %r14d, %ecx
addl %eax, %ecx
movq 0x10(%r15), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addl $0xa, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x5823
movss %xmm0, 0x5c(%rsp)
movaps %xmm0, %xmm1
movss %xmm1, 0x4c(%rsp)
movq 0xe0(%rsp), %rdi
movq 0x60(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x50(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x68(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x58f5
movq %rbx, %rdi
callq 0x4b28
movq %rbx, %rdi
callq 0x49dc
movss 0x4c(%rsp), %xmm0
testb %al, %al
jne 0x5679
movq 0x78(%rsp), %rbx
movq 0x10(%rbx), %rdi
callq 0x2290
movq %rbx, %rdi
callq 0x2290
movq 0x70(%rsp), %rbx
movq 0x10(%rbx), %rdi
callq 0x2290
movq %rbx, %rdi
callq 0x2290
leaq 0xa8(%rsp), %rdi
callq 0x4ff7
xorl %ebp, %ebp
jmp 0x58e3
leaq 0x811(%rip), %rsi       # 0x60d0
leaq 0xb2a(%rip), %rdx       # 0x63f0
leaq 0x1936(%rip), %rcx      # 0x7203
leaq 0x1946(%rip), %r9       # 0x721a
xorl %edi, %edi
movl $0x27, %r8d
xorl %eax, %eax
callq 0x22e0
movl %ebp, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq