// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/Main.c
// Function: RenderGIFAnimation
static void RenderGIFAnimation(int width,int height)
{
	fprintf(stderr,"Initializing renderer...\n");
	Initialize(width*Oversampling,height*Oversampling);

	Bitmap *screen=AllocateBitmap(width*Oversampling,height*Oversampling);

	Bitmap *downsampled=NULL;
	if(Oversampling>1) downsampled=AllocateBitmap(width,height);

	uint8_t *quantized=malloc(width*height);

	FILE *fh=fopen(Filename,"wb");
    fprintf(stderr,"Output file %s\n",Filename);
	WriteGIFHeader(fh,width,height,NULL,0,0);
	WriteGIFNetscapeApplicationExtension(fh,0xffff);

	int gifduration=Duration*100+0.5;
	int numframes=Duration*FPS+0.5;

	int lastgiftime=gifduration*(numframes-1)/numframes-gifduration;
	for(int i=0;i<numframes;i++)
	{
		float animtime=(float)i/(float)numframes;
		int giftime=gifduration*i/numframes;

		fprintf(stderr,"Frame %d/%d: Rendering, ",i+1,numframes);
		fflush(stderr);

		Render(screen,animtime);

		Bitmap *result=screen;
		if(Oversampling>1)
		{
			fprintf(stderr,"downsampling, ");
			fflush(stderr);

			DownsampleBitmap(downsampled,screen,Oversampling);
			result=downsampled;
		}

		fprintf(stderr,"quantizing, ");
		fflush(stderr);

		Palette palette;
		int numcolours=QuantizeBitmap(result,quantized,palette,screen);

		WriteGIFGraphicControlExtension(fh,GIFNoDisposal,giftime-lastgiftime,-1);
		WriteGIFImage(fh,0,0,width,height,palette,numcolours,quantized);

		fprintf(stderr,"done.\n");
		fflush(stderr);

		lastgiftime=giftime;
	}

	WriteGIFTrailer(fh);
	fclose(fh);

	FreeBitmap(screen);
	FreeBitmap(downsampled);
	free(quantized);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x470(%rsp), %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq 0x1980f(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0x13902(%rip), %rsi     # 0x170f5
movb $0x0, %al
callq 0x1130
movl -0x4(%rbp), %edi
imull 0x19da4(%rip), %edi     # 0x1d5a8
movl -0x8(%rbp), %esi
imull 0x19d9a(%rip), %esi     # 0x1d5a8
callq 0x1620
movl -0x4(%rbp), %edi
imull 0x19d8b(%rip), %edi     # 0x1d5a8
movl -0x8(%rbp), %esi
imull 0x19d81(%rip), %esi     # 0x1d5a8
callq 0x3b90
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
cmpl $0x1, 0x19d69(%rip)     # 0x1d5a8
jle 0x3850
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
callq 0x3b90
movq %rax, -0x18(%rbp)
movl -0x4(%rbp), %eax
imull -0x8(%rbp), %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, -0x20(%rbp)
movq 0x19d46(%rip), %rdi     # 0x1d5b0
leaq 0x1389e(%rip), %rsi     # 0x1710f
callq 0x11c0
movq %rax, -0x28(%rbp)
movq 0x19777(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq 0x19d25(%rip), %rdx     # 0x1d5b0
leaq 0x13880(%rip), %rsi     # 0x17112
movb $0x0, %al
callq 0x1130
movq -0x28(%rbp), %rdi
movl -0x4(%rbp), %esi
movl -0x8(%rbp), %edx
xorl %eax, %eax
movl %eax, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
callq 0x2680
movq -0x28(%rbp), %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x2b90
movss 0x1381c(%rip), %xmm0    # 0x170e4
mulss 0x19ccc(%rip), %xmm0    # 0x1d59c
cvtss2sd %xmm0, %xmm0
movsd 0x1380c(%rip), %xmm1    # 0x170e8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2c(%rbp)
movss 0x19cad(%rip), %xmm0    # 0x1d59c
mulss 0x19cad(%rip), %xmm0    # 0x1d5a4
cvtss2sd %xmm0, %xmm0
movsd 0x137e5(%rip), %xmm1    # 0x170e8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
movl -0x30(%rbp), %ecx
subl $0x1, %ecx
imull %ecx, %eax
cltd
idivl -0x30(%rbp)
subl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x3ab1
cvtsi2ssl -0x38(%rbp), %xmm0
cvtsi2ssl -0x30(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
imull -0x38(%rbp), %eax
cltd
idivl -0x30(%rbp)
movl %eax, -0x40(%rbp)
movq 0x19699(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movl -0x38(%rbp), %edx
addl $0x1, %edx
movl -0x30(%rbp), %ecx
leaq 0x137b0(%rip), %rsi     # 0x17122
movb $0x0, %al
callq 0x1130
movq 0x19678(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
callq 0x1170
movq -0x10(%rbp), %rdi
movss -0x3c(%rbp), %xmm0
callq 0x1e10
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpl $0x1, 0x19c03(%rip)     # 0x1d5a8
jle 0x39e9
movq 0x1964a(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0x13783(%rip), %rsi     # 0x1713b
movb $0x0, %al
callq 0x1130
movq 0x19632(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
callq 0x1170
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl 0x19bcc(%rip), %edx     # 0x1d5a8
callq 0x2070
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x19608(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0x13750(%rip), %rsi     # 0x1714a
movb $0x0, %al
callq 0x1130
movq 0x195f0(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
callq 0x1170
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x450(%rbp), %rdx
movq -0x10(%rbp), %rcx
callq 0x7420
movl %eax, -0x454(%rbp)
movq -0x28(%rbp), %rdi
movl -0x40(%rbp), %edx
subl -0x34(%rbp), %edx
movl $0x1, %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x29c0
movq -0x28(%rbp), %rdi
movl -0x4(%rbp), %ecx
movl -0x8(%rbp), %r8d
leaq -0x450(%rbp), %r9
movl -0x454(%rbp), %r10d
movq -0x20(%rbp), %rax
xorl %edx, %edx
movl %edx, %esi
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2be0
movq 0x1957b(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0x136d0(%rip), %rsi     # 0x17157
movb $0x0, %al
callq 0x1130
movq 0x19563(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
callq 0x1170
movl -0x40(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x392b
movq -0x28(%rbp), %rdi
callq 0x2990
movq -0x28(%rbp), %rdi
callq 0x10a0
movq -0x10(%rbp), %rdi
callq 0x3bf0
movq -0x18(%rbp), %rdi
callq 0x3bf0
movq -0x20(%rbp), %rdi
callq 0x1030
leaq 0x470(%rsp), %rsp
popq %rbp
retq
nopl (%rax,%rax)