// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/../Graphics/Tools/PNG.h
// Function: LoadPNGHeader
static bool LoadPNGHeader(PNGLoader *self)
{
	const uint8_t *ptr=self->bytes;
	const uint8_t *end=self->bytes+self->length;

	if(ptr+8>end) return false;
	if(*ptr++!=137) return false;
	if(*ptr++!=80) return false;
	if(*ptr++!=78) return false;
	if(*ptr++!=71) return false;
	if(*ptr++!=13) return false;
	if(*ptr++!=10) return false;
	if(*ptr++!=26) return false;
	if(*ptr++!=10) return false;

	while(ptr+12<end)
	{
		uint32_t size=PNGGetUInt32BE(&ptr[0]);
		uint32_t type=PNGGetUInt32BE(&ptr[4]);
		const uint8_t *next=ptr+size+12;
		if(next>end) return false;

		ptr+=8;

		switch(type)
		{
			case PNGMakeID('I','H','D','R'):
				if(size<13) return false;
				if(ptr[10]!=0) return false; // Compression type
				if(ptr[11]!=0) return false; // Filter method
				if(ptr[12]!=0) return false; // Interlace method

				self->width=PNGGetUInt32BE(&ptr[0]);
				self->height=PNGGetUInt32BE(&ptr[4]);
				self->bitdepth=ptr[8];
				self->colourtype=ptr[9];

				switch(self->colourtype)
				{
					case 0: // Grayscale
					case 3: // Palette
						if(self->bitdepth!=1&&self->bitdepth!=2&&
						self->bitdepth!=4&&self->bitdepth!=8) return false;

						self->bytesperrow=(self->bitdepth*self->width+7)/8;
						self->bytesperpixel=1;
					break;

					case 2: // RGB
						if(self->bitdepth!=8) return false;

						self->bytesperrow=3*self->width;
						self->bytesperpixel=3;
					break;

					case 4: // Gray+alpha
						if(self->bitdepth!=8) return false;

						self->bytesperrow=2*self->width;
						self->bytesperpixel=2;
					break;

					case 6: // RGB+alpha
						if(self->bitdepth!=8) return false;

						self->bytesperrow=4*self->width;
						self->bytesperpixel=4;
					break;

					default: return false;
				}
			break;

			case PNGMakeID('P','L','T','E'):
				self->palettestart=ptr;
				self->palettecount=size/3;
			break;

			case PNGMakeID('t','R','N','S'):
				self->transparencystart=ptr;
				self->transparencycount=size;
			break;

			case PNGMakeID('I','D','A','T'):
				self->idatstart=ptr;
				self->idatsize=size;
				return true;
			break;
		}

		ptr=next;
	}

	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x40(%rsp), %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
addq 0x8(%rcx), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
cmpq -0x20(%rbp), %rax
jbe 0x4d82
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0x89, %eax
je 0x4da4
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0x50, %eax
je 0x4dc4
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0x4e, %eax
je 0x4de4
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0x47, %eax
je 0x4e04
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0xd, %eax
je 0x4e24
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0xa, %eax
je 0x4e44
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0x1a, %eax
je 0x4e64
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movzbl (%rax), %eax
cmpl $0xa, %eax
je 0x4e84
movb $0x0, -0x1(%rbp)
jmp 0x514b
jmp 0x4e86
movq -0x18(%rbp), %rax
addq $0xc, %rax
cmpq -0x20(%rbp), %rax
jae 0x5147
movq -0x18(%rbp), %rdi
callq 0x5670
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rdi
addq $0x4, %rdi
callq 0x5670
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addq %rcx, %rax
addq $0xc, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x20(%rbp), %rax
jbe 0x4ed9
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x34(%rbp)
subl $0x49444154, %eax       # imm = 0x49444154
je 0x511e
jmp 0x4ef8
movl -0x34(%rbp), %eax
subl $0x49484452, %eax       # imm = 0x49484452
je 0x4f27
jmp 0x4f04
movl -0x34(%rbp), %eax
subl $0x504c5445, %eax       # imm = 0x504C5445
je 0x50e3
jmp 0x4f14
movl -0x34(%rbp), %eax
subl $0x74524e53, %eax       # imm = 0x74524E53
je 0x5106
jmp 0x513a
cmpl $0xd, -0x24(%rbp)
jae 0x4f36
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movzbl 0xa(%rax), %eax
cmpl $0x0, %eax
je 0x4f4c
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movzbl 0xb(%rax), %eax
cmpl $0x0, %eax
je 0x4f62
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
je 0x4f78
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x18(%rbp), %rdi
callq 0x5670
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rdi
addq $0x4, %rdi
callq 0x5670
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movzbl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
movzbl 0x9(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x40(%rbp)
subq $0x6, %rax
ja 0x50db
movq -0x40(%rbp), %rax
leaq 0x122b2(%rip), %rcx     # 0x17290
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
cmpl $0x1, 0x18(%rax)
je 0x5018
movq -0x10(%rbp), %rax
cmpl $0x2, 0x18(%rax)
je 0x5018
movq -0x10(%rbp), %rax
cmpl $0x4, 0x18(%rax)
je 0x5018
movq -0x10(%rbp), %rax
cmpl $0x8, 0x18(%rax)
je 0x5018
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x10(%rcx), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x24(%rax)
jmp 0x50e1
movq -0x10(%rbp), %rax
cmpl $0x8, 0x18(%rax)
je 0x505e
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x10(%rbp), %rax
imull $0x3, 0x10(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x3, 0x24(%rax)
jmp 0x50e1
movq -0x10(%rbp), %rax
cmpl $0x8, 0x18(%rax)
je 0x508d
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
shll %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x2, 0x24(%rax)
jmp 0x50e1
movq -0x10(%rbp), %rax
cmpl $0x8, 0x18(%rax)
je 0x50bd
movb $0x0, -0x1(%rbp)
jmp 0x514b
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
shll $0x2, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl $0x4, 0x24(%rax)
jmp 0x50e1
movb $0x0, -0x1(%rbp)
jmp 0x514b
jmp 0x513a
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movl -0x24(%rbp), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x513a
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x40(%rax)
jmp 0x513a
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x50(%rax)
movb $0x1, -0x1(%rbp)
jmp 0x514b
movq -0x30(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x4e86
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
leaq 0x40(%rsp), %rsp
popq %rbp
retq
nopw (%rax,%rax)