// File: /workspace/github_c_makefile_star2_O0/zhiyb[P]png2tlg/png2tlg.cpp
// Function: SaveTLG6(std::ostream*, tTVPBaseBitmap const*, bool)
void SaveTLG6( std::ostream* stream, const tTVPBaseBitmap* bmp, bool is24 )
{
	std::ostream *out = stream;

	// DWORD medstart, medend;
#ifdef WRITE_ENTROPY_VALUES
	FILE *vs = fopen("vs.bin", "wb");
#endif

	int colors;

	TVPTLG6InitGolombTable();

	// check pixel format
	if( bmp->Is32BPP() ) {
		if( is24 ) colors = 3;
		else colors = 4;
	} else {
		colors = 1;
	}
	int stride = colors;
	if( stride == 3 ) stride = 4;

	// output stream header
	{
		out->write("TLG6.0\x00raw\x1a\x00", 11);
		out->write((const char *)&colors, 1);
		int n = 0;
		out->write((const char *)&n, 1); // data flag (0)
		out->write((const char *)&n, 1); // color type (0)
		out->write((const char *)&n, 1); // external golomb table (0)
		int width = bmp->GetWidth();
		int height = bmp->GetHeight();
		WriteInt32(width, out);
		WriteInt32(height, out);
	}

	// compress
	long max_bit_length = 0;

	unsigned char *buf[MAX_COLOR_COMPONENTS];
	for(int i = 0; i < MAX_COLOR_COMPONENTS; i++) buf[i] = NULL;
	char *block_buf[MAX_COLOR_COMPONENTS];
	for(int i = 0; i < MAX_COLOR_COMPONENTS; i++) block_buf[i] = NULL;
	unsigned char *filtertypes = NULL;
	std::stringstream *memstream = NULL;

	try
	{
		memstream = new std::stringstream();

		TLG6BitStream bs(memstream);

//		int buf_size = bmp->Width * bmp->Height;

		// allocate buffer
		for(int c = 0; c < colors; c++)
		{
			buf[c] = new unsigned char [W_BLOCK_SIZE * H_BLOCK_SIZE * 3];
			block_buf[c] = new char [H_BLOCK_SIZE * bmp->GetWidth()];
		}
		int w_block_count = (int)((bmp->GetWidth() - 1) / W_BLOCK_SIZE) + 1;
		int h_block_count = (int)((bmp->GetHeight() - 1) / H_BLOCK_SIZE) + 1;
		filtertypes = new unsigned char [w_block_count * h_block_count];

		int fc = 0;
		for(int y = 0; y < (int)bmp->GetHeight(); y += H_BLOCK_SIZE)
		{
			int ylim = y + H_BLOCK_SIZE;
			if(ylim > (int)bmp->GetHeight()) ylim = bmp->GetHeight();
			int gwp = 0;
			int xp = 0;
			for(int x = 0; x < (int)bmp->GetWidth(); x += W_BLOCK_SIZE, xp++)
			{
				int xlim = x + W_BLOCK_SIZE;
				if(xlim > (int)bmp->GetWidth()) xlim = bmp->GetWidth();
				int bw = xlim - x;

				int p0size; // size of MED method (p=0)
				int minp = 0; // most efficient method (0:MED, 1:AVG)
				int ft; // filter type
				int wp; // write point
				for(int p = 0; p < 2; p++)
				{
					int dbofs = (p+1) * (H_BLOCK_SIZE * W_BLOCK_SIZE);

					// do med(when p=0) or take average of upper and left pixel(p=1)
					for(int c = 0; c < colors; c++)
					{
						int wp = 0;
						for(int yy = y; yy < ylim; yy++)
						{
							const unsigned char * sl = x*stride +
								c + (const unsigned char *)bmp->GetScanLine(yy);
							const unsigned char * usl;
							if(yy >= 1)
								usl = x*stride + c + (const unsigned char *)bmp->GetScanLine(yy-1);
							else
								usl = NULL;
							for(int xx = x; xx < xlim; xx++)
							{
								unsigned char pa = xx > 0 ? sl[-stride] : 0;
								unsigned char pb = usl ? *usl : 0;
								unsigned char px = *sl;

								unsigned char py;

//								py = 0;
								if(p == 0)
								{
									unsigned char pc = (xx > 0 && usl) ? usl[-stride] : 0;
									unsigned char min_a_b = pa>pb?pb:pa;
									unsigned char max_a_b = pa<pb?pb:pa;

									if(pc >= max_a_b)
										py = min_a_b;
									else if(pc < min_a_b)
										py = max_a_b;
									else
										py = pa + pb - pc;
								}
								else
								{
									py = (pa+pb+1)>>1;
								}
								
								// stbi_image format is RGBA, so swap to BGRA
								int wc = c == 0 ? 2 : c == 2 ? 0 : c;
								buf[wc][wp] = (unsigned char)(px - py);

								wp++;
								sl += stride;
								if(usl) usl += stride;
							}
						}
					}

					// reordering
					// Transfer the data into block_buf (block buffer).
					// Even lines are stored forward (left to right),
					// Odd lines are stored backward (right to left).

					wp = 0;
					for(int yy = y; yy < ylim; yy++)
					{
						int ofs;
						if(!(xp&1))
							ofs = (yy - y)*bw;
						else
							ofs = (ylim - yy - 1) * bw;
						bool dir; // false for forward, true for backward
						if(!((ylim-y)&1))
						{
							// vertical line count per block is even
							dir = ((yy&1) ^ (xp&1)) ? true : false;
						}
						else
						{
							// otherwise;
							if(xp & 1)
							{
								dir = (yy&1);
							}
							else
							{
								dir = ((yy&1) ^ (xp&1)) ? true : false;
							}
						}

						if(!dir)
						{
							// forward
							for(int xx = 0; xx < bw; xx++)
							{
								for(int c = 0; c < colors; c++)
									buf[c][wp + dbofs] =
									buf[c][ofs + xx];
								wp++;
							}
						}
						else
						{
							// backward
							for(int xx = bw - 1; xx >= 0; xx--)
							{
								for(int c = 0; c < colors; c++)
									buf[c][wp + dbofs] =
									buf[c][ofs + xx];
								wp++;
							}
						}
					}
				}


				for(int p = 0; p < 2; p++)
				{
					int dbofs = (p+1) * (H_BLOCK_SIZE * W_BLOCK_SIZE);
					// detect color filter
					int size = 0;
					int ft_;
					if(colors >= 3)
						ft_ = DetectColorFilter(
							reinterpret_cast<char*>(buf[0] + dbofs),
							reinterpret_cast<char*>(buf[1] + dbofs),
							reinterpret_cast<char*>(buf[2] + dbofs), wp, size);
					else
						ft_ = 0;

					// select efficient mode of p (MED or average)
					if(p == 0)
					{
						p0size = size;
						ft = ft_;
					}
					else
					{
						if(p0size >= size)
							minp = 1, ft = ft_;
					}
				}

				// Apply most efficient color filter / prediction method
				wp = 0;
				int dbofs = (minp + 1)  * (H_BLOCK_SIZE * W_BLOCK_SIZE);
				for(int yy = y; yy < ylim; yy++)
				{
					for(int xx = 0; xx < bw; xx++)
					{
						for(int c = 0; c < colors; c++)
							block_buf[c][gwp + wp] = buf[c][wp + dbofs];
						wp++;
					}
				}

				ApplyColorFilter(block_buf[0] + gwp,
					block_buf[1] + gwp, block_buf[2] + gwp, wp, ft);

				filtertypes[fc++] = (ft<<1) + minp;
//				ftfreq[ft]++;
				gwp += wp;
			}

			// compress values (entropy coding)
			for(int c = 0; c < colors; c++)
			{
				int method;
				CompressValuesGolomb(bs, block_buf[c], gwp);
				method = 0;
#ifdef WRITE_ENTROPY_VALUES
				fwrite(block_buf[c], 1, gwp, vs);
#endif
				long bitlength = bs.GetBitLength();
				if(bitlength & 0xc0000000)
					throw std::runtime_error("TVPTlgTooLargeBitLength");
				// two most significant bits of bitlength are
				// entropy coding method;
				// 00 means Golomb method,
				// 01 means Gamma method (implemented but not used),
				// 10 means modified LZSS method (not yet implemented),
				// 11 means raw (uncompressed) data (not yet implemented).
				if(max_bit_length < bitlength) max_bit_length = bitlength;
				bitlength |= (method << 30);
				WriteInt32(bitlength, memstream);
				bs.Flush();
			}

		}


		// write max bit length
		WriteInt32(max_bit_length, out);

		// output filter types
		{
			SlideCompressor comp;
			TLG6InitializeColorFilterCompressor(comp);
			unsigned char *outbuf = new unsigned char[fc * 2];
			try
			{
				long outlen;
				comp.Encode(filtertypes, fc, outbuf, outlen);
				WriteInt32(outlen, out);
				out->write((const char *)outbuf, outlen);
			}
			catch(...)
			{
				delete [] outbuf;
				throw std::runtime_error("Encoding error");
			}
			delete [] outbuf;

		}

		// copy memory stream to output stream
		std::string str(memstream->str());
		out->write((const char *)str.data(), (tjs_uint)str.size() );
	}
	catch(...)
	{
		for(int i = 0; i < MAX_COLOR_COMPONENTS; i++)
		{
			if(buf[i]) delete [] (buf[i]);
			if(block_buf[i]) delete [] (block_buf[i]);
		}
		if(filtertypes) delete [] filtertypes;
		if(memstream) delete memstream;
		throw;
	}

	for(int i = 0; i < MAX_COLOR_COMPONENTS; i++)
	{
		if(buf[i]) delete [] (buf[i]);
		if(block_buf) delete [] (block_buf[i]);
	}
	if(filtertypes) delete [] filtertypes;
	if(memstream) delete memstream;

#ifdef WRITE_ENTROPY_VALUES
	fclose(vs);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x92550, %rsp          # imm = 0x92550
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
callq 0x4900
movq -0x10(%rbp), %rdi
callq 0x1f520
testb $0x1, %al
jne 0x6d16
jmp 0x6d2e
testb $0x1, -0x11(%rbp)
je 0x6d25
movl $0x3, -0x24(%rbp)
jmp 0x6d2c
movl $0x4, -0x24(%rbp)
jmp 0x6d35
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x3, -0x28(%rbp)
jne 0x6d48
movl $0x4, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x19505(%rip), %rsi     # 0x20258
movl $0xb, %edx
callq 0x22d0
movq -0x20(%rbp), %rdi
leaq -0x24(%rbp), %rsi
movl $0x1, %edx
callq 0x22d0
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x1, %edx
callq 0x22d0
movq -0x20(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x1, %edx
callq 0x22d0
movq -0x20(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x1, %edx
callq 0x22d0
movq -0x10(%rbp), %rdi
callq 0x1f530
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f540
movl %eax, -0x34(%rbp)
movslq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x8090
movslq -0x34(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x8090
movq $0x0, -0x40(%rbp)
movl $0x0, -0x64(%rbp)
cmpl $0x4, -0x64(%rbp)
jge 0x6e0b
movslq -0x64(%rbp), %rax
movq $0x0, -0x60(%rbp,%rax,8)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x6ded
movl $0x0, -0x94(%rbp)
cmpl $0x4, -0x94(%rbp)
jge 0x6e42
movslq -0x94(%rbp), %rax
movq $0x0, -0x90(%rbp,%rax,8)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x6e15
movq $0x0, -0xa0(%rbp)
movq $0x0, -0xa8(%rbp)
movl $0x188, %edi            # imm = 0x188
callq 0x2210
movq %rax, -0x92410(%rbp)
jmp 0x6e6b
movq -0x92410(%rbp), %rdi
callq 0x2170
jmp 0x6e79
movq -0x92410(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rcx
movq %rcx, -0x92420(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x92418(%rbp)
je 0x6eb6
movq -0x92420(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x92418(%rbp)
movq -0x92418(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x1f560
jmp 0x6ecb
movl $0x0, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x6fb4
movl $0xc0, %edi
callq 0x2040
movq %rax, -0x92428(%rbp)
jmp 0x6ef7
movq -0x92428(%rbp), %rcx
movslq -0xe4(%rbp), %rax
movq %rcx, -0x60(%rbp,%rax,8)
movq -0x10(%rbp), %rdi
callq 0x1f530
movl %eax, -0x9242c(%rbp)
jmp 0x6f1b
movl -0x9242c(%rbp), %eax
shll $0x3, %eax
movl %eax, %edi
callq 0x2040
movq %rax, -0x92438(%rbp)
jmp 0x6f34
movq -0x92438(%rbp), %rcx
movslq -0xe4(%rbp), %rax
movq %rcx, -0x90(%rbp,%rax,8)
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x6ed5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x7e62
movq -0x92410(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
movl $0x188, %esi            # imm = 0x188
callq 0x2220
jmp 0x7e62
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x7e56
movq -0x10(%rbp), %rdi
callq 0x1f530
movl %eax, -0x9243c(%rbp)
jmp 0x6fc5
movl -0x9243c(%rbp), %eax
decl %eax
shrl $0x3, %eax
incl %eax
movl %eax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f540
movl %eax, -0x92440(%rbp)
jmp 0x6fe9
movl -0x92440(%rbp), %eax
decl %eax
shrl $0x3, %eax
incl %eax
movl %eax, -0xec(%rbp)
movl -0xe8(%rbp), %eax
movl -0xec(%rbp), %ecx
imull %ecx, %eax
movslq %eax, %rdi
callq 0x2040
movq %rax, -0x92448(%rbp)
jmp 0x701c
movq -0x92448(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl $0x0, -0xf0(%rbp)
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0x92450(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f540
movl %eax, -0x9244c(%rbp)
jmp 0x705b
movl -0x92450(%rbp), %eax
movl -0x9244c(%rbp), %ecx
cmpl %ecx, %eax
jge 0x7c01
movl -0xf4(%rbp), %eax
addl $0x8, %eax
movl %eax, -0xf8(%rbp)
movl -0xf8(%rbp), %eax
movl %eax, -0x92458(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f540
movl %eax, -0x92454(%rbp)
jmp 0x709b
movl -0x92458(%rbp), %eax
movl -0x92454(%rbp), %ecx
cmpl %ecx, %eax
jle 0x70c8
movq -0x10(%rbp), %rdi
callq 0x1f540
movl %eax, -0x9245c(%rbp)
jmp 0x70bc
movl -0x9245c(%rbp), %eax
movl %eax, -0xf8(%rbp)
movl $0x0, -0xfc(%rbp)
movl $0x0, -0x100(%rbp)
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
movl %eax, -0x92464(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f530
movl %eax, -0x92460(%rbp)
jmp 0x7103
movl -0x92464(%rbp), %eax
movl -0x92460(%rbp), %ecx
cmpl %ecx, %eax
jge 0x7a5d
movl -0x104(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x108(%rbp)
movl -0x108(%rbp), %eax
movl %eax, -0x9246c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1f530
movl %eax, -0x92468(%rbp)
jmp 0x7143
movl -0x9246c(%rbp), %eax
movl -0x92468(%rbp), %ecx
cmpl %ecx, %eax
jle 0x7170
movq -0x10(%rbp), %rdi
callq 0x1f530
movl %eax, -0x92470(%rbp)
jmp 0x7164
movl -0x92470(%rbp), %eax
movl %eax, -0x108(%rbp)
movl -0x108(%rbp), %eax
subl -0x104(%rbp), %eax
movl %eax, -0x10c(%rbp)
movl $0x0, -0x114(%rbp)
movl $0x0, -0x120(%rbp)
cmpl $0x2, -0x120(%rbp)
jge 0x77de
movl -0x120(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
movl %eax, -0x124(%rbp)
movl $0x0, -0x128(%rbp)
movl -0x128(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x757c
movl $0x0, -0x12c(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0x130(%rbp)
movl -0x130(%rbp), %eax
cmpl -0xf8(%rbp), %eax
jge 0x7566
movl -0x104(%rbp), %eax
movl -0x28(%rbp), %ecx
imull %ecx, %eax
movl -0x128(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x9247c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x130(%rbp), %esi
callq 0x1f5a0
movq %rax, -0x92478(%rbp)
jmp 0x7228
movq -0x92478(%rbp), %rax
movl -0x9247c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
cmpl $0x1, -0x130(%rbp)
jl 0x729b
movl -0x104(%rbp), %eax
movl -0x28(%rbp), %ecx
imull %ecx, %eax
movl -0x128(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x9248c(%rbp)
movq -0x10(%rbp), %rdi
movl -0x130(%rbp), %esi
decl %esi
callq 0x1f5a0
movq %rax, -0x92488(%rbp)
jmp 0x727f
movq -0x92488(%rbp), %rax
movl -0x9248c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x140(%rbp)
jmp 0x72a6
movq $0x0, -0x140(%rbp)
movl -0x104(%rbp), %eax
movl %eax, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x108(%rbp), %eax
jge 0x7550
cmpl $0x0, -0x144(%rbp)
jle 0x72e8
movq -0x138(%rbp), %rax
xorl %ecx, %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x92490(%rbp)
jmp 0x72f2
xorl %eax, %eax
movl %eax, -0x92490(%rbp)
jmp 0x72f2
movl -0x92490(%rbp), %eax
movb %al, -0x145(%rbp)
cmpq $0x0, -0x140(%rbp)
je 0x731a
movq -0x140(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x92494(%rbp)
jmp 0x7324
xorl %eax, %eax
movl %eax, -0x92494(%rbp)
jmp 0x7324
movl -0x92494(%rbp), %eax
movb %al, -0x146(%rbp)
movq -0x138(%rbp), %rax
movb (%rax), %al
movb %al, -0x147(%rbp)
cmpl $0x0, -0x120(%rbp)
jne 0x7463
cmpl $0x0, -0x144(%rbp)
jle 0x737a
cmpq $0x0, -0x140(%rbp)
je 0x737a
movq -0x140(%rbp), %rax
xorl %ecx, %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x92498(%rbp)
jmp 0x7384
xorl %eax, %eax
movl %eax, -0x92498(%rbp)
jmp 0x7384
movl -0x92498(%rbp), %eax
movb %al, -0x149(%rbp)
movzbl -0x145(%rbp), %eax
movzbl -0x146(%rbp), %ecx
cmpl %ecx, %eax
jle 0x73b0
movb -0x146(%rbp), %al
movb %al, -0x92499(%rbp)
jmp 0x73bc
movb -0x145(%rbp), %al
movb %al, -0x92499(%rbp)
movb -0x92499(%rbp), %al
movb %al, -0x14a(%rbp)
movzbl -0x145(%rbp), %eax
movzbl -0x146(%rbp), %ecx
cmpl %ecx, %eax
jge 0x73e8
movb -0x146(%rbp), %al
movb %al, -0x9249a(%rbp)
jmp 0x73f4
movb -0x145(%rbp), %al
movb %al, -0x9249a(%rbp)
movb -0x9249a(%rbp), %al
movb %al, -0x14b(%rbp)
movzbl -0x149(%rbp), %eax
movzbl -0x14b(%rbp), %ecx
cmpl %ecx, %eax
jl 0x7420
movb -0x14a(%rbp), %al
movb %al, -0x148(%rbp)
jmp 0x7461
movzbl -0x149(%rbp), %eax
movzbl -0x14a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x7440
movb -0x14b(%rbp), %al
movb %al, -0x148(%rbp)
jmp 0x745f
movzbl -0x145(%rbp), %eax
movzbl -0x146(%rbp), %ecx
addl %ecx, %eax
movzbl -0x149(%rbp), %ecx
subl %ecx, %eax
movb %al, -0x148(%rbp)
jmp 0x7461
jmp 0x747e
movzbl -0x145(%rbp), %eax
movzbl -0x146(%rbp), %ecx
addl %ecx, %eax
addl $0x1, %eax
sarl %eax
movb %al, -0x148(%rbp)
cmpl $0x0, -0x128(%rbp)
jne 0x7494
movl $0x2, %eax
movl %eax, -0x924a0(%rbp)
jmp 0x74bf
cmpl $0x2, -0x128(%rbp)
jne 0x74a7
xorl %eax, %eax
movl %eax, -0x924a4(%rbp)
jmp 0x74b3
movl -0x128(%rbp), %eax
movl %eax, -0x924a4(%rbp)
movl -0x924a4(%rbp), %eax
movl %eax, -0x924a0(%rbp)
movl -0x924a0(%rbp), %eax
movl %eax, -0x150(%rbp)
movzbl -0x147(%rbp), %eax
movzbl -0x148(%rbp), %ecx
subl %ecx, %eax
movb %al, %dl
movslq -0x150(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movslq -0x12c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
movl -0x28(%rbp), %ecx
movq -0x138(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
cmpq $0x0, -0x140(%rbp)
je 0x753a
movl -0x28(%rbp), %ecx
movq -0x140(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x140(%rbp)
jmp 0x753c
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x72b2
jmp 0x7552
movl -0x130(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x130(%rbp)
jmp 0x71e4
jmp 0x7568
movl -0x128(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x128(%rbp)
jmp 0x71bf
movl $0x0, -0x11c(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0x154(%rbp)
movl -0x154(%rbp), %eax
cmpl -0xf8(%rbp), %eax
jge 0x77c8
movl -0x100(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x75cd
movl -0x154(%rbp), %eax
subl -0xf4(%rbp), %eax
imull -0x10c(%rbp), %eax
movl %eax, -0x158(%rbp)
jmp 0x75e9
movl -0xf8(%rbp), %eax
subl -0x154(%rbp), %eax
subl $0x1, %eax
imull -0x10c(%rbp), %eax
movl %eax, -0x158(%rbp)
movl -0xf8(%rbp), %eax
subl -0xf4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x7619
movl -0x154(%rbp), %eax
movl -0x100(%rbp), %ecx
xorl %ecx, %eax
andb $0x1, %al
negb %al
andb $0x1, %al
movb %al, -0x159(%rbp)
jmp 0x765c
movl -0x100(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7640
movl -0x154(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x159(%rbp)
jmp 0x765a
movl -0x154(%rbp), %eax
movl -0x100(%rbp), %ecx
xorl %ecx, %eax
andb $0x1, %al
negb %al
andb $0x1, %al
movb %al, -0x159(%rbp)
jmp 0x765c
testb $0x1, -0x159(%rbp)
jne 0x770f
movl $0x0, -0x160(%rbp)
movl -0x160(%rbp), %eax
cmpl -0x10c(%rbp), %eax
jge 0x770a
movl $0x0, -0x164(%rbp)
movl -0x164(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x76e7
movslq -0x164(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movl -0x158(%rbp), %ecx
addl -0x160(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movslq -0x164(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movl -0x11c(%rbp), %ecx
addl -0x124(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x164(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x164(%rbp)
jmp 0x768f
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
movl -0x160(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x160(%rbp)
jmp 0x7673
jmp 0x77b2
movl -0x10c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x168(%rbp)
cmpl $0x0, -0x168(%rbp)
jl 0x77b0
movl $0x0, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x778d
movslq -0x16c(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movl -0x158(%rbp), %ecx
addl -0x168(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movslq -0x16c(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movl -0x11c(%rbp), %ecx
addl -0x124(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x16c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16c(%rbp)
jmp 0x7735
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
movl -0x168(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x168(%rbp)
jmp 0x771e
jmp 0x77b2
jmp 0x77b4
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
jmp 0x7592
jmp 0x77ca
movl -0x120(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x120(%rbp)
jmp 0x7196
movl $0x0, -0x170(%rbp)
cmpl $0x2, -0x170(%rbp)
jge 0x78c4
movl -0x170(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
movl %eax, -0x174(%rbp)
movl $0x0, -0x178(%rbp)
cmpl $0x3, -0x24(%rbp)
jl 0x785b
movslq -0x174(%rbp), %rax
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq %rax, %rdi
addq %rax, %rsi
movq -0x50(%rbp), %rdx
addq %rax, %rdx
movl -0x11c(%rbp), %ecx
leaq -0x178(%rbp), %r8
callq 0x6a10
movl %eax, -0x924a8(%rbp)
jmp 0x784d
movl -0x924a8(%rbp), %eax
movl %eax, -0x17c(%rbp)
jmp 0x7865
movl $0x0, -0x17c(%rbp)
cmpl $0x0, -0x170(%rbp)
jne 0x7888
movl -0x178(%rbp), %eax
movl %eax, -0x110(%rbp)
movl -0x17c(%rbp), %eax
movl %eax, -0x118(%rbp)
jmp 0x78ae
movl -0x110(%rbp), %eax
cmpl -0x178(%rbp), %eax
jl 0x78ac
movl $0x1, -0x114(%rbp)
movl -0x17c(%rbp), %eax
movl %eax, -0x118(%rbp)
jmp 0x78ae
jmp 0x78b0
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x77e8
movl $0x0, -0x11c(%rbp)
movl -0x114(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
movl %eax, -0x180(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0x184(%rbp)
movl -0x184(%rbp), %eax
cmpl -0xf8(%rbp), %eax
jge 0x79b8
movl $0x0, -0x188(%rbp)
movl -0x188(%rbp), %eax
cmpl -0x10c(%rbp), %eax
jge 0x79a2
movl $0x0, -0x18c(%rbp)
movl -0x18c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x797f
movslq -0x18c(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movl -0x11c(%rbp), %ecx
addl -0x180(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movslq -0x18c(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movl -0xfc(%rbp), %ecx
addl -0x11c(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x18c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18c(%rbp)
jmp 0x7924
movl -0x11c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x11c(%rbp)
movl -0x188(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x188(%rbp)
jmp 0x7908
jmp 0x79a4
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
jmp 0x78ec
movq -0x90(%rbp), %rdi
movslq -0xfc(%rbp), %rax
addq %rax, %rdi
movq -0x88(%rbp), %rsi
movslq -0xfc(%rbp), %rax
addq %rax, %rsi
movq -0x80(%rbp), %rdx
movslq -0xfc(%rbp), %rax
addq %rax, %rdx
movl -0x11c(%rbp), %ecx
movl -0x118(%rbp), %r8d
callq 0x4c50
movl -0x118(%rbp), %eax
shll %eax
addl -0x114(%rbp), %eax
movb %al, %dl
movq -0xa0(%rbp), %rax
movl -0xf0(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0xf0(%rbp)
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x11c(%rbp), %eax
addl -0xfc(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0x104(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x104(%rbp)
movl -0x100(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x100(%rbp)
jmp 0x70e6
movl $0x0, -0x190(%rbp)
movl -0x190(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x7beb
movslq -0x190(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rsi
movl -0xfc(%rbp), %edx
leaq -0xe0(%rbp), %rdi
callq 0x49d0
jmp 0x7a99
movl $0x0, -0x194(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x1f5d0
movq %rax, -0x924b0(%rbp)
jmp 0x7ab8
movq -0x924b0(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movabsq $0xc0000000, %rax       # imm = 0xC0000000
andq -0x1a0(%rbp), %rax
cmpq $0x0, %rax
je 0x7b44
movl $0x10, %edi
callq 0x20f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x924b8(%rbp)
leaq 0x18c84(%rip), %rsi     # 0x2077f
callq 0x20a0
jmp 0x7b02
movq -0x924b8(%rbp), %rdi
movq 0x1e4e0(%rip), %rsi     # 0x25ff0
movq 0x1e4b1(%rip), %rdx     # 0x25fc8
callq 0x23c0
jmp 0x8088
movq -0x924b8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x2190
jmp 0x7e56
movq -0x40(%rbp), %rax
cmpq -0x1a0(%rbp), %rax
jge 0x7b5c
movq -0x1a0(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x194(%rbp), %eax
shll $0x1e, %eax
cltq
orq -0x1a0(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x1a0(%rbp), %rax
movq %rax, -0x924d0(%rbp)
movq -0xa8(%rbp), %rcx
movq %rcx, -0x924c8(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x924c0(%rbp)
je 0x7bb2
movq -0x924c8(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x924c0(%rbp)
movq -0x924d0(%rbp), %rdi
movq -0x924c0(%rbp), %rsi
callq 0x8090
jmp 0x7bc7
leaq -0xe0(%rbp), %rdi
callq 0x1f5f0
jmp 0x7bd5
jmp 0x7bd7
movl -0x190(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x190(%rbp)
jmp 0x7a67
jmp 0x7bed
movl -0xf4(%rbp), %eax
addl $0x8, %eax
movl %eax, -0xf4(%rbp)
jmp 0x703e
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x8090
jmp 0x7c10
leaq -0x923d0(%rbp), %rdi
callq 0x3f20
jmp 0x7c1e
leaq -0x923d0(%rbp), %rdi
callq 0x8100
jmp 0x7c2c
movl -0xf0(%rbp), %eax
addl %eax, %eax
movslq %eax, %rdi
callq 0x2040
movq %rax, -0x924d8(%rbp)
jmp 0x7c45
movq -0x924d8(%rbp), %rax
movq %rax, -0x923d8(%rbp)
movq -0xa0(%rbp), %rsi
movslq -0xf0(%rbp), %rdx
movq -0x923d8(%rbp), %rcx
leaq -0x923d0(%rbp), %rdi
leaq -0x923e0(%rbp), %r8
callq 0x4400
movq -0x923e0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x8090
jmp 0x7c8d
movq -0x20(%rbp), %rdi
movq -0x923d8(%rbp), %rsi
movq -0x923e0(%rbp), %rdx
callq 0x22d0
jmp 0x7ca6
jmp 0x7d82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x7e2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x20b0
movq -0x923d8(%rbp), %rax
movq %rax, -0x924e0(%rbp)
cmpq $0x0, %rax
je 0x7d00
movq -0x924e0(%rbp), %rdi
callq 0x22c0
movl $0x10, %edi
callq 0x20f0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x924e8(%rbp)
leaq 0x18a79(%rip), %rsi     # 0x20797
callq 0x20a0
jmp 0x7d25
movq -0x924e8(%rbp), %rdi
movq 0x1e2bd(%rip), %rsi     # 0x25ff0
movq 0x1e28e(%rip), %rdx     # 0x25fc8
callq 0x23c0
jmp 0x8088
movq -0x924e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x2190
jmp 0x7d76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x23a0
jmp 0x7d7d
jmp 0x7e2a
movq -0x923d8(%rbp), %rax
movq %rax, -0x924f0(%rbp)
cmpq $0x0, %rax
je 0x7da2
movq -0x924f0(%rbp), %rdi
callq 0x22c0
leaq -0x923d0(%rbp), %rdi
callq 0x40c0
movq -0xa8(%rbp), %rsi
leaq -0x92400(%rbp), %rdi
callq 0x21e0
jmp 0x7dc3
movq -0x20(%rbp), %rax
movq %rax, -0x92500(%rbp)
leaq -0x92400(%rbp), %rdi
movq %rdi, -0x92508(%rbp)
callq 0x2120
movq -0x92508(%rbp), %rdi
movq %rax, -0x924f8(%rbp)
callq 0x2160
movq -0x92500(%rbp), %rdi
movq -0x924f8(%rbp), %rsi
movl %eax, %eax
movl %eax, %edx
callq 0x22d0
jmp 0x7e0d
leaq -0x92400(%rbp), %rdi
callq 0x2130
leaq -0xe0(%rbp), %rdi
callq 0x1f6a0
jmp 0x7f8e
leaq -0x923d0(%rbp), %rdi
callq 0x40c0
jmp 0x7e56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x92400(%rbp), %rdi
callq 0x2130
leaq -0xe0(%rbp), %rdi
callq 0x1f6a0
movq -0xb0(%rbp), %rdi
callq 0x20b0
movl $0x0, -0x92404(%rbp)
cmpl $0x4, -0x92404(%rbp)
jge 0x7f0d
movslq -0x92404(%rbp), %rax
cmpq $0x0, -0x60(%rbp,%rax,8)
je 0x7ebb
movslq -0x92404(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movq %rax, -0x92510(%rbp)
cmpq $0x0, %rax
je 0x7eb9
movq -0x92510(%rbp), %rdi
callq 0x22c0
jmp 0x7ebb
movslq -0x92404(%rbp), %rax
cmpq $0x0, -0x90(%rbp,%rax,8)
je 0x7ef7
movslq -0x92404(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movq %rax, -0x92518(%rbp)
cmpq $0x0, %rax
je 0x7ef5
movq -0x92518(%rbp), %rdi
callq 0x22c0
jmp 0x7ef7
jmp 0x7ef9
movl -0x92404(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x92404(%rbp)
jmp 0x7e78
cmpq $0x0, -0xa0(%rbp)
je 0x7f39
movq -0xa0(%rbp), %rax
movq %rax, -0x92520(%rbp)
cmpq $0x0, %rax
je 0x7f37
movq -0x92520(%rbp), %rdi
callq 0x22c0
jmp 0x7f39
cmpq $0x0, -0xa8(%rbp)
je 0x7f66
movq -0xa8(%rbp), %rax
movq %rax, -0x92528(%rbp)
cmpq $0x0, %rax
je 0x7f64
movq -0x92528(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x7f66
callq 0x2330
jmp 0x8088
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
callq 0x23a0
jmp 0x7f89
jmp 0x8074
movl $0x0, -0x92408(%rbp)
cmpl $0x4, -0x92408(%rbp)
jge 0x8012
movslq -0x92408(%rbp), %rax
cmpq $0x0, -0x60(%rbp,%rax,8)
je 0x7fd7
movslq -0x92408(%rbp), %rax
movq -0x60(%rbp,%rax,8), %rax
movq %rax, -0x92530(%rbp)
cmpq $0x0, %rax
je 0x7fd5
movq -0x92530(%rbp), %rdi
callq 0x22c0
jmp 0x7fd7
movslq -0x92408(%rbp), %rax
movq -0x90(%rbp,%rax,8), %rax
movq %rax, -0x92538(%rbp)
cmpq $0x0, %rax
je 0x7fff
movq -0x92538(%rbp), %rdi
callq 0x22c0
jmp 0x8001
movl -0x92408(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x92408(%rbp)
jmp 0x7f98
cmpq $0x0, -0xa0(%rbp)
je 0x803e
movq -0xa0(%rbp), %rax
movq %rax, -0x92540(%rbp)
cmpq $0x0, %rax
je 0x803c
movq -0x92540(%rbp), %rdi
callq 0x22c0
jmp 0x803e
cmpq $0x0, -0xa8(%rbp)
je 0x806b
movq -0xa8(%rbp), %rax
movq %rax, -0x92548(%rbp)
cmpq $0x0, %rax
je 0x8069
movq -0x92548(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x806b
addq $0x92550, %rsp          # imm = 0x92550
popq %rbp
retq
movq -0xb0(%rbp), %rdi
callq 0x23e0
movq %rax, %rdi
callq 0x1f690
nopl (%rax,%rax)