// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/../Graphics/Tools/DeflateReader.h
// Function: ReadDeflateBlockHeader
static bool ReadDeflateBlockHeader(DeflateReader *self)
{
	self->islastblock=ReadBitString(&self->bitstream,1);

	int type=ReadBitString(&self->bitstream,2);
	if(type<0) return false;

	switch(type)
	{
		case 0: // Stored.
		{
			FlushBitStream(&self->bitstream);

			int count=ReadBitString(&self->bitstream,16);
			int count2=ReadBitString(&self->bitstream,16);
			if(count!=(count2^0xffff)) return false;

			self->storedbytesleft=count;
			self->isstoredblock=true;
		}
		break;

		case 1: // Fixed Huffman.
			InitializeDeflateFixedLiteralCode(self->literalcode);
			InitializeDeflateFixedDistanceCode(self->distancecode);
			self->isstoredblock=false;
		break;

		case 2: // Dynamic Huffman.
		{
			int numliterals=ReadBitString(&self->bitstream,5)+257;
			int numdistances=ReadBitString(&self->bitstream,5)+1;
			int nummetas=ReadBitString(&self->bitstream,4)+4;

			uint16_t metacode[128];
			if(!ReadDeflateMetaCode(self,metacode,nummetas)) return false;

			int total=numliterals+numdistances;
			int lengths[total];
			int i=0;
			while(i<total)
			{
				int val=ReadHuffmanCode(&self->bitstream,metacode,7);
				if(val<0) return false;

				if(val<16)
				{
					lengths[i++]=val;
				}
				else if(val==16)
				{
					int repeats=ReadBitString(&self->bitstream,2)+3;

					if(i==0||i+repeats>total) return false;

					for(int j=0;j<repeats;j++) lengths[i+j]=lengths[i-1];
					i+=repeats;
				}
				else
				{
					int repeats;
					if(val==17) repeats=ReadBitString(&self->bitstream,3)+3;
					else repeats=ReadBitString(&self->bitstream,7)+11;

					if(i+repeats>total) return false;

					for(int j=0;j<repeats;j++) lengths[i+j]=0;
					i+=repeats;
				}
			}

			if(!BuildHuffmanTableFromLengths(self->literalcode,15,lengths,numliterals)) return false;
			if(!BuildHuffmanTableFromLengths(self->distancecode,15,lengths+numliterals,numdistances)) return false;

			self->isstoredblock=false;
		}
		break;

		default: return false;
	}

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x170(%rsp), %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x65a0
cmpl $0x0, %eax
setne %cl
movq -0x10(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x2d(%rax)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x65a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x666e
movb $0x0, -0x1(%rbp)
jmp 0x6a6c
movl -0x14(%rbp), %eax
movl %eax, -0x168(%rbp)
testl %eax, %eax
je 0x669e
jmp 0x667d
movl -0x168(%rbp), %eax
subl $0x1, %eax
je 0x66f9
jmp 0x668a
movl -0x168(%rbp), %eax
subl $0x2, %eax
je 0x6726
jmp 0x6a62
movq -0x10(%rbp), %rdi
callq 0x6c90
movq -0x10(%rbp), %rdi
movl $0x10, %esi
callq 0x65a0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x10, %esi
callq 0x65a0
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movl -0x1c(%rbp), %ecx
xorl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %eax
je 0x66e2
movb $0x0, -0x1(%rbp)
jmp 0x6a6c
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x2c(%rax)
jmp 0x6a68
movq -0x10(%rbp), %rdi
addq $0x8034, %rdi           # imm = 0x8034
callq 0x6cd0
movq -0x10(%rbp), %rdi
addq $0x18034, %rdi          # imm = 0x18034
callq 0x6df0
movq -0x10(%rbp), %rax
movb $0x0, 0x2c(%rax)
jmp 0x6a68
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0x65a0
addl $0x101, %eax            # imm = 0x101
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0x65a0
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x65a0
addl $0x4, %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movl -0x28(%rbp), %edx
callq 0x6e60
testb $0x1, %al
jne 0x6784
movb $0x0, -0x1(%rbp)
jmp 0x6a6c
movl -0x20(%rbp), %eax
movl -0x24(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x134(%rbp)
movl -0x134(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x140(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x170(%rbp)
movq %rcx, %rsp
movq %rax, -0x148(%rbp)
movl $0x0, -0x14c(%rbp)
movl -0x14c(%rbp), %eax
cmpl -0x134(%rbp), %eax
jge 0x69c5
movq -0x10(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movl $0x7, %edx
callq 0x6a80
movl %eax, -0x150(%rbp)
cmpl $0x0, -0x150(%rbp)
jge 0x6818
movb $0x0, -0x1(%rbp)
movl $0x1, -0x154(%rbp)
jmp 0x6a48
cmpl $0x10, -0x150(%rbp)
jge 0x684a
movq -0x170(%rbp), %rax
movl -0x150(%rbp), %edx
movl -0x14c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14c(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x69c0
cmpl $0x10, -0x150(%rbp)
jne 0x6906
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x65a0
addl $0x3, %eax
movl %eax, -0x158(%rbp)
cmpl $0x0, -0x14c(%rbp)
je 0x688b
movl -0x14c(%rbp), %eax
addl -0x158(%rbp), %eax
cmpl -0x134(%rbp), %eax
jle 0x689e
movb $0x0, -0x1(%rbp)
movl $0x1, -0x154(%rbp)
jmp 0x6a48
movl $0x0, -0x15c(%rbp)
movl -0x15c(%rbp), %eax
cmpl -0x158(%rbp), %eax
jge 0x68ef
movq -0x170(%rbp), %rax
movl -0x14c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movl -0x14c(%rbp), %ecx
addl -0x15c(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x15c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x15c(%rbp)
jmp 0x68a8
movl -0x158(%rbp), %eax
addl -0x14c(%rbp), %eax
movl %eax, -0x14c(%rbp)
jmp 0x69be
cmpl $0x11, -0x150(%rbp)
jne 0x6928
movq -0x10(%rbp), %rdi
movl $0x3, %esi
callq 0x65a0
addl $0x3, %eax
movl %eax, -0x160(%rbp)
jmp 0x693f
movq -0x10(%rbp), %rdi
movl $0x7, %esi
callq 0x65a0
addl $0xb, %eax
movl %eax, -0x160(%rbp)
movl -0x14c(%rbp), %eax
addl -0x160(%rbp), %eax
cmpl -0x134(%rbp), %eax
jle 0x6966
movb $0x0, -0x1(%rbp)
movl $0x1, -0x154(%rbp)
jmp 0x6a48
movl $0x0, -0x164(%rbp)
movl -0x164(%rbp), %eax
cmpl -0x160(%rbp), %eax
jge 0x69ac
movq -0x170(%rbp), %rax
movl -0x14c(%rbp), %ecx
addl -0x164(%rbp), %ecx
movslq %ecx, %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x6970
movl -0x160(%rbp), %eax
addl -0x14c(%rbp), %eax
movl %eax, -0x14c(%rbp)
jmp 0x69c0
jmp 0x67cf
movq -0x170(%rbp), %rdx
movq -0x10(%rbp), %rdi
addq $0x8034, %rdi           # imm = 0x8034
movl -0x20(%rbp), %ecx
movl $0xf, %esi
callq 0x6f00
testb $0x1, %al
jne 0x69f8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x154(%rbp)
jmp 0x6a48
movq -0x170(%rbp), %rdx
movq -0x10(%rbp), %rdi
addq $0x18034, %rdi          # imm = 0x18034
movslq -0x20(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdx
movl -0x24(%rbp), %ecx
movl $0xf, %esi
callq 0x6f00
testb $0x1, %al
jne 0x6a36
movb $0x0, -0x1(%rbp)
movl $0x1, -0x154(%rbp)
jmp 0x6a48
movq -0x10(%rbp), %rax
movb $0x0, 0x2c(%rax)
movl $0x0, -0x154(%rbp)
movq -0x140(%rbp), %rax
movq %rax, %rsp
movl -0x154(%rbp), %eax
testl %eax, %eax
je 0x6a60
jmp 0x6a5e
jmp 0x6a6c
jmp 0x6a68
movb $0x0, -0x1(%rbp)
jmp 0x6a6c
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)