// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq -0xa8(%rsp), %rsp
leaq 0x915f(%rip), %rsi      # 0xc44c
movq %rdi, %r14
callq 0x11b0
testq %rax, %rax
je 0x3710
movq %rax, %rbx
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1180
movq %rbx, %rdi
callq 0x1130
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rax, %r15
callq 0x1180
movq %r15, %rdi
callq 0x1150
testq %rax, %rax
je 0x36f2
movq %rax, %r12
movq %r14, 0x38(%rsp)
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x1060
cmpq %r15, %rax
jne 0x3726
movq %rbx, %rdi
callq 0x1090
cmpq $0x8, %r15
movq %r12, 0x50(%rsp)
movq %r15, 0x58(%rsp)
jl 0x36cd
cmpb $-0x77, (%r12)
jne 0x36cd
cmpb $0x50, 0x1(%r12)
jne 0x36cd
cmpb $0x4e, 0x2(%r12)
jne 0x36cd
cmpb $0x47, 0x3(%r12)
jne 0x36cd
cmpb $0xd, 0x4(%r12)
jne 0x36cd
cmpb $0xa, 0x5(%r12)
jne 0x36cd
cmpb $0x1a, 0x6(%r12)
jne 0x36cd
cmpb $0xa, 0x7(%r12)
jne 0x36cd
movq %r12, %r14
addq %r12, %r15
movq $0x0, 0x20(%rsp)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x18(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x0, 0x34(%rsp)
movq $0x0, 0x48(%rsp)
movl $0x0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
addq $0x8, %r14
leaq 0xc(%r14), %rbp
cmpq %r15, %rbp
jae 0x36cd
movq %r14, %rdi
movq %r14, %r13
callq 0x3db8
movl %eax, %ebx
leal (%eax), %eax
leaq 0xc(%r14,%rax), %r14
cmpq %r15, %r14
ja 0x36cd
leaq 0x4(%r13), %rdi
callq 0x3db8
cmpl $0x49444154, %eax       # imm = 0x49444154
je 0x35ea
cmpl $0x74524e53, %eax       # imm = 0x74524E53
je 0x3545
cmpl $0x504c5445, %eax       # imm = 0x504C5445
je 0x3557
cmpl $0x49484452, %eax       # imm = 0x49484452
jne 0x3432
cmpl $0xd, %ebx
jb 0x36cd
cmpb $0x0, 0x12(%r13)
jne 0x36cd
cmpb $0x0, 0x13(%r13)
jne 0x36cd
cmpb $0x0, 0x14(%r13)
jne 0x36cd
leaq 0x8(%r13), %rdi
callq 0x3db8
movq %rbp, %rdi
movq %rax, 0x10(%rsp)
callq 0x3db8
movzbl 0x11(%r13), %edx
movl %eax, 0x2c(%rsp)
cmpq $0x6, %rdx
movq %rdx, 0x18(%rsp)
ja 0x36cd
leaq 0x8dc3(%rip), %rcx      # 0xc2b0
movq 0x18(%rsp), %rax
movzbl 0x10(%r13), %edx
movslq (%rcx,%rax,4), %rax
movl %edx, 0x8(%rsp)
addq %rcx, %rax
jmpq *%rax
cmpl $0x8, 0x8(%rsp)
ja 0x36cd
movl $0x116, %eax            # imm = 0x116
movl 0x8(%rsp), %ecx
btl %ecx, %eax
jae 0x36cd
movq 0x10(%rsp), %rax
imull 0x8(%rsp), %eax
addl $0x7, %eax
cltd
pushq $0x8
popq %rcx
idivl %ecx
movl %eax, 0xc(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x20(%rsp)
jmp 0x3432
addq $0x8, %r13
movl %ebx, 0x30(%rsp)
movq %r13, 0x40(%rsp)
jmp 0x3432
movl %ebx, %eax
xorl %edx, %edx
pushq $0x3
popq %rcx
divl %ecx
addq $0x8, %r13
movq %r13, 0x48(%rsp)
movl %eax, 0x34(%rsp)
jmp 0x3432
cmpl $0x8, 0x8(%rsp)
jne 0x36cd
movq 0x10(%rsp), %rax
shll $0x2, %eax
movl %eax, 0xc(%rsp)
pushq $0x4
popq %rax
movq %rax, 0x20(%rsp)
pushq $0x6
jmp 0x35d8
cmpl $0x8, 0x8(%rsp)
jne 0x36cd
movq 0x10(%rsp), %rax
leal (%rax,%rax,2), %eax
movl %eax, 0xc(%rsp)
pushq $0x3
popq %rax
movq %rax, 0x20(%rsp)
pushq $0x2
jmp 0x35d8
cmpl $0x8, 0x8(%rsp)
jne 0x36cd
movq 0x10(%rsp), %rax
addl %eax, %eax
movl %eax, 0xc(%rsp)
pushq $0x2
popq %rax
movq %rax, 0x20(%rsp)
pushq $0x4
popq %rax
movq %rax, 0x18(%rsp)
pushq $0x8
popq %rax
movl %eax, 0x8(%rsp)
jmp 0x3432
movq 0x10(%rsp), %r14
movl 0x2c(%rsp), %r15d
movq 0x40(%rsp), %rax
movl 0x30(%rsp), %ecx
addq $0x8, %r13
leal (,%r14,4), %ebp
movq %rax, 0x88(%rsp)
movl %ecx, 0x90(%rsp)
movq 0x48(%rsp), %rcx
movl %ebp, %edx
movq %rcx, 0x78(%rsp)
movl 0x34(%rsp), %ecx
imull %r15d, %edx
movl %ecx, 0x80(%rsp)
movl 0x8(%rsp), %ecx
movl %r14d, 0x60(%rsp)
movl %r15d, 0x64(%rsp)
movl %ecx, 0x68(%rsp)
movq 0x18(%rsp), %rcx
movl %ecx, 0x6c(%rsp)
movl 0xc(%rsp), %ecx
movl %ecx, 0x70(%rsp)
movq 0x20(%rsp), %rcx
movl %ecx, 0x74(%rsp)
movq %r13, 0x98(%rsp)
movl %ebx, 0xa0(%rsp)
movslq %edx, %rdi
addq $0x10, %rdi
callq 0x1150
leaq 0x10(%rax), %r8
movq %rax, %rdi
movl %r14d, %esi
movl %r15d, %edx
movl %ebp, %ecx
movq %rax, %rbx
callq 0x4c00
testq %rbx, %rbx
je 0x36f2
movq 0x8(%rbx), %rsi
movl 0x4(%rbx), %edx
leaq 0x50(%rsp), %rdi
callq 0x3746
testb %al, %al
je 0x3736
movq %r12, %rdi
callq 0x1040
movq %rbx, %rax
leaq 0xa8(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd924(%rip), %rax      # 0x10ff8
leaq 0x8dbf(%rip), %rsi      # 0xc49a
movq (%rax), %rdi
movq 0x38(%rsp), %rdx
xorl %eax, %eax
callq 0x1120
pushq $0x1
popq %rdi
callq 0x11d0
movq 0xd8ff(%rip), %rax      # 0x10ff8
leaq 0x8d6a(%rip), %rdi      # 0xc46a
movq (%rax), %rcx
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x11e0
jmp 0x36ea
movq 0xd8e1(%rip), %rax      # 0x10ff8
leaq 0x8d31(%rip), %rsi      # 0xc44f
movq %r14, %rdx
movq (%rax), %rdi
jmp 0x36e3
movq 0xd8cb(%rip), %rax      # 0x10ff8
leaq 0x8d46(%rip), %rsi      # 0xc47a
jmp 0x36db
movq 0xd8bb(%rip), %rax      # 0x10ff8
leaq 0x8d7a(%rip), %rsi      # 0xc4be
jmp 0x36db