// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/metablobs.c
// Function: draw
static void draw(scg_image_t *draw_target, metablobs_t *metablobs) {
    scg_image_clear(draw_target, SCG_COLOR_WHITE);

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

    const float32_t origin_x = (float32_t)w / 2.0f;
    const float32_t origin_y = (float32_t)h / 2.0f;
    blob_t *blobs = metablobs->blobs;
    float32_t const_a = metablobs->const_a;
    float32_t const_b = metablobs->const_b;

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            float32_t distance_product = 1.0f;

            for (int i = 0; i < NUM_BLOBS; i++) {
                float32_t blob_x = origin_x + blobs[i].x;
                float32_t blob_y = origin_y + blobs[i].y;
                float32_t dx = (float32_t)x - blob_x;
                float32_t dy = (float32_t)y - blob_y;
                distance_product *= sqrtf((dx * dx) + (dy * dy));
            }

            float32_t result = const_b - distance_product / const_a;
            uint8_t clamped = 255 - (uint8_t)scg_clamp_float32(result, 0, 255);
            scg_pixel_t color = scg_pixel_new_rgb(clamped, clamped, clamped);

            int i = scg_pixel_index_from_xy(x, y, w);
            draw_target->pixels[i] = color.packed;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movb $-0x1, -0x14(%rbp)
movb $-0x1, -0x13(%rbp)
movb $-0x1, -0x12(%rbp)
movb $-0x1, -0x11(%rbp)
movl -0x14(%rbp), %esi
callq 0x3110
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x1c(%rbp)
cvtsi2ssl -0x18(%rbp), %xmm0
movss 0x14f4(%rip), %xmm1     # 0x8010
divss %xmm1, %xmm0
movss %xmm0, -0x20(%rbp)
cvtsi2ssl -0x1c(%rbp), %xmm0
movss 0x14de(%rip), %xmm1     # 0x8010
divss %xmm1, %xmm0
movss %xmm0, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movss 0x60(%rax), %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x10(%rbp), %rax
movss 0x64(%rax), %xmm0
movss %xmm0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x6cca
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x6cba
movss 0x147b(%rip), %xmm0     # 0x8008
movss %xmm0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
cmpl $0x3, -0x48(%rbp)
jge 0x6c35
movss -0x20(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addss (%rax), %xmm0
movss %xmm0, -0x4c(%rbp)
movss -0x24(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addss 0x4(%rax), %xmm0
movss %xmm0, -0x50(%rbp)
cvtsi2ssl -0x40(%rbp), %xmm0
subss -0x4c(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
cvtsi2ssl -0x3c(%rbp), %xmm0
subss -0x50(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0x54(%rbp), %xmm0
movss -0x54(%rbp), %xmm2
movss -0x58(%rbp), %xmm1
mulss -0x58(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
callq 0x23b0
mulss -0x44(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x6b99
movss -0x38(%rbp), %xmm0
movss -0x44(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
divss %xmm2, %xmm1
subss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0x5c(%rbp), %xmm0
xorps %xmm1, %xmm1
movss 0x13ab(%rip), %xmm2     # 0x800c
callq 0x2600
cvttss2si %xmm0, %eax
movzbl %al, %ecx
movl $0xff, %eax
subl %ecx, %eax
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
movb %al, -0x64(%rbp)
movb -0x5d(%rbp), %al
movb %al, -0x63(%rbp)
movb -0x5d(%rbp), %al
movb %al, -0x62(%rbp)
movb $-0x1, -0x61(%rbp)
movl -0x3c(%rbp), %eax
imull -0x18(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x68(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x6b79
jmp 0x6cbc
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6b66
addq $0x70, %rsp
popq %rbp
retq