// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/tunnel.c
// Function: init
static void init(scg_app_t *app, tunnel_t *tunnel, scg_image_t *src_image) {
    int w = app->draw_target->width;
    int h = app->draw_target->height;

    uint32_t *distance_buffer = malloc(w * h * sizeof(*distance_buffer));
    uint32_t *angle_buffer = malloc(w * h * sizeof(*angle_buffer));
    float32_t *shade_buffer = malloc(w * h * sizeof(*shade_buffer));

    int image_w = src_image->width;
    int image_h = src_image->height;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int i = scg_pixel_index_from_xy(x, y, w);
            float32_t dx = x - w / 2;
            float32_t dy = y - h / 2;
            float32_t dist = sqrtf(dx * dx + dy * dy);

            distance_buffer[i] =
                (uint32_t)(32.0f * (float32_t)image_h / dist) % image_h;
            angle_buffer[i] =
                (uint32_t)(0.5f * (float32_t)image_w * atan2f(dy, dx) / SCG_PI);
            shade_buffer[i] = scg_min_float32(16.0f + dist, 255.0f) / 255.0f;
        }
    }

    tunnel->distance_buffer = distance_buffer;
    tunnel->angle_buffer = angle_buffer;
    tunnel->shade_buffer = shade_buffer;
    tunnel->src_image = src_image;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2300
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2300
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
imull -0x20(%rbp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2300
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x6a12
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x6a02
movl -0x44(%rbp), %eax
movl -0x1c(%rbp), %ecx
imull %ecx, %eax
movl -0x48(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
movl -0x1c(%rbp), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %edx, %ecx
sarl %ecx
subl %ecx, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x50(%rbp)
movl -0x44(%rbp), %eax
movl -0x20(%rbp), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %edx, %ecx
sarl %ecx
subl %ecx, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x54(%rbp), %xmm1
mulss %xmm1, %xmm1
mulss %xmm0, %xmm0
addss %xmm1, %xmm0
callq 0x23d0
movss %xmm0, -0x58(%rbp)
movl -0x40(%rbp), %ecx
cvtsi2ss %ecx, %xmm0
movss 0x6eb(%rip), %xmm1      # 0x703c
mulss %xmm1, %xmm0
movss -0x58(%rbp), %xmm1
divss %xmm1, %xmm0
cvttss2si %xmm0, %rax
xorl %edx, %edx
divl %ecx
movq -0x28(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
cvtsi2ssl -0x3c(%rbp), %xmm0
movss 0x685(%rip), %xmm1      # 0x7004
mulss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x54(%rbp), %xmm0
movss -0x50(%rbp), %xmm1
callq 0x2320
movaps %xmm0, %xmm1
movss -0x5c(%rbp), %xmm0
mulss %xmm1, %xmm0
movss 0x67d(%rip), %xmm1      # 0x7028
divss %xmm1, %xmm0
cvttss2si %xmm0, %rax
movl %eax, %edx
movq -0x30(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movss 0x66f(%rip), %xmm0      # 0x7038
addss -0x58(%rbp), %xmm0
movss 0x636(%rip), %xmm1      # 0x700c
callq 0x2580
movss 0x629(%rip), %xmm1      # 0x700c
divss %xmm1, %xmm0
movq -0x38(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x68d1
jmp 0x6a04
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x68be
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)