// File: /workspace/github_c_makefile_star2_O3/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 -0x78(%rsp), %rsp
leaq 0xabe2(%rip), %rsi      # 0xe598
movq %rdi, %rbx
callq 0x11b0
testq %rax, %rax
je 0x3d2d
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
movq %rax, %r12
callq 0x1180
movq %r12, %rdi
callq 0x1130
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %rax, %r15
callq 0x1180
movq %r15, %rdi
callq 0x1150
testq %rax, %rax
je 0x3d35
movl $0x1, %esi
movq %rax, %rdi
movq %r15, %rdx
movq %r12, %rcx
movq %rax, %r14
movq %rbx, 0x10(%rsp)
callq 0x1060
cmpq %r15, %rax
jne 0x3d3a
movq %r12, %rdi
callq 0x1090
cmpq $0x8, %r15
movq %r14, 0x20(%rsp)
movq %r14, (%rsp)
movq %r15, 0x28(%rsp)
jl 0x3c7c
movq (%rsp), %rax
cmpb $-0x77, (%rax)
jne 0x3c7c
movq (%rsp), %rax
cmpb $0x50, 0x1(%rax)
jne 0x3c7c
movq (%rsp), %rax
cmpb $0x4e, 0x2(%rax)
jne 0x3c7c
movq (%rsp), %rax
cmpb $0x47, 0x3(%rax)
jne 0x3c7c
movq (%rsp), %rax
cmpb $0xd, 0x4(%rax)
jne 0x3c7c
movq (%rsp), %rax
cmpb $0xa, 0x5(%rax)
jne 0x3c7c
movq (%rsp), %rax
cmpb $0x1a, 0x6(%rax)
jne 0x3c7c
cmpq $0x15, %r15
jb 0x3c7c
movq (%rsp), %rax
cmpb $0xa, 0x7(%rax)
jne 0x3c7c
movq (%rsp), %rcx
xorl %esi, %esi
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %edx, %edx
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %eax, %eax
xorl %r9d, %r9d
movq $0x0, 0x18(%rsp)
movl $0x0, 0xc(%rsp)
addq %rcx, %r15
leaq 0x8(%rcx), %r10
addq $0x14, %rcx
movbel (%r10), %r11d
movq %r10, %r13
leaq 0xc(%r10,%r11), %r10
cmpq %r15, %r10
ja 0x3c7c
movbel 0x4(%r13), %edi
leaq 0x8(%r13), %r8
cmpl $0x504c5444, %edi       # imm = 0x504C5444
jle 0x3b3e
cmpl $0x504c5445, %edi       # imm = 0x504C5445
je 0x3bf8
cmpl $0x74524e53, %edi       # imm = 0x74524E53
jne 0x3c69
movl %r11d, 0xc(%rsp)
movq %r8, %r9
jmp 0x3c69
cmpl $0x49484452, %edi       # imm = 0x49484452
jne 0x3c0f
cmpl $0xd, %r11d
jb 0x3c7c
cmpb $0x0, 0x12(%r13)
jne 0x3c7c
cmpb $0x0, 0x13(%r13)
jne 0x3c7c
cmpb $0x0, 0x14(%r13)
jne 0x3c7c
movzbl 0x11(%r13), %ebx
cmpq $0x6, %rbx
ja 0x3c7c
movzbl (%rcx), %ecx
movzbl 0xd(%r13), %edx
movzbl 0xe(%r13), %esi
movzbl 0xf(%r13), %ebp
movbel 0x8(%r13), %r14d
shll $0x18, %ecx
shll $0x10, %edx
shll $0x8, %esi
orl %ecx, %edx
orl %edx, %esi
leaq 0xa7e0(%rip), %rdx      # 0xe390
movslq (%rdx,%rbx,4), %rcx
orl %esi, %ebp
addq %rdx, %rcx
movzbl 0x10(%r13), %edx
jmpq *%rcx
cmpl $0x8, %edx
ja 0x3c7c
movl $0x116, %ecx            # imm = 0x116
btl %edx, %ecx
jae 0x3c7c
movl %r14d, %r12d
movl $0x1, %esi
imull %edx, %r12d
leal 0x7(%r12), %ecx
addl $0xe, %r12d
testl %ecx, %ecx
cmovnsl %ecx, %r12d
sarl $0x3, %r12d
jmp 0x3c69
movl %r11d, %eax
movl $0xaaaaaaab, %ecx       # imm = 0xAAAAAAAB
movq %r8, 0x18(%rsp)
imulq %rcx, %rax
shrq $0x21, %rax
jmp 0x3c69
cmpl $0x49444154, %edi       # imm = 0x49444154
jne 0x3c69
jmp 0x3c86
cmpl $0x8, %edx
jne 0x3c7c
leal (,%r14,4), %r12d
movl $0x8, %edx
movl $0x6, %ebx
movl $0x4, %esi
jmp 0x3c69
cmpl $0x8, %edx
jne 0x3c7c
leal (%r14,%r14,2), %r12d
movl $0x8, %edx
movl $0x2, %ebx
movl $0x3, %esi
jmp 0x3c69
cmpl $0x8, %edx
jne 0x3c7c
leal (%r14,%r14), %r12d
movl $0x8, %edx
movl $0x4, %ebx
movl $0x2, %esi
addq %r11, %r13
addq $0x18, %r13
cmpq %r15, %r13
movq %r13, %rcx
jb 0x3af1
movq 0x10(%rsp), %rdi
callq 0x1626
leal (,%r14,4), %r13d
movl 0xc(%rsp), %edi
movq %r9, 0x58(%rsp)
movl %r13d, %ecx
movl %edi, 0x60(%rsp)
movq 0x18(%rsp), %rdi
imull %ebp, %ecx
movq %rdi, 0x48(%rsp)
movl %eax, 0x50(%rsp)
movl %r14d, 0x30(%rsp)
movl %ebp, 0x34(%rsp)
movl %edx, 0x38(%rsp)
movl %ebx, 0x3c(%rsp)
movl %r12d, 0x40(%rsp)
movl %esi, 0x44(%rsp)
movq %r8, 0x68(%rsp)
movl %r11d, 0x70(%rsp)
movslq %ecx, %rdi
addq $0x10, %rdi
callq 0x1150
leaq 0x10(%rax), %r8
movq %rax, %rdi
movl %r14d, %esi
movl %ebp, %edx
movl %r13d, %ecx
movq %rax, %r15
callq 0x5700
testq %r15, %r15
je 0x3d44
movq 0x8(%r15), %rsi
movl 0x4(%r15), %edx
leaq 0x20(%rsp), %rdi
callq 0x3d53
testb %al, %al
movq (%rsp), %rdi
je 0x3d49
callq 0x1040
movq %r15, %rax
leaq 0x78(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x166f
callq 0x164a
movq 0x10(%rsp), %rdi
callq 0x15b9
callq 0x1601
movq 0x10(%rsp), %rdi
callq 0x15dd