// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/voxel_space.c
// Function: draw
static void draw(scg_image_t *draw_target, terrain_t terrain, camera_t camera) {
    scg_image_clear(draw_target, SCG_COLOR_WHITE);

    int w = draw_target->width;
    int h = draw_target->height;
    int map_w_period = terrain.map_w - 1;
    int map_h_period = terrain.map_h - 1;

    float32_t s = sinf(camera.angle);
    float32_t c = cosf(camera.angle);

    float32_t ybuffer[w];
    for (int x = 0; x < w; x++) {
        ybuffer[x] = h;
    }

    float32_t dt = 1.0f;
    float32_t inv_max_distance = 1.0f / camera.max_distance;

    for (float32_t z = 1; z < camera.max_distance; z += dt) {
        float32_t pleft_x = -c * z - s * z;
        float32_t pleft_y = s * z - c * z;
        float32_t pright_x = c * z - s * z;
        float32_t pright_y = -s * z - c * z;

        float32_t dx = (pright_x - pleft_x) / (float32_t)w;
        float32_t dy = (pright_y - pleft_y) / (float32_t)w;
        pleft_x += camera.x;
        pleft_y += camera.y;
        float32_t invz = 1.0f / z * 240.0f;

        float32_t fog = fog_factor(z * inv_max_distance, 2.2f);

        for (int x = 0; x < w; x++) {
            int i = (((int)pleft_y & map_w_period) << 10) +
                    ((int)pleft_x & map_h_period);

            scg_pixel_t color_map_pixel =
                scg_pixel_new_uint32(terrain.color_map->pixels[i]);
            scg_pixel_t height_map_pixel =
                scg_pixel_new_uint32(terrain.height_map->pixels[i]);

            color_map_pixel = shade_pixel(color_map_pixel, fog);

            float32_t height_on_screen =
                (camera.height - height_map_pixel.packed) * invz +
                camera.horizon;
            draw_vertical_line(draw_target, x, height_on_screen, ybuffer[x],
                               color_map_pixel);

            if (height_on_screen < ybuffer[x]) {
                ybuffer[x] = height_on_screen;
            }

            pleft_x += dx;
            pleft_y += dy;
        }

        dt += 0.01f;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
leaq 0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movb $-0x1, -0xc(%rbp)
movb $-0x1, -0xb(%rbp)
movb $-0x1, -0xa(%rbp)
movb $-0x1, -0x9(%rbp)
movl -0xc(%rbp), %esi
callq 0x3110
movq -0x98(%rbp), %rcx
movq -0x90(%rbp), %rax
movq -0x8(%rbp), %rdx
movl (%rdx), %edx
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rdx
movl 0x4(%rdx), %edx
movl %edx, -0x14(%rbp)
movl (%rcx), %edx
decl %edx
movl %edx, -0x18(%rbp)
movl 0x4(%rcx), %ecx
decl %ecx
movl %ecx, -0x1c(%rbp)
movss 0x8(%rax), %xmm0
callq 0x21d0
movq -0x90(%rbp), %rax
movss %xmm0, -0x20(%rbp)
movss 0x8(%rax), %xmm0
callq 0x2180
movss %xmm0, -0x24(%rbp)
movl -0x10(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x6d5f
movq -0x88(%rbp), %rax
cvtsi2ssl -0x14(%rbp), %xmm0
movslq -0x3c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6d37
movq -0x90(%rbp), %rax
movss 0x129a(%rip), %xmm0     # 0x8008
movss %xmm0, -0x40(%rbp)
movss 0x128d(%rip), %xmm0     # 0x8008
divss 0x14(%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movss 0x127b(%rip), %xmm0     # 0x8008
movss %xmm0, -0x48(%rbp)
movq -0x90(%rbp), %rax
movss -0x48(%rbp), %xmm1
movss 0x14(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x7059
movq -0x90(%rbp), %rax
movss -0x24(%rbp), %xmm0
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
movss -0x48(%rbp), %xmm2
movss -0x20(%rbp), %xmm1
mulss -0x48(%rbp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x20(%rbp), %xmm0
movss -0x48(%rbp), %xmm2
movss -0x24(%rbp), %xmm1
mulss -0x48(%rbp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x24(%rbp), %xmm0
movss -0x48(%rbp), %xmm2
movss -0x20(%rbp), %xmm1
mulss -0x48(%rbp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x20(%rbp), %xmm0
movd %xmm0, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm0
movss -0x48(%rbp), %xmm2
movss -0x24(%rbp), %xmm1
mulss -0x48(%rbp), %xmm1
movd %xmm1, %ecx
xorl $0x80000000, %ecx       # imm = 0x80000000
movd %ecx, %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x54(%rbp), %xmm0
subss -0x4c(%rbp), %xmm0
cvtsi2ssl -0x10(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x58(%rbp), %xmm0
subss -0x50(%rbp), %xmm0
cvtsi2ssl -0x10(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x60(%rbp)
movss (%rax), %xmm0
addss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss 0x4(%rax), %xmm0
addss -0x50(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movss 0x1128(%rip), %xmm0     # 0x8008
divss -0x48(%rbp), %xmm0
movss 0x1167(%rip), %xmm1     # 0x8054
mulss %xmm1, %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x48(%rbp), %xmm0
mulss -0x44(%rbp), %xmm0
movss 0x1148(%rip), %xmm1     # 0x8050
callq 0x7340
movss %xmm0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x7033
movq -0x98(%rbp), %rax
cvttss2si -0x50(%rbp), %ecx
movl -0x18(%rbp), %edx
andl %edx, %ecx
shll $0xa, %ecx
cvttss2si -0x4c(%rbp), %edx
movl -0x1c(%rbp), %esi
andl %esi, %edx
addl %edx, %ecx
movl %ecx, -0x70(%rbp)
movq 0x8(%rax), %rcx
movq 0x10(%rcx), %rcx
movslq -0x70(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x74(%rbp)
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x70(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x78(%rbp)
movss -0x68(%rbp), %xmm0
movl -0x74(%rbp), %edi
callq 0x73b0
movq -0x90(%rbp), %rcx
movl %eax, %edx
movq -0x88(%rbp), %rax
movl %edx, -0x7c(%rbp)
movl -0x7c(%rbp), %edx
movl %edx, -0x74(%rbp)
movss 0xc(%rcx), %xmm0
movl -0x78(%rbp), %edx
cvtsi2ss %rdx, %xmm1
subss %xmm1, %xmm0
movss -0x64(%rbp), %xmm2
movss 0x10(%rcx), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movl -0x6c(%rbp), %esi
cvttss2si -0x80(%rbp), %edx
movslq -0x6c(%rbp), %rcx
cvttss2si (%rax,%rcx,4), %ecx
movl -0x74(%rbp), %r8d
callq 0x7470
movq -0x88(%rbp), %rax
movss -0x80(%rbp), %xmm1
movslq -0x6c(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x7007
movq -0x88(%rbp), %rax
movss -0x80(%rbp), %xmm0
movslq -0x6c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movss -0x5c(%rbp), %xmm0
addss -0x4c(%rbp), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x60(%rbp), %xmm0
addss -0x50(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x6f19
movss 0x101d(%rip), %xmm0     # 0x8058
addss -0x40(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
movss -0x40(%rbp), %xmm0
addss -0x48(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
jmp 0x6d92
movq -0x30(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)