// File: /workspace/github_cpp_makefile_star2_O3/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 0x1325(%rip), %rdi      # 0x40b2
callq 0x20f0
leaq -0x190(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x131d(%rip), %rsi      # 0x40c1
leaq 0x131d(%rip), %rdx      # 0x40c8
leaq -0x1a0(%rbp), %r14
movq %r14, %rdi
callq 0x3800
leaq -0x180(%rbp), %r15
leaq -0x170(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x12f6(%rip), %rsi      # 0x40c9
leaq 0x12f6(%rip), %rdx      # 0x40d0
movq %r15, %rdi
callq 0x3800
leaq -0x160(%rbp), %r15
leaq -0x150(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x12d6(%rip), %rsi      # 0x40d1
leaq 0x12d6(%rip), %rdx      # 0x40d8
movq %r15, %rdi
callq 0x3800
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x1a0(%rbp), %rsi
movq -0x198(%rbp), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x3762
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x128(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x138(%rbp), %rdi
callq 0x3762
leaq -0x50(%rbp), %rdi
movss 0x11ae(%rip), %xmm0     # 0x4020
leaq -0x138(%rbp), %rsi
callq 0x357a
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x389e
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ea4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x2ebf
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2120
leaq -0xa8(%rbp), %rbx
leaq -0x40(%rbp), %r12
leaq -0x118(%rbp), %r14
xorl %esi, %esi
movq $0x0, -0x98(%rbp)
movq %r14, %rdi
movl %esi, -0x54(%rbp)
movl $0x5, %edx
callq 0x230c
movl $0x8, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x11d7(%rip), %rcx      # 0x40d9
callq 0x2140
movq %rbx, -0xb8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2f30
movq %rdx, -0xb8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xa8(%rbp)
jmp 0x2f36
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, -0xb0(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xb8(%rbp), %rdi
leaq 0x1184(%rip), %rsi      # 0x40e2
callq 0x21d0
movq %r12, -0x50(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2f83
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x2f8b
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, -0x48(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x50(%rbp), %rdi
leaq 0x113a(%rip), %rsi      # 0x40e7
callq 0x2160
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x2fca
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0xb8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2fe5
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x3007
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2120
movq %r14, %rdi
leaq 0x10d8(%rip), %rsi      # 0x40e9
movsd 0x102f(%rip), %xmm0     # 0x4048
movaps %xmm0, %xmm1
movb $0x2, %al
callq 0x2180
movl $0x6, %esi
movl $0x1, %edx
leaq 0x1117(%rip), %rdi      # 0x414b
movq %r14, %rcx
callq 0x21e0
movq %r14, %rdi
leaq 0x110c(%rip), %rsi      # 0x4152
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0x2180
movq %r14, %rdi
leaq 0x1102(%rip), %rsi      # 0x415e
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0x2180
movl $0x6, %esi
movl $0x1, %edx
leaq 0x10f2(%rip), %rdi      # 0x416b
movq %r14, %rcx
callq 0x21e0
movl $0x6, %esi
movl $0x1, %edx
leaq 0x10e0(%rip), %rdi      # 0x4172
movq %r14, %rcx
callq 0x21e0
movl $0x11, %esi
movl $0x1, %edx
leaq 0x10ce(%rip), %rdi      # 0x4179
movq %r14, %rcx
callq 0x21e0
movq -0x70(%rbp), %r13
cmpq %r13, -0x68(%rbp)
je 0x3177
xorl %r15d, %r15d
xorl %r12d, %r12d
movss (%r13,%r15), %xmm0
movss %xmm0, -0x58(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq 0x8(%r13,%r15), %rsi
movq 0x10(%r13,%r15), %rdx
addq %rsi, %rdx
leaq -0xf8(%rbp), %rbx
movq %rbx, %rdi
callq 0x3762
movq %r14, %rdi
movss -0x58(%rbp), %xmm0
movq %rbx, %rsi
callq 0x246f
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x312f
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x2120
movss (%r13,%r15), %xmm0
addss 0xeda(%rip), %xmm0      # 0x4018
movss %xmm0, (%r13,%r15)
incq %r12
movq -0x70(%rbp), %r13
movq -0x68(%rbp), %rax
subq %r13, %rax
movq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
addq $0x28, %r15
cmpq %r12, %rcx
ja 0x30c7
jmp 0x3179
xorl %eax, %eax
movss -0x28(%r13,%rax), %xmm0
ucomiss 0xe9d(%rip), %xmm0      # 0x4024
leaq -0xa8(%rbp), %rbx
jbe 0x3270
movq -0x98(%rbp), %rdx
incl %edx
movslq %edx, %rdx
imulq $0x55555556, %rdx, %rax # imm = 0x55555556
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x20, %rax
addl %ecx, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edx
movq %rdx, -0x98(%rbp)
movslq %edx, %rax
shlq $0x5, %rax
leaq (%rax,%rbp), %rsi
addq $-0x1a0, %rsi           # imm = 0xFE60
leaq -0x90(%rbp), %rdi
callq 0x2080
leaq -0x40(%rbp), %r12
leaq -0xd8(%rbp), %r13
leaq -0xc8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x3762
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movss 0xe01(%rip), %xmm0      # 0x4020
movq %r13, %rsi
callq 0x357a
leaq -0x70(%rbp), %rdi
movq %r15, %rsi
callq 0x389e
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x324c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x3274
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x2120
jmp 0x3274
leaq -0x40(%rbp), %r12
movl $0x6, %esi
movl $0x1, %edx
leaq 0xf06(%rip), %rdi       # 0x418b
movq %r14, %rcx
callq 0x21e0
movq %r14, %rdi
callq 0x2100
movl -0x54(%rbp), %esi
incl %esi
cmpl $0x12c, %esi            # imm = 0x12C
leaq -0x118(%rbp), %r14
jne 0x2ede
leaq 0x1003(%rip), %rdi      # 0x42b7
callq 0x2190
leaq 0xed2(%rip), %rdi       # 0x4192
callq 0x20f0
leaq 0xff8(%rip), %rdi       # 0x42c4
callq 0x2190
leaq 0xf13(%rip), %rdi       # 0x41eb
callq 0x20f0
leaq 0xff6(%rip), %rdi       # 0x42da
callq 0x2190
leaq -0x70(%rbp), %rdi
callq 0x35d2
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x330e
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2120
movq $-0x60, %r14
leaq -0x150(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x3336
movq (%rax), %rsi
incq %rsi
movq %rax, %rbx
callq 0x2120
movq %rbx, %rax
addq $-0x20, %rax
addq $0x20, %r14
jne 0x331c
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3375
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
jmp 0x3375
movq %rax, %r12
movq -0x138(%rbp), %rdi
cmpq %r14, %rdi
je 0x3484
movq -0x128(%rbp), %rsi
jmp 0x347c
jmp 0x345a
movq %rax, %r12
jmp 0x34a9
jmp 0x33a0
movq %rax, %r12
addq $-0x10, %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x33bb
movq (%r15), %rsi
incq %rsi
callq 0x2120
leaq -0x20(%r15), %rax
addq $-0x10, %r15
cmpq %r14, %r15
movq %rax, %r15
jne 0x33a7
jmp 0x34e0
jmp 0x345a
jmp 0x345a
movq %rax, %r12
jmp 0x33fd
jmp 0x345a
movq %rax, %r12
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x33fd
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x3484
movq -0xc8(%rbp), %rsi
jmp 0x347c
jmp 0x345a
movq %rax, %r12
jmp 0x343e
movq %rax, %r12
movq -0xb8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x343e
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x3484
movq -0x108(%rbp), %rsi
jmp 0x347c
movq %rax, %r12
jmp 0x3484
movq %rax, %r12
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x3484
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x2120
leaq -0x70(%rbp), %rdi
callq 0x35d2
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x34a9
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2120
leaq -0x150(%rbp), %rcx
xorl %r14d, %r14d
movq -0x160(%rbp,%r14), %rdi
leaq (%rcx,%r14), %rax
cmpq %rdi, %rax
je 0x34d6
movq (%rax), %rsi
incq %rsi
callq 0x2120
leaq -0x150(%rbp), %rcx
addq $-0x20, %r14
cmpq $-0x60, %r14
jne 0x34b3
movq %r12, %rdi
callq 0x21b0