// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/GIF.c
// Function: WriteGIFHeader
void WriteGIFHeader(FILE *fh,int width,int height,Palette palette,int numcolours,int background)
{
	uint8_t flags=0;

	int palettesize=0;
	if(palette && numcolours>0)
	{
		int exp;
		if(numcolours>128) exp=8;
		else if(numcolours>64) exp=7;
		else if(numcolours>32) exp=6;
		else if(numcolours>16) exp=5;
		else if(numcolours>8) exp=4;
		else if(numcolours>4) exp=3;
		else if(numcolours>2) exp=2;
		else exp=1;

		flags|=0x80|0x70|0x00|(exp-1); // GCT present, 8-bit entries, not sorted, number of entries.
		palettesize=1<<exp;
	}

	uint8_t header[]=
	{
		'G','I','F','8','9','a',
		width&0xff,width>>8,
		height&0xff,height>>8,
		flags,
		background,
		0, // Pixel Aspect Ratio
	};

	Write(fh,header,sizeof(header));
	for(int i=0;i<palettesize;i++)
	{
		uint8_t entry[3]={0,0,0};
		if(i<numcolours)
		{
			entry[0]=ExtractRed(palette[i]);
			entry[1]=ExtractGreen(palette[i]);
			entry[2]=ExtractBlue(palette[i]);
		}
		Write(fh,entry,3);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x50(%rsp), %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x2760
cmpl $0x0, -0x1c(%rbp)
jle 0x2760
cmpl $0x80, -0x1c(%rbp)
jle 0x26d1
movl $0x8, -0x2c(%rbp)
jmp 0x273e
cmpl $0x40, -0x1c(%rbp)
jle 0x26e0
movl $0x7, -0x2c(%rbp)
jmp 0x273c
cmpl $0x20, -0x1c(%rbp)
jle 0x26ef
movl $0x6, -0x2c(%rbp)
jmp 0x273a
cmpl $0x10, -0x1c(%rbp)
jle 0x26fe
movl $0x5, -0x2c(%rbp)
jmp 0x2738
cmpl $0x8, -0x1c(%rbp)
jle 0x270d
movl $0x4, -0x2c(%rbp)
jmp 0x2736
cmpl $0x4, -0x1c(%rbp)
jle 0x271c
movl $0x3, -0x2c(%rbp)
jmp 0x2734
cmpl $0x2, -0x1c(%rbp)
jle 0x272b
movl $0x2, -0x2c(%rbp)
jmp 0x2732
movl $0x1, -0x2c(%rbp)
jmp 0x2734
jmp 0x2736
jmp 0x2738
jmp 0x273a
jmp 0x273c
jmp 0x273e
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
orl $0xf0, %ecx
movzbl -0x21(%rbp), %eax
orl %ecx, %eax
movb %al, -0x21(%rbp)
movl -0x2c(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x28(%rbp)
movb $0x47, -0x39(%rbp)
movb $0x49, -0x38(%rbp)
movb $0x46, -0x37(%rbp)
movb $0x38, -0x36(%rbp)
movb $0x39, -0x35(%rbp)
movb $0x61, -0x34(%rbp)
movl -0xc(%rbp), %eax
andl $0xff, %eax
movb %al, -0x33(%rbp)
movl -0xc(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x32(%rbp)
movl -0x10(%rbp), %eax
andl $0xff, %eax
movb %al, -0x31(%rbp)
movl -0x10(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x30(%rbp)
movb -0x21(%rbp), %al
movb %al, -0x2f(%rbp)
movl -0x20(%rbp), %eax
movb %al, -0x2e(%rbp)
movb $0x0, -0x2d(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x39(%rbp), %rsi
movl $0xd, %edx
callq 0x2930
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x291c
leaq -0x43(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x10f0
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x28fc
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x0, %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x2810
xorl %eax, %eax
movl %eax, -0x48(%rbp)
jmp 0x2844
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x8, %eax
andl $0xff, %eax
imull $0xff, %eax, %eax
movq -0x18(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl $0x0, %ecx
andl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movb %al, -0x43(%rbp)
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x0, %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x2869
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
jmp 0x289d
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x10, %eax
andl $0xff, %eax
imull $0xff, %eax, %eax
movq -0x18(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl $0x0, %ecx
andl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movb %al, -0x42(%rbp)
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x0, %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x28c2
xorl %eax, %eax
movl %eax, -0x50(%rbp)
jmp 0x28f6
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x18, %eax
andl $0xff, %eax
imull $0xff, %eax, %eax
movq -0x18(%rbp), %rcx
movslq -0x40(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shrl $0x0, %ecx
andl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movb %al, -0x41(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x43(%rbp), %rsi
movl $0x3, %edx
callq 0x2930
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x27c9
leaq 0x50(%rsp), %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)