// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/../Graphics/Tools/PNG.h
// Function: LoadPNGImageDataWithTemporaryStorage
static bool LoadPNGImageDataWithTemporaryStorage(PNGLoader *self,void *pixels,int bytesperrow,PNGPixelFunction *pixelfunc,void *temporarystorage)
{
	DeflateReader *reader=temporarystorage;
	uint8_t *buf1=(uint8_t *)temporarystorage+sizeof(DeflateReader);
	uint8_t *buf2=buf1+self->bytesperrow+self->bytesperpixel;

	// TODO: Check first two bytes for zlib header.
	InitializeDeflateReader(reader);
	ProvideDeflateInputBuffer(reader,self->idatstart+2,self->idatsize-2);
	SetDeflateInputCallback(reader,PNGInputCallback,self);

	memset(buf1,0,self->bytesperrow+self->bytesperpixel);
	memset(buf2,0,self->bytesperpixel);

	uint8_t *lastline=buf1+self->bytesperpixel;
	uint8_t *currline=buf2+self->bytesperpixel;

	for(int y=0;y<self->height;y++)
	{
		uint32_t linestart=y*(self->bytesperrow+1);
		uint32_t lineend=(y+1)*(self->bytesperrow+1);

		// Advance deflate stream until we can see all data, the copy data from window.
		if(!ReadDeflateStreamToPosition(reader,lineend)) return false;

		uint8_t filter=ByteFromDeflateWindow(reader,linestart);
		if(filter>4) return false;

		CopyBytesFromDeflateWindow(reader,currline,linestart+1,self->bytesperrow);

		// Undo filtering.
		for(int i=0;i<self->bytesperrow;i++)
		switch(filter)
		{
			case 0: break; // No filter.

			case 1:
			{
				int left=currline[i-self->bytesperpixel];
				currline[i]+=left;
			}
			break;

			case 2:
			{
				int above=lastline[i];
				currline[i]+=above;
			}
			break;

			case 3:
			{
				int left=currline[i-self->bytesperpixel];
				int above=lastline[i];
				currline[i]+=(left+above)/2;
			}
			break;

			case 4:
			{
				int left=currline[i-self->bytesperpixel];
				int above=lastline[i];
				int aboveleft=lastline[i-self->bytesperpixel];

				int p=left+above-aboveleft;
				int pa=PNGAbs(p-left);
				int pb=PNGAbs(p-above);
				int pc=PNGAbs(p-aboveleft);

				if(pa<=pb && pa<=pc) currline[i]+=left;
				else if(pb<=pc) currline[i]+=above;
				else currline[i]+=aboveleft;
			}
			break;
		}

		// Unpack pixels.
		void *outputline=(uint8_t *)pixels+bytesperrow*y;

		for(int x=0;x<self->width;x++)
		switch(self->colourtype)
		{
			case 0: // Grayscale
			{
				uint8_t gray=0;
				switch(self->bitdepth)
				{
					case 1: gray=((currline[x>>3]>>(x&7))&0x01)*0xff; break;
					case 2: gray=((currline[x>>2]>>(x&3))&0x03)*0x55; break;
					case 4: gray=((currline[x>>1]>>(x&1))&0x0f)*0x11; break;
					case 8: gray=currline[x]; break;
				}

				outputline=pixelfunc(outputline,gray,gray,gray,0xff,x,y);
			}
			break;

			case 2: // RGB
				outputline=pixelfunc(outputline,currline[3*x+0],currline[3*x+1],currline[3*x+2],0xff,x,y);
			break;

			case 3: // Palette
			{
				uint8_t index=0;
				switch(self->bitdepth)
				{
					case 1: index=(currline[x>>3]>>(x&7))&0x01; break;
					case 2: index=(currline[x>>2]>>(x&3))&0x03; break;
					case 4: index=(currline[x>>1]>>(x&1))&0x0f; break;
					case 8: index=currline[x]; break;
				}

				if(index>=self->palettecount) return false;
				uint8_t r=self->palettestart[3*index+0];
				uint8_t g=self->palettestart[3*index+1];
				uint8_t b=self->palettestart[3*index+2];

				uint8_t a=0xff;
				if(index<self->transparencycount) a=self->transparencystart[index];

				outputline=pixelfunc(outputline,r,g,b,a,x,y);
			}
			break;

			case 4: // Gray+alpha
				outputline=pixelfunc(outputline,currline[2*x+0],currline[2*x+0],currline[2*x+0],currline[2*x+1],x,y);
			break;

			case 6: // RGB+alpha
				outputline=pixelfunc(outputline,currline[4*x+0],currline[4*x+1],currline[4*x+2],currline[4*x+3],x,y);
			break;
		}

		// Swap line buffers.
		uint8_t *tmp=lastline;
		lastline=currline;
		currline=tmp;
	}

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0xe0(%rsp), %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x28038, %rax          # imm = 0x28038
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x20(%rcx), %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x5fb0
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
addq $0x2, %rsi
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
subl $0x2, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x6000
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x8f2(%rip), %rsi       # 0x6060
callq 0x6030
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
addl 0x24(%rcx), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10f0
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x24(%rax), %rdx
xorl %esi, %esi
callq 0x10f0
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x24(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x5f93
movl -0x5c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, -0x64(%rbp)
movq -0x38(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x6130
testb $0x1, %al
jne 0x5821
movb $0x0, -0x1(%rbp)
jmp 0x5f97
movq -0x38(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x6180
movb %al, -0x65(%rbp)
movzbl -0x65(%rbp), %eax
cmpl $0x4, %eax
jle 0x5842
movb $0x0, -0x1(%rbp)
jmp 0x5f97
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x60(%rbp), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
callq 0x61a0
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x5a6a
movzbl -0x65(%rbp), %eax
movq %rax, -0xc0(%rbp)
subq $0x4, %rax
ja 0x5a5a
movq -0xc0(%rbp), %rax
leaq 0x11a72(%rip), %rcx     # 0x17308
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x5a5a
movq -0x58(%rbp), %rax
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x24(%rdx), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %esi
movq -0x58(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x5a5a
movq -0x50(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %esi
movq -0x58(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x5a5a
movq -0x58(%rbp), %rax
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x24(%rdx), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x78(%rbp)
movq -0x50(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
addl -0x7c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %esi
movq -0x58(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x5a5a
movq -0x58(%rbp), %rax
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x24(%rdx), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x84(%rbp)
movq -0x50(%rbp), %rax
movl -0x6c(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x24(%rdx), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x88(%rbp)
movl -0x80(%rbp), %eax
addl -0x84(%rbp), %eax
subl -0x88(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %edi
subl -0x80(%rbp), %edi
callq 0x6240
movl %eax, -0x90(%rbp)
movl -0x8c(%rbp), %edi
subl -0x84(%rbp), %edi
callq 0x6240
movl %eax, -0x94(%rbp)
movl -0x8c(%rbp), %edi
subl -0x88(%rbp), %edi
callq 0x6240
movl %eax, -0x98(%rbp)
movl -0x90(%rbp), %eax
cmpl -0x94(%rbp), %eax
jg 0x5a18
movl -0x90(%rbp), %eax
cmpl -0x98(%rbp), %eax
jg 0x5a18
movl -0x80(%rbp), %esi
movq -0x58(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x5a58
movl -0x94(%rbp), %eax
cmpl -0x98(%rbp), %eax
jg 0x5a3f
movl -0x84(%rbp), %esi
movq -0x58(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x5a56
movl -0x88(%rbp), %esi
movq -0x58(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
jmp 0x5a58
jmp 0x5a5a
jmp 0x5a5c
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x5863
movq -0x18(%rbp), %rax
movl -0x1c(%rbp), %ecx
imull -0x5c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x5f67
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0xc8(%rbp)
subq $0x6, %rax
ja 0x5f51
movq -0xc8(%rbp), %rax
leaq 0x117e7(%rip), %rcx     # 0x172ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, -0xa5(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xd0(%rbp)
subl $0x7, %eax
ja 0x5ba4
movq -0xd0(%rbp), %rax
leaq 0x117ea(%rip), %rcx     # 0x172e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x58(%rbp), %rax
movl -0xa4(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xa4(%rbp), %ecx
andl $0x7, %ecx
sarl %cl, %eax
andl $0x1, %eax
imull $0xff, %eax, %eax
movb %al, -0xa5(%rbp)
jmp 0x5ba4
movq -0x58(%rbp), %rax
movl -0xa4(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xa4(%rbp), %ecx
andl $0x3, %ecx
sarl %cl, %eax
andl $0x3, %eax
imull $0x55, %eax, %eax
movb %al, -0xa5(%rbp)
jmp 0x5ba4
movq -0x58(%rbp), %rax
movl -0xa4(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xa4(%rbp), %ecx
andl $0x1, %ecx
sarl %cl, %eax
andl $0xf, %eax
imull $0x11, %eax, %eax
movb %al, -0xa5(%rbp)
jmp 0x5ba4
movq -0x58(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0xa5(%rbp)
movq -0x28(%rbp), %rax
movq -0xa0(%rbp), %rdi
movb -0xa5(%rbp), %sil
movb -0xa5(%rbp), %dl
movb -0xa5(%rbp), %cl
movl -0xa4(%rbp), %r9d
movl -0x5c(%rbp), %r10d
movl $0xff, %r8d
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movl %r10d, (%rsp)
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0x5f51
movq -0x28(%rbp), %rax
movq -0xa0(%rbp), %rdi
movq -0x58(%rbp), %rcx
imull $0x3, -0xa4(%rbp), %edx
addl $0x0, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %sil
movq -0x58(%rbp), %rcx
imull $0x3, -0xa4(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %dl
movq -0x58(%rbp), %rcx
imull $0x3, -0xa4(%rbp), %r8d
addl $0x2, %r8d
movslq %r8d, %r8
movb (%rcx,%r8), %cl
movl -0xa4(%rbp), %r9d
movl -0x5c(%rbp), %r10d
movl $0xff, %r8d
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movl %r10d, (%rsp)
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0x5f51
movb $0x0, -0xa6(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xd8(%rbp)
subl $0x7, %eax
ja 0x5d31
movq -0xd8(%rbp), %rax
leaq 0x11631(%rip), %rcx     # 0x172c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x58(%rbp), %rax
movl -0xa4(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xa4(%rbp), %ecx
andl $0x7, %ecx
sarl %cl, %eax
andl $0x1, %eax
movb %al, -0xa6(%rbp)
jmp 0x5d31
movq -0x58(%rbp), %rax
movl -0xa4(%rbp), %ecx
sarl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xa4(%rbp), %ecx
andl $0x3, %ecx
sarl %cl, %eax
andl $0x3, %eax
movb %al, -0xa6(%rbp)
jmp 0x5d31
movq -0x58(%rbp), %rax
movl -0xa4(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0xa4(%rbp), %ecx
andl $0x1, %ecx
sarl %cl, %eax
andl $0xf, %eax
movb %al, -0xa6(%rbp)
jmp 0x5d31
movq -0x58(%rbp), %rax
movslq -0xa4(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0xa6(%rbp)
movzbl -0xa6(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jl 0x5d4a
movb $0x0, -0x1(%rbp)
jmp 0x5f97
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movzbl -0xa6(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0xa7(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movzbl -0xa6(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movzbl -0xa6(%rbp), %ecx
imull $0x3, %ecx, %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0xa9(%rbp)
movb $-0x1, -0xaa(%rbp)
movzbl -0xa6(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jge 0x5ddc
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movzbl -0xa6(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0xaa(%rbp)
movq -0x28(%rbp), %rax
movq -0xa0(%rbp), %rdi
movb -0xa7(%rbp), %sil
movb -0xa8(%rbp), %dl
movb -0xa9(%rbp), %cl
movb -0xaa(%rbp), %r8b
movl -0xa4(%rbp), %r9d
movl -0x5c(%rbp), %r10d
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %r8b, %r8d
movl %r10d, (%rsp)
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0x5f51
movq -0x28(%rbp), %rax
movq -0xa0(%rbp), %rdi
movq -0x58(%rbp), %rcx
movl -0xa4(%rbp), %edx
shll %edx
addl $0x0, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %sil
movq -0x58(%rbp), %rcx
movl -0xa4(%rbp), %edx
shll %edx
addl $0x0, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %dl
movq -0x58(%rbp), %rcx
movl -0xa4(%rbp), %r8d
shll %r8d
addl $0x0, %r8d
movslq %r8d, %r8
movb (%rcx,%r8), %cl
movq -0x58(%rbp), %r8
movl -0xa4(%rbp), %r9d
shll %r9d
addl $0x1, %r9d
movslq %r9d, %r9
movb (%r8,%r9), %r8b
movl -0xa4(%rbp), %r9d
movl -0x5c(%rbp), %r10d
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %r8b, %r8d
movl %r10d, (%rsp)
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0x5f51
movq -0x28(%rbp), %rax
movq -0xa0(%rbp), %rdi
movq -0x58(%rbp), %rcx
movl -0xa4(%rbp), %edx
shll $0x2, %edx
addl $0x0, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %sil
movq -0x58(%rbp), %rcx
movl -0xa4(%rbp), %edx
shll $0x2, %edx
addl $0x1, %edx
movslq %edx, %rdx
movb (%rcx,%rdx), %dl
movq -0x58(%rbp), %rcx
movl -0xa4(%rbp), %r8d
shll $0x2, %r8d
addl $0x2, %r8d
movslq %r8d, %r8
movb (%rcx,%r8), %cl
movq -0x58(%rbp), %r8
movl -0xa4(%rbp), %r9d
shll $0x2, %r9d
addl $0x3, %r9d
movslq %r9d, %r9
movb (%r8,%r9), %r8b
movl -0xa4(%rbp), %r9d
movl -0x5c(%rbp), %r10d
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl %r8b, %r8d
movl %r10d, (%rsp)
callq *%rax
movq %rax, -0xa0(%rbp)
jmp 0x5f53
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x5a8c
movq -0x50(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x57cf
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
leaq 0xe0(%rsp), %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)