// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/tunnel.c
// Function: draw
static void draw(scg_image_t *draw_target, tunnel_t *tunnel,
                 float32_t elapsed_time) {
    int w = draw_target->width;
    int h = draw_target->height;
    int image_w = tunnel->src_image->width;
    int image_h = tunnel->src_image->height;
    int shift_x = (int)floorf((float32_t)image_w * elapsed_time * 0.5f);
    int shift_y = (int)floorf((float32_t)image_h * elapsed_time * 0.25f);

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int dest_i = scg_pixel_index_from_xy(j, i, w);
            int x = (tunnel->distance_buffer[dest_i] + shift_x) % image_w;
            int y = (tunnel->angle_buffer[dest_i] + shift_y) % image_h;

            int src_i = scg_pixel_index_from_xy(x, y, image_w);
            scg_pixel_t color =
                scg_pixel_new_uint32(tunnel->src_image->pixels[src_i]);

            float32_t shade = tunnel->shade_buffer[dest_i];
            color.data.r = (uint8_t)((float32_t)color.data.r * shade);
            color.data.g = (uint8_t)((float32_t)color.data.g * shade);
            color.data.b = (uint8_t)((float32_t)color.data.b * shade);

            draw_target->pixels[dest_i] = color.packed;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movss %xmm0, -0x14(%rbp)
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
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
cvtsi2ssl -0x20(%rbp), %xmm0
mulss -0x14(%rbp), %xmm0
movss 0x55f(%rip), %xmm1      # 0x7004
mulss %xmm1, %xmm0
callq 0x20a0
cvttss2si %xmm0, %eax
movl %eax, -0x28(%rbp)
cvtsi2ssl -0x24(%rbp), %xmm0
mulss -0x14(%rbp), %xmm0
movss 0x579(%rip), %xmm1      # 0x7040
mulss %xmm1, %xmm0
callq 0x20a0
cvttss2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x6c04
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x6bf4
movl -0x30(%rbp), %eax
movl -0x18(%rbp), %ecx
imull %ecx, %eax
movl -0x34(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl -0x28(%rbp), %ecx
addl %ecx, %eax
movl -0x20(%rbp), %ecx
xorl %edx, %edx
movl %edx, -0x50(%rbp)
divl %ecx
movl %edx, %eax
movl -0x50(%rbp), %edx
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl -0x2c(%rbp), %ecx
addl %ecx, %eax
movl -0x24(%rbp), %ecx
divl %ecx
movl %edx, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl -0x20(%rbp), %ecx
imull %ecx, %eax
movl -0x3c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x38(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x4c(%rbp)
movzbl -0x46(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x4c(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, -0x46(%rbp)
movzbl -0x47(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x4c(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, -0x47(%rbp)
movzbl -0x48(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss -0x4c(%rbp), %xmm1
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movb %al, -0x48(%rbp)
movl -0x48(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x38(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6af1
jmp 0x6bf6
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x6ade
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)