// File: /workspace/github_cpp_makefile_star2_O2/Erkaman[P]spiky-anim/main.cpp
// Function: main
int main(int argc, char** argv) {
    // create output dir.
    system("mkdir -p temp/");

    float START_RAD = 3.0f;
    float SPAWN_RAD = 40.0f;

    // colors of spikys.
    const int NC = 3;
    string colors[NC] = {
        "#990022",
        "#888822",
        "#9C8066",
    };

    int ic = 0;
    string curColor = colors[ic];

    vector<Star> stars;

    stars.push_back(Star(START_RAD, curColor));

    for(int i = 0; i < 300; i++) { // 1000

        FILE* fp = fopen(("temp/out" + zeroPad(i, 5) + ".svg").c_str(), "w");

        fprintf(fp, "<svg width=\"%f\" height=\"%f\" version=\"1.1\" baseProfile=\"full\" xmlns=\"http://www.w3.org/2000/svg\">\n", (float)WIDTH, (float)HEIGHT);

        // clear to black background.
        fprintf(fp,"<rect ");
        fprintf(fp,"width=\"%d\" ", WIDTH);
        fprintf(fp,"height=\"%d\" ", HEIGHT);
        fprintf(fp,"x=\"0\" ");
        fprintf(fp,"y=\"0\" ");
        fprintf(fp,"fill=\"#000000\"/>\n");

        for(int j = 0; j < stars.size(); j++) {
            Star& star = stars[j];

            makeSpiky(fp, star.rad, star.color);
            star.rad+=2.0f; // spiky velocity.
        }

        // once last spiky is big enough, spawn another one.
        const float& lastRad = stars[stars.size()-1].rad;
        if(lastRad > SPAWN_RAD) {
            ic = (ic+1)%NC;
            curColor = colors[ic];

            stars.push_back(Star(START_RAD, curColor));
        }

        fprintf(fp, "</svg>");
        fclose(fp);
    }
    printf("created svgs\n");

    system("cd temp/ && for i in *.svg; do rsvg-convert $i -o `echo $i | sed -e 's/svg$/png/'`; done");
    printf("converted svgs to png\n");

    // frames from (225) to (225+58) makes a good loop.
    system("cd temp/ && ffmpeg -start_number 225 -y -framerate 30 -i  out%05d.png -vframes 58 -c:v libx264 -vf \"scale=512:512\" -r 30 ../out.mp4 ");
    printf("encoded to mp4\n");


    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
leaq 0x1887(%rip), %rdi      # 0x40b2
callq 0x2110
leaq 0x188a(%rip), %rsi      # 0x40c1
leaq -0x180(%rbp), %r14
leaq -0x78(%rbp), %rdx
movq %r14, %rdi
callq 0x2cb0
leaq -0x160(%rbp), %r15
leaq 0x1871(%rip), %rsi      # 0x40c9
leaq -0x98(%rbp), %rdx
movq %r15, %rdi
callq 0x2cb0
leaq -0x140(%rbp), %r15
leaq 0x185c(%rip), %rsi      # 0x40d1
leaq -0xb8(%rbp), %rdx
movq %r15, %rdi
callq 0x2cb0
leaq -0x98(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x21a0
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
andq $0x0, -0x40(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x21a0
leaq -0x78(%rbp), %rdi
movss 0x175e(%rip), %xmm0     # 0x4020
leaq -0xd8(%rbp), %rsi
callq 0x2f0a
leaq -0x50(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3384
leaq -0x70(%rbp), %rdi
callq 0x2090
leaq -0xd8(%rbp), %rdi
callq 0x2090
leaq -0xb8(%rbp), %r12
leaq -0x78(%rbp), %r13
leaq -0x1a0(%rbp), %r14
movl $0x0, -0x2c(%rbp)
xorl %ebx, %ebx
cmpl $0x12c, %ebx            # imm = 0x12C
je 0x2b61
leaq -0x118(%rbp), %r15
movq %r15, %rdi
movl %ebx, %esi
pushq $0x5
popq %rdx
callq 0x233c
movq %r12, %rdi
leaq 0x17a4(%rip), %rsi      # 0x40d9
movq %r15, %rdx
callq 0x2ead
movl %ebx, -0x30(%rbp)
movq %r13, %rdi
movq %r12, %rsi
leaq 0x1795(%rip), %rdx      # 0x40e2
callq 0x2e84
movq -0x78(%rbp), %rdi
leaq 0x178a(%rip), %rsi      # 0x40e7
callq 0x2170
movq %rax, %rbx
movq %r13, %rdi
callq 0x2090
movq %r12, %rdi
callq 0x2090
leaq -0x118(%rbp), %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x175e(%rip), %rsi      # 0x40e9
movsd 0x16b5(%rip), %xmm0     # 0x4048
movaps %xmm0, %xmm1
movb $0x2, %al
callq 0x21b0
leaq 0x17a7(%rip), %rdi      # 0x414b
pushq $0x6
popq %r15
movq %r15, %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2220
movq %rbx, %rdi
leaq 0x178e(%rip), %rsi      # 0x4152
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0x21b0
movq %rbx, %rdi
leaq 0x1784(%rip), %rsi      # 0x415e
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0x21b0
leaq 0x177e(%rip), %rdi      # 0x416b
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2220
leaq 0x1770(%rip), %rdi      # 0x4172
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2220
leaq 0x1762(%rip), %rdi      # 0x4179
pushq $0x11
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2220
pushq $0x8
popq %r15
xorl %r13d, %r13d
movq -0x50(%rbp), %r12
movq -0x48(%rbp), %rcx
subq %r12, %rcx
movq %rcx, %rax
cqto
pushq $0x28
popq %rsi
idivq %rsi
cmpq %r13, %rax
jbe 0x2a98
movss -0x8(%r12,%r15), %xmm0
movss %xmm0, -0x34(%rbp)
addq %r15, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x21a0
movq %rbx, %rdi
movss -0x34(%rbp), %xmm0
movq %r14, %rsi
callq 0x23df
movq %r14, %rdi
callq 0x2090
movss -0x8(%r12), %xmm0
addss 0x1590(%rip), %xmm0     # 0x4018
movss %xmm0, -0x8(%r12)
incq %r13
addq $0x28, %r15
jmp 0x2a2c
movss -0x28(%r12,%rcx), %xmm0
ucomiss 0x157e(%rip), %xmm0     # 0x4024
jbe 0x2b2f
movl -0x2c(%rbp), %eax
incl %eax
cltd
pushq $0x3
popq %rcx
idivl %ecx
movl %edx, -0x2c(%rbp)
movslq %edx, %rax
shlq $0x5, %rax
leaq (%rax,%rbp), %rsi
addq $-0x180, %rsi           # imm = 0xFE80
leaq -0x98(%rbp), %rdi
callq 0x20b0
leaq -0xb8(%rbp), %r12
leaq -0x78(%rbp), %r13
leaq -0xf8(%rbp), %r15
movq %r15, %rdi
leaq -0x98(%rbp), %rsi
callq 0x21a0
movq %r13, %rdi
movss 0x151c(%rip), %xmm0     # 0x4020
movq %r15, %rsi
callq 0x2f0a
leaq -0x50(%rbp), %rdi
movq %r13, %rsi
callq 0x3384
leaq -0x70(%rbp), %rdi
callq 0x2090
leaq -0xf8(%rbp), %rdi
callq 0x2090
jmp 0x2b3a
leaq -0xb8(%rbp), %r12
leaq -0x78(%rbp), %r13
leaq 0x164a(%rip), %rdi      # 0x418b
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x2220
movq %rbx, %rdi
callq 0x2120
movl -0x30(%rbp), %ebx
incl %ebx
jmp 0x290b
leaq 0x1780(%rip), %rdi      # 0x42e8
callq 0x21c0
leaq 0x161e(%rip), %rdi      # 0x4192
callq 0x2110
leaq 0x1775(%rip), %rdi      # 0x42f5
callq 0x21c0
leaq 0x165f(%rip), %rdi      # 0x41eb
callq 0x2110
leaq 0x1773(%rip), %rdi      # 0x430b
callq 0x21c0
leaq -0x50(%rbp), %rdi
callq 0x2f4a
leaq -0x98(%rbp), %rdi
callq 0x2090
pushq $0x40
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x180, %rdi           # imm = 0xFE80
callq 0x2090
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x2bb5
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2090
jmp 0x2bf4
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
jmp 0x2c6b
jmp 0x2c72
movq %rax, %rbx
jmp 0x2c8a
jmp 0x2c09
movq %rax, %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x2090
cmpq %r14, %r15
jne 0x2c0c
jmp 0x2ca8
jmp 0x2c72
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x2090
jmp 0x2c37
jmp 0x2c72
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
jmp 0x2c6b
jmp 0x2c72
movq %rax, %rbx
jmp 0x2c56
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x2090
leaq -0x118(%rbp), %rdi
jmp 0x2c6b
jmp 0x2c72
movq %rax, %rbx
leaq -0x1a0(%rbp), %rdi
callq 0x2090
jmp 0x2c75
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x2f4a
leaq -0x98(%rbp), %rdi
callq 0x2090
pushq $0x40
popq %r14
leaq (%r14,%rbp), %rdi
addq $-0x180, %rdi           # imm = 0xFE80
callq 0x2090
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x2c8e
movq %rbx, %rdi
callq 0x21f0