// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/starfield_3d.c
// Function: draw
static void draw(scg_image_t *draw_target, starfield_t *starfield) {
    scg_image_clear(draw_target, SCG_COLOR_BLACK);

    int w = draw_target->width;
    int h = draw_target->height;
    int num_stars = starfield->num_stars;

    for (int i = 0; i < num_stars; i++) {
        scg_pixel_t star_color = SCG_COLOR_WHITE;
        star_t *current = &starfield->stars[i];

        float32_t shade =
            scg_max_float32(1.0f - current->z / starfield->max_distance, 0.0f);

        star_color.data.r = (uint8_t)((float32_t)star_color.data.r * shade);
        star_color.data.g = (uint8_t)((float32_t)star_color.data.g * shade);
        star_color.data.b = (uint8_t)((float32_t)star_color.data.b * shade);

        float32_t z = scg_max_float32(current->z, 1.0f);
        float32_t x = (current->x * starfield->horizontal_view_distance) / z;
        x += (float32_t)w / 2.0f;
        float32_t y = (float32_t)h / 2.0f -
                      ((current->y * starfield->vertical_view_distance) / z);

        scg_image_set_pixel(draw_target, (int)x, (int)y, star_color);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movb $0x0, -0x14(%rbp)
movb $0x0, -0x13(%rbp)
movb $0x0, -0x12(%rbp)
movb $-0x1, -0x11(%rbp)
movl -0x14(%rbp), %esi
callq 0x3130
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6d36
movl $0xffffffff, -0x28(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x24(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movss 0x8(%rax), %xmm1
movq -0x10(%rbp), %rax
movss 0x14(%rax), %xmm0
divss %xmm0, %xmm1
movss 0x13d1(%rip), %xmm0     # 0x8008
subss %xmm1, %xmm0
xorps %xmm1, %xmm1
callq 0x25c0
movss %xmm0, -0x34(%rbp)
movzbl -0x26(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x34(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, -0x26(%rbp)
movzbl -0x27(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x34(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, -0x27(%rbp)
movzbl -0x28(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x34(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, -0x28(%rbp)
movq -0x30(%rbp), %rax
movss 0x8(%rax), %xmm0
movss 0x1367(%rip), %xmm1     # 0x8008
callq 0x25c0
movss %xmm0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movss (%rax), %xmm0
movq -0x10(%rbp), %rax
mulss 0x1c(%rax), %xmm0
divss -0x38(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
cvtsi2ssl -0x18(%rbp), %xmm0
movss 0x133d(%rip), %xmm1     # 0x8010
divss %xmm1, %xmm0
addss -0x3c(%rbp), %xmm0
movss %xmm0, -0x3c(%rbp)
cvtsi2ssl -0x1c(%rbp), %xmm0
movss 0x1322(%rip), %xmm1     # 0x8010
divss %xmm1, %xmm0
movq -0x30(%rbp), %rax
movss 0x4(%rax), %xmm1
movq -0x10(%rbp), %rax
mulss 0x20(%rax), %xmm1
divss -0x38(%rbp), %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
cvttss2si -0x3c(%rbp), %esi
cvttss2si -0x40(%rbp), %edx
movl -0x28(%rbp), %ecx
callq 0x2f90
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6bef
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)