// File: /workspace/github_cpp_makefile_star2_O1/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 0x1306(%rip), %rdi      # 0x40b2
callq 0x20f0
leaq -0x190(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x12fe(%rip), %rsi      # 0x40c1
leaq 0x12fe(%rip), %rdx      # 0x40c8
leaq -0x1a0(%rbp), %r12
movq %r12, %rdi
callq 0x3830
leaq -0x180(%rbp), %r14
leaq -0x170(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x12d7(%rip), %rsi      # 0x40c9
leaq 0x12d7(%rip), %rdx      # 0x40d0
movq %r14, %rdi
callq 0x3830
leaq -0x160(%rbp), %r14
leaq -0x150(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x12b7(%rip), %rsi      # 0x40d1
leaq 0x12b7(%rip), %rdx      # 0x40d8
movq %r14, %rdi
callq 0x3830
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x1a0(%rbp), %rsi
movq -0x198(%rbp), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x3796
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x128(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
addq %rsi, %rdx
leaq -0x138(%rbp), %rdi
callq 0x3796
leaq -0x50(%rbp), %rdi
movss 0x118f(%rip), %xmm0     # 0x4020
leaq -0x138(%rbp), %rsi
callq 0x35b0
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x38ca
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ec3
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0x138(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2ede
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2120
leaq -0xa8(%rbp), %r15
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 0x11b8(%rip), %rcx      # 0x40d9
callq 0x2140
movq %r15, -0xb8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2f4f
movq %rdx, -0xb8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xa8(%rbp)
jmp 0x2f56
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, -0xb0(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0xb8(%rbp), %rdi
leaq 0x1164(%rip), %rsi      # 0x40e2
callq 0x21d0
movq %r12, -0x50(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2fa3
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x2fab
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 0x111a(%rip), %rsi      # 0x40e7
callq 0x2160
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
je 0x2fea
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0xb8(%rbp), %rdi
cmpq %r15, %rdi
je 0x3005
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x3027
movq -0x108(%rbp), %rsi
incq %rsi
callq 0x2120
movq %r14, %rdi
leaq 0x10b8(%rip), %rsi      # 0x40e9
movsd 0x100f(%rip), %xmm0     # 0x4048
movaps %xmm0, %xmm1
movb $0x2, %al
callq 0x2180
movl $0x6, %esi
movl $0x1, %edx
leaq 0x10f7(%rip), %rdi      # 0x414b
movq %r14, %rcx
callq 0x21e0
movq %r14, %rdi
leaq 0x10ec(%rip), %rsi      # 0x4152
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0x2180
movq %r14, %rdi
leaq 0x10e2(%rip), %rsi      # 0x415e
movl $0x200, %edx            # imm = 0x200
xorl %eax, %eax
callq 0x2180
movl $0x6, %esi
movl $0x1, %edx
leaq 0x10d2(%rip), %rdi      # 0x416b
movq %r14, %rcx
callq 0x21e0
movl $0x6, %esi
movl $0x1, %edx
leaq 0x10c0(%rip), %rdi      # 0x4172
movq %r14, %rcx
callq 0x21e0
movl $0x11, %esi
movl $0x1, %edx
leaq 0x10ae(%rip), %rdi      # 0x4179
movq %r14, %rcx
callq 0x21e0
movq -0x70(%rbp), %r13
movq -0x68(%rbp), %rax
subq %r13, %rax
je 0x3197
xorl %ebx, %ebx
xorl %r12d, %r12d
movss (%r13,%rbx), %xmm0
movss %xmm0, -0x58(%rbp)
leaq -0xe8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq 0x8(%r13,%rbx), %rsi
movq 0x10(%r13,%rbx), %rdx
addq %rsi, %rdx
leaq -0xf8(%rbp), %r15
movq %r15, %rdi
callq 0x3796
movq %r14, %rdi
movss -0x58(%rbp), %xmm0
movq %r15, %rsi
callq 0x246f
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x3151
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x2120
movss (%r13,%rbx), %xmm0
addss 0xeb8(%rip), %xmm0      # 0x4018
movss %xmm0, (%r13,%rbx)
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, %rbx
cmpq %r12, %rcx
ja 0x30e9
movss -0x28(%r13,%rax), %xmm0
ucomiss 0xe7f(%rip), %xmm0      # 0x4024
leaq -0xa8(%rbp), %r15
jbe 0x328e
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 0x3796
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movss 0xde3(%rip), %xmm0      # 0x4020
movq %r13, %rsi
callq 0x35b0
leaq -0x70(%rbp), %rdi
movq %rbx, %rsi
callq 0x38ca
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x326a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x3292
movq -0xc8(%rbp), %rsi
incq %rsi
callq 0x2120
jmp 0x3292
leaq -0x40(%rbp), %r12
movl $0x6, %esi
movl $0x1, %edx
leaq 0xee8(%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 0x2efd
leaq 0xfe5(%rip), %rdi       # 0x42b7
callq 0x2190
leaq 0xeb4(%rip), %rdi       # 0x4192
callq 0x20f0
leaq 0xfda(%rip), %rdi       # 0x42c4
callq 0x2190
leaq 0xef5(%rip), %rdi       # 0x41eb
callq 0x20f0
leaq 0xfd8(%rip), %rdi       # 0x42da
callq 0x2190
leaq -0x70(%rbp), %rdi
callq 0x3608
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x332c
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2120
movq $-0x60, %rbx
leaq -0x150(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rdi, %rax
je 0x3354
movq (%rax), %rsi
incq %rsi
movq %rax, %r14
callq 0x2120
movq %r14, %rax
addq $-0x20, %rax
addq $0x20, %rbx
jne 0x333a
xorl %eax, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r13
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3393
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
jmp 0x3393
movq %rax, %r13
movq -0x138(%rbp), %rdi
cmpq %rbx, %rdi
je 0x34ba
movq -0x128(%rbp), %rsi
jmp 0x34b2
jmp 0x3490
movq %rax, %r13
jmp 0x34df
jmp 0x33be
movq %rax, %r13
jmp 0x33c9
movq %rax, %r13
movq %r12, %r14
cmpq %r14, %r12
je 0x3515
addq $-0x10, %r14
leaq -0x1a0(%rbp), %rbx
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x33f1
movq (%r14), %rsi
incq %rsi
callq 0x2120
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %rbx, %r14
movq %rax, %r14
jne 0x33dd
jmp 0x3515
jmp 0x3490
jmp 0x3490
movq %rax, %r13
jmp 0x3433
jmp 0x3490
movq %rax, %r13
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3433
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x34ba
movq -0xc8(%rbp), %rsi
jmp 0x34b2
jmp 0x3490
movq %rax, %r13
jmp 0x3474
movq %rax, %r13
movq -0xb8(%rbp), %rdi
cmpq %r15, %rdi
je 0x3474
movq -0xa8(%rbp), %rsi
incq %rsi
callq 0x2120
movq -0x118(%rbp), %rdi
leaq -0x108(%rbp), %rax
cmpq %rax, %rdi
je 0x34ba
movq -0x108(%rbp), %rsi
jmp 0x34b2
movq %rax, %r13
jmp 0x34ba
movq %rax, %r13
movq -0xf8(%rbp), %rdi
leaq -0xe8(%rbp), %rax
cmpq %rax, %rdi
je 0x34ba
movq -0xe8(%rbp), %rsi
incq %rsi
callq 0x2120
leaq -0x70(%rbp), %rdi
callq 0x3608
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x34df
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2120
leaq -0x150(%rbp), %rcx
xorl %ebx, %ebx
movq -0x160(%rbp,%rbx), %rdi
leaq (%rcx,%rbx), %rax
cmpq %rdi, %rax
je 0x350b
movq (%rax), %rsi
incq %rsi
callq 0x2120
leaq -0x150(%rbp), %rcx
addq $-0x20, %rbx
cmpq $-0x60, %rbx
jne 0x34e8
movq %r13, %rdi
callq 0x21b0