// File: Erkaman[P]spiky-anim/main.cpp
// Function: makeSpiky(_IO_FILE*, float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void makeSpiky(FILE* fp, float rad, string color) {
    int N = 24;

    // spiky center in image center.
    float PX = WIDTH/2;
    float PY = HEIGHT/2;

    vector<vec2> pos(N);

    float SMALLR = rad * 0.20f;
    float R1 = rad - SMALLR;
    float R2 = rad + SMALLR;

    // generate points on circle. But displace the points in direction of normal.
    // so that it becomes spiky.
    for(int i = 0; i < N; i++) {
        float theta = (i / (float)N) * 2.0 * PI;

        float R = i % 2 == 0 ? R1 : R2;

        pos[i].x = PX + R * cos(theta);
        pos[i].y = PY + R * sin(theta);
    }

    string str;

    // now make line paths between the generated points.
    for(int i = 0; i < (N+1); i++) {
        vec2 v = pos[(i) % N];

        if(i == 0) {
            // for first point, we just position the cursor.
            str += "<path d=\"M" + to_string(v.x) + ", " + to_string(v.y);
        } else {
            str += "L " +     to_string(v.x) + " " + to_string(v.y) + " ";
        }
    }

    str += "Z\n"; // close loop. path is now done.
    str += "\" />";

    float strokeWidth = 2.0f + 10.0f * (rad / 100.0f);
    if(strokeWidth > 8.0f) { // clamp stroke-width to max 8.0f
        strokeWidth = 8.0f;
    }

    fprintf(fp,"<g fill=\"none\" stroke=\"%s\"  stroke-width=\"%f\" fill-opacity=\"1.0\">", color.c_str(), strokeWidth);
    fprintf(fp,"%s", str.c_str() );

    fprintf(fp,"</g>");

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rsi, -0x220(%rbp)
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x18, -0x1c(%rbp)
movl $0x43800000, -0x20(%rbp) # imm = 0x43800000
movl $0x43800000, -0x24(%rbp) # imm = 0x43800000
movslq -0x1c(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x37e0
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x3800
jmp 0x2608
leaq -0x41(%rbp), %rdi
callq 0x3870
movss 0x39eb(%rip), %xmm0     # 0x6004
mulss -0xc(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
movss -0xc(%rbp), %xmm0
subss -0x58(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movss -0xc(%rbp), %xmm0
addss -0x58(%rbp), %xmm0
movss %xmm0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x27d8
cvtsi2ssl -0x64(%rbp), %xmm0
cvtsi2ssl -0x1c(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x39b2(%rip), %xmm1     # 0x6020
mulsd %xmm1, %xmm0
movsd 0x399e(%rip), %xmm1     # 0x6018
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x68(%rbp)
movl -0x64(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x26a6
movss -0x5c(%rbp), %xmm0
movss %xmm0, -0x224(%rbp)
jmp 0x26b3
movss -0x60(%rbp), %xmm0
movss %xmm0, -0x224(%rbp)
movss -0x224(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
movss -0x20(%rbp), %xmm0
movss %xmm0, -0x230(%rbp)
movss -0x6c(%rbp), %xmm0
movss %xmm0, -0x22c(%rbp)
movss -0x68(%rbp), %xmm0
callq 0x3890
movss %xmm0, -0x228(%rbp)
jmp 0x26ee
movss -0x230(%rbp), %xmm1
movss -0x228(%rbp), %xmm2
movss -0x22c(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x240(%rbp)
movslq -0x64(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x38b0
movss -0x240(%rbp), %xmm0
movss %xmm0, (%rax)
movss -0x24(%rbp), %xmm0
movss %xmm0, -0x23c(%rbp)
movss -0x6c(%rbp), %xmm0
movss %xmm0, -0x238(%rbp)
movss -0x68(%rbp), %xmm0
callq 0x38d0
movss %xmm0, -0x234(%rbp)
jmp 0x275d
movss -0x23c(%rbp), %xmm1
movss -0x234(%rbp), %xmm2
movss -0x238(%rbp), %xmm0
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x244(%rbp)
movslq -0x64(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x38b0
movss -0x244(%rbp), %xmm0
movss %xmm0, 0x4(%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x2648
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x3870
jmp 0x2c80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2c77
leaq -0x90(%rbp), %rdi
callq 0x22b0
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jge 0x2b51
movl -0x94(%rbp), %eax
cltd
idivl -0x1c(%rbp)
movslq %edx, %rsi
leaq -0x40(%rbp), %rdi
callq 0x38b0
movq (%rax), %rax
movq %rax, -0x9c(%rbp)
cmpl $0x0, -0x94(%rbp)
jne 0x299b
movss -0x9c(%rbp), %xmm0
leaq -0x120(%rbp), %rdi
callq 0x3a60
jmp 0x2845
leaq 0x37e6(%rip), %rsi      # 0x6032
leaq -0x100(%rbp), %rdi
leaq -0x120(%rbp), %rdx
callq 0x3a10
jmp 0x2861
leaq 0x37d5(%rip), %rdx      # 0x603d
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x39c0
jmp 0x287d
movss -0x98(%rbp), %xmm0
leaq -0x140(%rbp), %rdi
callq 0x3a60
jmp 0x2893
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x38f0
jmp 0x28af
leaq -0x90(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x22a0
jmp 0x28c4
leaq -0xc0(%rbp), %rdi
callq 0x2140
leaq -0x140(%rbp), %rdi
callq 0x2140
leaq -0xe0(%rbp), %rdi
callq 0x2140
leaq -0x100(%rbp), %rdi
callq 0x2140
leaq -0x120(%rbp), %rdi
callq 0x2140
jmp 0x2b3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2c6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x298a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x297e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2972
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2966
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x2140
leaq -0x140(%rbp), %rdi
callq 0x2140
leaq -0xe0(%rbp), %rdi
callq 0x2140
leaq -0x100(%rbp), %rdi
callq 0x2140
leaq -0x120(%rbp), %rdi
callq 0x2140
jmp 0x2c6b
movss -0x9c(%rbp), %xmm0
leaq -0x1e0(%rbp), %rdi
callq 0x3a60
jmp 0x29b1
leaq 0x3688(%rip), %rsi      # 0x6040
leaq -0x1c0(%rbp), %rdi
leaq -0x1e0(%rbp), %rdx
callq 0x3a10
jmp 0x29cd
leaq 0x377f(%rip), %rdx      # 0x6153
leaq -0x1a0(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x39c0
jmp 0x29e9
movss -0x98(%rbp), %xmm0
leaq -0x200(%rbp), %rdi
callq 0x3a60
jmp 0x29ff
leaq -0x180(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
leaq -0x200(%rbp), %rdx
callq 0x38f0
jmp 0x2a1b
leaq 0x3731(%rip), %rdx      # 0x6153
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x39c0
jmp 0x2a37
leaq -0x90(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x22a0
jmp 0x2a4c
leaq -0x160(%rbp), %rdi
callq 0x2140
leaq -0x180(%rbp), %rdi
callq 0x2140
leaq -0x200(%rbp), %rdi
callq 0x2140
leaq -0x1a0(%rbp), %rdi
callq 0x2140
leaq -0x1c0(%rbp), %rdi
callq 0x2140
leaq -0x1e0(%rbp), %rdi
callq 0x2140
jmp 0x2b3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2b2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2b1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2b12
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2b06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2afa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x2140
leaq -0x180(%rbp), %rdi
callq 0x2140
leaq -0x200(%rbp), %rdi
callq 0x2140
leaq -0x1a0(%rbp), %rdi
callq 0x2140
leaq -0x1c0(%rbp), %rdi
callq 0x2140
leaq -0x1e0(%rbp), %rdi
callq 0x2140
jmp 0x2c6b
jmp 0x2b3d
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x27ee
leaq 0x34eb(%rip), %rsi      # 0x6043
leaq -0x90(%rbp), %rdi
callq 0x21e0
jmp 0x2b66
leaq 0x34d9(%rip), %rsi      # 0x6046
leaq -0x90(%rbp), %rdi
callq 0x21e0
jmp 0x2b7b
movss -0xc(%rbp), %xmm0
movss 0x348c(%rip), %xmm1     # 0x6014
divss %xmm1, %xmm0
movss 0x3478(%rip), %xmm1     # 0x600c
mulss %xmm1, %xmm0
movss 0x3470(%rip), %xmm1     # 0x6010
addss %xmm1, %xmm0
movss %xmm0, -0x204(%rbp)
movss -0x204(%rbp), %xmm0
movss 0x344c(%rip), %xmm1     # 0x6008
ucomiss %xmm1, %xmm0
jbe 0x2bd1
movss 0x343f(%rip), %xmm0     # 0x6008
movss %xmm0, -0x204(%rbp)
movq -0x220(%rbp), %rdi
movq -0x8(%rbp), %rax
movq %rax, -0x258(%rbp)
callq 0x20e0
movq -0x258(%rbp), %rdi
movq %rax, %rdx
movss -0x204(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x3446(%rip), %rsi      # 0x604b
movb $0x1, %al
callq 0x22c0
movq -0x8(%rbp), %rax
movq %rax, -0x250(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x20e0
movq -0x250(%rbp), %rdi
movq %rax, %rdx
leaq 0x3459(%rip), %rsi      # 0x608d
movb $0x0, %al
callq 0x22c0
movq -0x8(%rbp), %rdi
leaq 0x344a(%rip), %rsi      # 0x6090
movb $0x0, %al
callq 0x22c0
leaq -0x90(%rbp), %rdi
callq 0x2140
leaq -0x40(%rbp), %rdi
callq 0x3ab0
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x2140
leaq -0x40(%rbp), %rdi
callq 0x3ab0
movq -0x50(%rbp), %rdi
callq 0x2320
nopl (%rax)