// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/PNG.c
// Function: LoadPNG
Bitmap *LoadPNG(const char *filename)
{
	FILE *fh=fopen(filename,"rb");
	if(!fh)
	{
		fprintf(stderr,"Could not open file \"%s\".\n",filename);
		exit(1);
	}

	fseek(fh,0,SEEK_END);
	long size=ftell(fh);
	fseek(fh,0,SEEK_SET);

	void *bytes=malloc(size);
	if(!bytes)
	{
		fprintf(stderr,"Out of memory.\n");
		exit(1);
	}

	if(fread(bytes,1,size,fh)!=size)
	{
		fprintf(stderr,"Reading from file \"%s\" failed.\n",filename);
		exit(1);
	}

	fclose(fh);

	PNGLoader loader;
	InitializePNGLoader(&loader,bytes,size);

	if(!LoadPNGHeader(&loader))
	{
		fprintf(stderr,"File \"%s\" is not a valid PNG file.\n",filename);
		exit(1);
	}

	Bitmap *bitmap=AllocateBitmap(loader.width,loader.height);
	if(!bitmap)
	{
		fprintf(stderr,"Out of memory.\n");
		exit(1);
	}

	if(!LoadPNGImageData(&loader,bitmap->pixels,bitmap->bytesperrow,PixelFunc))
	{
		fprintf(stderr,"Failed while loading PNG data from file \"%s\".\n",filename);
		exit(1);
	}

	free(bytes);

	return bitmap;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x80(%rsp), %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x12964(%rip), %rsi     # 0x1742c
callq 0x11c0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4afe
movq 0x18519(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x12942(%rip), %rsi     # 0x1742f
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x11f0
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x1190
movq -0x10(%rbp), %rdi
callq 0x1140
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x1190
movq -0x18(%rbp), %rdi
callq 0x1160
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4b62
movq 0x184b1(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0x128f9(%rip), %rsi     # 0x1744a
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x11f0
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x1070
cmpq -0x18(%rbp), %rax
je 0x4ba4
movq 0x18473(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x128c7(%rip), %rsi     # 0x1745a
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x11f0
movq -0x10(%rbp), %rdi
callq 0x10a0
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x4c90
leaq -0x78(%rbp), %rdi
callq 0x4d40
testb $0x1, %al
jne 0x4bf1
movq 0x18426(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x1289a(%rip), %rsi     # 0x1747a
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x11f0
movl -0x68(%rbp), %edi
movl -0x64(%rbp), %esi
callq 0x5160
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x4c29
movq 0x183ea(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
leaq 0x12832(%rip), %rsi     # 0x1744a
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x11f0
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x80(%rbp), %rax
movl 0x4(%rax), %edx
leaq -0x78(%rbp), %rdi
leaq 0x5ed(%rip), %rcx       # 0x5230
callq 0x51c0
testb $0x1, %al
jne 0x4c72
movq 0x183a5(%rip), %rax     # 0x1cff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x1283d(%rip), %rsi     # 0x1749e
movb $0x0, %al
callq 0x1130
movl $0x1, %edi
callq 0x11f0
movq -0x20(%rbp), %rdi
callq 0x1030
movq -0x80(%rbp), %rax
leaq 0x80(%rsp), %rsp
popq %rbp
retq
nopl (%rax)