// File: Alcaro[P]bridges/arlib/image-png-decode.cpp
// Function: oimage::init_decode_png(arrayview<unsigned char>)
bool oimage::init_decode_png(arrayview<uint8_t> pngdata)
{
	struct pngchunk : public bytestream {
		uint32_t type;
		uint32_t len;
	};
	class pngreader : public bytestream {
	public:
		pngreader(arrayview<uint8_t> bytes) : bytestream(bytes) {}
		
		pngchunk chunk_raw()
		{
			pngchunk ret;
			ret.type = 0; // invalid value, looks like an unrecognized critical chunk and will propagate outwards
			
			if (remaining() < 12) return ret;
			ret.len = u32b();
			
			if (ret.len >= 0x80000000 || remaining()-8 < ret.len) return ret;
			
			uint32_t crc32_actual = crc32(peekbytes(4+ret.len));
			
			ret.type = u32b();
			ret.init(bytes(ret.len));
			
			uint32_t crc32_exp = u32b();
			if (crc32_actual != crc32_exp) ret.type = 0;
			
			return ret;
		}
		
		//Returns the next recognized or critical chunk. (Only tRNS is recognized.)
		pngchunk chunk()
		{
			while (true)
			{
				pngchunk ret = chunk_raw();
				if (ret.type == 0x74524E53) return ret; // tRNS
				if (!(ret.type&0x20000000)) return ret; // critical
			}
		}
	};
	
	
	pngreader reader(pngdata);
	
	if (reader.remaining() < 8 || !reader.signature("\x89PNG\r\n\x1A\n"))
	{
	fail: // putting this up here to avoid 99999 'jump to label foo crosses initialization of bar' errors
		this->storage = NULL; // forcibly deallocate - this can leave this->pixels as a dead pointer, but caller won't use that.
		return false;
	}
	
	pngchunk IHDR = reader.chunk_raw(); // no ancillary chunks allowed before IHDR
	if (IHDR.type != 0x49484452) goto fail; // IHDR must be the first chunk
	if (IHDR.len != 13) goto fail; // the IHDR chunk is always 13 bytes
	
	uint32_t width  = this->width  = IHDR.u32b();
	uint32_t height = this->height = IHDR.u32b();
	
	// Greyscale             - 0
	// Truecolour            - 2
	// Indexed-colour        - 3
	// Greyscale with alpha  - 4
	// Truecolour with alpha - 6
	
	uint8_t bits_per_sample = IHDR.u8();
	uint8_t color_type = IHDR.u8();
	uint8_t comp_meth = IHDR.u8();
	uint8_t filter_meth = IHDR.u8();
	uint8_t interlace_meth = IHDR.u8();
	
	if (width == 0 || height == 0 || width >= 0x80000000 || height >= 0x80000000) goto fail;
	if ((uint64_t)width * height >= 0x80000000 / sizeof(uint32_t)) goto fail; // ensure width*height doesn't overflow
	// huge images will still OOM, but at least they won't corrupt memory
	if (bits_per_sample >= 32 || color_type > 6 || comp_meth != 0 || filter_meth != 0 || interlace_meth > 1) goto fail;
	if (bits_per_sample > 8) goto fail; // bpp=16 is allowed by the png standard, but not by this program
	if (interlace_meth) goto fail; // TODO: implement this
	static const uint32_t bpp_allowed[7] = { 0x68808000, 0x00000000, 0x00808000, 0x68800000, 0x00808000, 0x00000000, 0x00808000 };
	if (!((bpp_allowed[color_type]<<bits_per_sample)&0x80000000)) goto fail; // clear bit - invalid bpp (this also rejects types 1 and 5)
	
	uint32_t palette[256];
	unsigned palettelen = 0;
	
	if (color_type == 3)
	{
		pngchunk PLTE = reader.chunk();
		if (PLTE.type != 0x504C5445) goto fail;
		
		if (PLTE.len == 0 || PLTE.len%3 || PLTE.len/3 > (1u<<bits_per_sample)) goto fail;
		palettelen = PLTE.len/3;
		for (unsigned i=0;i<palettelen;i++)
		{
			// this reads a byte it shouldn't, but it's either previous color or the chunk's type, so not UB
			palette[i] = 0xFF000000 | readu_be32(PLTE.bytes(3).ptr()-1);
		}
	}
	
	bool has_alpha = (color_type >= 4);
	bool has_bool_alpha = false;
	uint32_t transparent = 0; // if you see this value (after filtering), make it transparent
	                          // for rgb, this value is ARGB, A=0xFF
	
	pngchunk tRNS_IDAT = reader.chunk();
	if (tRNS_IDAT.type == 0x504C5445) // PLTE
	{
		if (color_type == 2 || color_type == 6) // it's allowed on those two types
			tRNS_IDAT = reader.chunk();
		//else fall through and let IEND handler whine
	}
	pngchunk IDAT;
	if (!has_alpha && tRNS_IDAT.type == 0x74524E53) // tRNS
	{
		pngchunk tRNS = tRNS_IDAT;
		has_alpha = true;
		
		if (color_type == 0)
		{
			if (tRNS.len != 2) goto fail;
			transparent = tRNS.u16b();
			if (transparent >= 1u<<bits_per_sample) goto fail;
			if (bits_per_sample == 8) transparent = 0xFF000000 + transparent*0x010101;
			has_bool_alpha = true;
		}
		if (color_type == 2)
		{
			if (tRNS.len != 6) goto fail;
			
			uint16_t r = tRNS.u16b();
			uint16_t g = tRNS.u16b();
			uint16_t b = tRNS.u16b();
			
			if ((r|g|b) >= 1<<bits_per_sample) goto fail;
			
			transparent = 0xFF000000 | r<<16 | g<<8 | b;
			has_bool_alpha = true;
		}
		if (color_type == 3)
		{
			if (tRNS.len == 0 || tRNS.len > palettelen) goto fail;
			
			has_bool_alpha = true;
			for (size_t i=0;i<tRNS.len;i++)
			{
				uint8_t newa = tRNS.u8();
				if (newa != 0x00 && newa != 0xFF) has_bool_alpha = false;
				palette[i] = (palette[i]&0x00FFFFFF) | (uint32_t)newa<<24; // extra cast because u8 << 24 is signed
			}
		}
		if (color_type == 4) goto fail;
		if (color_type == 6) goto fail;
		
		IDAT = reader.chunk();
	}
	else IDAT = tRNS_IDAT; // could be neither tRNS or IDAT, in which case the while loop won't enter, and the IEND checker will whine
	
	
	this->stride = sizeof(uint32_t) * width;
	
	int samples_per_px = (0x04021301 >> (color_type*4))&15;
	size_t bytes_per_line_raw = (bits_per_sample*samples_per_px*width + 7)/8;
	
	//+4 and +2 to let filters read outside the image, and to ensure there's enough
	// space to decode and convert the image to the desired output format
	//+7*u32 because the decoder overshoots on low bitdepths
	//unpacking (png -> uint32_t) needs one pixel of buffer, though compiler considerations say minimum one scanline
	//unfiltering needs another scanline of buffer, plus another one must exist in front
	//
	//however, there's another another issue - what scanline size?
	// output must be packed, raw is pngpack+1, unfiltering needs at least pngpack+4
	//the correct offsets are
	//scan_out = width * (3 or 4)
	//scan_packed = whatever+4
	//scan_filtered = whatever+1
	//start_out = 0
	//start_packed = end - height*scan_packed - scan_packed
	//start_filtered = end - height*scan_filtered
	//deinterleaving probably isn't doable in-place at all
	size_t nbytes = max(this->stride, bytes_per_line_raw+4) * (height+2) + sizeof(uint32_t)*7;
	this->storage = xmalloc(nbytes);
	
	this->pixels8 = (uint8_t*)this->storage;
	this->fmt = (has_alpha ? (has_bool_alpha ? ifmt_bargb8888 : ifmt_argb8888) : ifmt_xrgb8888);
	
	uint8_t* inflate_end = (uint8_t*)this->storage + nbytes;
	uint8_t* inflate_start = inflate_end - (bytes_per_line_raw+1)*height;
	
	inflator::zlibhead infl;
	infl.set_output_first(bytesw(inflate_start, inflate_end-inflate_start));
	inflator::ret_t infl_status = inflator::ret_more_input;
	
	while (IDAT.type == 0x49444154 && infl_status == inflator::ret_more_input)
	{
		infl.set_input(IDAT.bytes(IDAT.len), false);
		infl_status = infl.inflate();
		IDAT = reader.chunk_raw(); // all IDAT chunks must be consecutive
	}
	
	if (infl_status == inflator::ret_more_input)
	{
		infl.set_input(NULL, true);
		infl_status = infl.inflate();
	}
	if (infl_status != inflator::ret_done) goto fail;
	if (inflate_start+infl.output_in_last() != inflate_end) goto fail;
	
	pngchunk IEND = IDAT;
	if (IEND.type != 0x49454E44) IEND = reader.chunk(); // ancillary between IDAT and IEND is fine, just discard that
	if (IEND.type != 0x49454E44 || IEND.len != 0) goto fail;
	
	
	if (interlace_meth == 1)
	{
puts("unsupported: Adam7");
goto fail;
	}
	
//for(uint8_t*n=inflate_start;n<inflate_at;n++)printf("%.2X ",*n);
//puts("");
	
	size_t defilter_out_line = 4 + bytes_per_line_raw;
	uint8_t* defilter_start = inflate_end - height*defilter_out_line - defilter_out_line;
	
	if (inflate_start[0] >= 2)
		memset(defilter_start - defilter_out_line, 0, defilter_out_line); // y=-1 is all zeroes
	size_t filter_bpp = (bits_per_sample*samples_per_px + 7)/8;
	if (!image::png_defilter(defilter_start, defilter_out_line, inflate_start, filter_bpp, bytes_per_line_raw, height)) goto fail;
	
	defilter_start += 4; // skip the x=-1 = 0 padding
	
	if(0);
	else if (color_type == 0)
	{
		//treating gray as a palette makes things a fair bit simpler, especially with tRNS handling
		//doing it for bpp=8 means an 1KB table which is boring, but that one doesn't pack multiple pixels in a single byte,
		// so it's easy to put in the non-palette decoder (and there's no other sane way to handle gray+alpha)
		if (bits_per_sample == 1)
		{
			static const uint32_t gray_1bpp[] = { 0xFF000000, 0xFFFFFFFF };
			if (has_alpha) transparent = gray_1bpp[transparent];
			png_unpack_plte<1>(defilter_start, defilter_out_line, gray_1bpp, 2);
		}
		else if (bits_per_sample == 2)
		{
			static const uint32_t gray_2bpp[] = { 0xFF000000, 0xFF555555, 0xFFAAAAAA, 0xFFFFFFFF };
			if (has_alpha) transparent = gray_2bpp[transparent];
			png_unpack_plte<2>(defilter_start, defilter_out_line, gray_2bpp, 4);
		}
		else if (bits_per_sample == 4)
		{
			static const uint32_t gray_4bpp[] = { 0xFF000000, 0xFF111111, 0xFF222222, 0xFF333333,
			                                      0xFF444444, 0xFF555555, 0xFF666666, 0xFF777777,
			                                      0xFF888888, 0xFF999999, 0xFFAAAAAA, 0xFFBBBBBB,
			                                      0xFFCCCCCC, 0xFFDDDDDD, 0xFFEEEEEE, 0xFFFFFFFF };
			if (has_alpha) transparent = gray_4bpp[transparent];
			png_unpack_plte<4>(defilter_start, defilter_out_line, gray_4bpp, 16);
		}
		else /* bits_per_sample == 8 */ png_unpack_rgb<0>(defilter_start, defilter_out_line);
	}
	
	else if (color_type == 2 /* bits_per_sample == 8 */) png_unpack_rgb<2>(defilter_start, defilter_out_line);
	else if (color_type == 3)
	{
		if      (bits_per_sample == 1) { if (!png_unpack_plte<1>(defilter_start, defilter_out_line, palette, palettelen)) goto fail; }
		else if (bits_per_sample == 2) { if (!png_unpack_plte<2>(defilter_start, defilter_out_line, palette, palettelen)) goto fail; }
		else if (bits_per_sample == 4) { if (!png_unpack_plte<4>(defilter_start, defilter_out_line, palette, palettelen)) goto fail; }
		else /* bits_per_sample = 8 */ { if (!png_unpack_plte<8>(defilter_start, defilter_out_line, palette, palettelen)) goto fail; }
	}
	else if (color_type == 4 /* bits_per_sample == 8 */) png_unpack_rgb<4>(defilter_start, defilter_out_line);
	else  /* color_type == 6 && bits_per_sample == 8 */  png_unpack_rgb<6>(defilter_start, defilter_out_line);
	
	if (transparent >= 0xFF000000)
	{
		uint32_t* pixels = (uint32_t*)(uint8_t*)this->storage;
		for (size_t i=0;i<width*height;i++)
		{
			if (pixels[i] == transparent) pixels[i] &= 0x00FFFFFF;
		}
	}
	
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1cb0, %rsp           # imm = 0x1CB0
movq %rsi, -0x308(%rbp)
movq %rdx, -0x300(%rbp)
movq %rdi, -0x310(%rbp)
movq -0x310(%rbp), %rax
movq %rax, -0x1c38(%rbp)
movq -0x308(%rbp), %rax
movq %rax, -0x338(%rbp)
movq -0x300(%rbp), %rax
movq %rax, -0x330(%rbp)
movq -0x338(%rbp), %rsi
movq -0x330(%rbp), %rdx
leaq -0x328(%rbp), %rdi
callq 0x15ab0
leaq -0x328(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2f0(%rbp), %rcx
movq 0x10(%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rcx, %rax
cmpq $0x8, %rax
jb 0x14752
leaq -0x328(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq 0x4f33e(%rip), %rax     # 0x638e1
movq %rax, -0x2a8(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x1c40(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq %rdi, -0x1c48(%rbp)
callq 0x40f0
movq -0x1c48(%rbp), %rsi
movq %rax, %rdx
leaq -0x10(%rbp), %rdi
callq 0x5d70
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, -0x2b8(%rbp)
movq %rax, -0x2b0(%rbp)
leaq -0x2b8(%rbp), %rdi
callq 0x6290
movq -0x1c40(%rbp), %rcx
movq %rcx, -0x290(%rbp)
movq -0x290(%rbp), %rdx
movq 0x10(%rdx), %rcx
movq 0x8(%rdx), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jbe 0x14639
movb $0x0, -0x291(%rbp)
jmp 0x14749
leaq -0x2b8(%rbp), %rdi
callq 0x6290
movq -0x1c40(%rbp), %rcx
movq %rcx, -0x70(%rbp)
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x78(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x5d70
movq -0x68(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x2c8(%rbp)
movq %rax, -0x2c0(%rbp)
movq -0x2b8(%rbp), %rax
movq %rax, -0x2d8(%rbp)
movq -0x2b0(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x2d8(%rbp), %rsi
movq -0x2d0(%rbp), %rdx
leaq -0x2c8(%rbp), %rdi
callq 0x60c0
testb $0x1, %al
jne 0x146be
jmp 0x14742
leaq -0x2b8(%rbp), %rdi
callq 0x6290
movq -0x1c40(%rbp), %rcx
movq %rcx, -0x1b0(%rbp)
movq %rax, -0x1b8(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x1c50(%rbp)
movq 0x8(%rax), %rsi
movq -0x1b8(%rbp), %rdx
leaq -0x1a8(%rbp), %rdi
callq 0x5d70
movq -0x1c50(%rbp), %rax
movq -0x1b8(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x1a8(%rbp), %rcx
movq -0x1a0(%rbp), %rax
movq %rcx, -0x2e8(%rbp)
movq %rax, -0x2e0(%rbp)
movb $0x1, -0x291(%rbp)
jmp 0x14749
movb $0x0, -0x291(%rbp)
testb $0x1, -0x291(%rbp)
jne 0x14774
jmp 0x14754
movq -0x1c38(%rbp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x17020
movb $0x0, -0x2f1(%rbp)
jmp 0x15a90
leaq -0x358(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15af0
cmpl $0x49484452, -0x340(%rbp) # imm = 0x49484452
je 0x14795
jmp 0x14754
cmpl $0xd, -0x33c(%rbp)
je 0x147a0
jmp 0x14754
leaq -0x358(%rbp), %rax
movq %rax, -0x1c60(%rbp)
movq %rax, -0x260(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq $0x4, -0x1f8(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x1c68(%rbp)
movq 0x8(%rax), %rsi
movq -0x1f8(%rbp), %rdx
leaq -0x1e8(%rbp), %rdi
callq 0x5d70
movq -0x1c68(%rbp), %rax
movq -0x1f8(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x1e8(%rbp), %rcx
movq -0x1e0(%rbp), %rax
movq %rcx, -0x270(%rbp)
movq %rax, -0x268(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x62c0
movq -0x1c38(%rbp), %rdx
movq %rax, %rcx
movq -0x1c60(%rbp), %rax
movq %rcx, -0x220(%rbp)
movq -0x220(%rbp), %rcx
movl (%rcx), %ecx
movl %ecx, -0x224(%rbp)
movl -0x224(%rbp), %ecx
bswapl %ecx
movl %ecx, (%rdx)
movl %ecx, -0x35c(%rbp)
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq $0x4, -0x1d8(%rbp)
movq -0x1d0(%rbp), %rax
movq %rax, -0x1c58(%rbp)
movq 0x8(%rax), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0x1c8(%rbp), %rdi
callq 0x5d70
movq -0x1c58(%rbp), %rax
movq -0x1d8(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x1c8(%rbp), %rcx
movq -0x1c0(%rbp), %rax
movq %rcx, -0x288(%rbp)
movq %rax, -0x280(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x62c0
movq -0x1c38(%rbp), %rcx
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x214(%rbp)
movl -0x214(%rbp), %eax
bswapl %eax
movl %eax, 0x4(%rcx)
movl %eax, -0x360(%rbp)
leaq -0x358(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x8(%rcx)
movb (%rax), %al
movb %al, -0x361(%rbp)
leaq -0x358(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x238(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x8(%rcx)
movb (%rax), %al
movb %al, -0x362(%rbp)
leaq -0x358(%rbp), %rax
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x8(%rcx)
movb (%rax), %al
movb %al, -0x363(%rbp)
leaq -0x358(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x8(%rcx)
movb (%rax), %al
movb %al, -0x364(%rbp)
leaq -0x358(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x250(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x8(%rcx)
movb (%rax), %al
movb %al, -0x365(%rbp)
cmpl $0x0, -0x35c(%rbp)
je 0x14a25
cmpl $0x0, -0x360(%rbp)
je 0x14a25
cmpl $0x80000000, -0x35c(%rbp) # imm = 0x80000000
jae 0x14a25
cmpl $0x80000000, -0x360(%rbp) # imm = 0x80000000
jb 0x14a2a
jmp 0x14754
movl -0x35c(%rbp), %eax
movl -0x360(%rbp), %ecx
imulq %rcx, %rax
cmpq $0x20000000, %rax       # imm = 0x20000000
jb 0x14a47
jmp 0x14754
movzbl -0x361(%rbp), %eax
cmpl $0x20, %eax
jge 0x14a83
movzbl -0x362(%rbp), %eax
cmpl $0x6, %eax
jg 0x14a83
movzbl -0x363(%rbp), %eax
cmpl $0x0, %eax
jne 0x14a83
movzbl -0x364(%rbp), %eax
cmpl $0x0, %eax
jne 0x14a83
movzbl -0x365(%rbp), %eax
cmpl $0x1, %eax
jle 0x14a88
jmp 0x14754
movzbl -0x361(%rbp), %eax
cmpl $0x8, %eax
jle 0x14a99
jmp 0x14754
cmpb $0x0, -0x365(%rbp)
je 0x14aa7
jmp 0x14754
movzbl -0x362(%rbp), %eax
movl %eax, %ecx
leaq 0x4eda9(%rip), %rax     # 0x63860
movl (%rax,%rcx,4), %eax
movzbl -0x361(%rbp), %ecx
shll %cl, %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x14ad2
jmp 0x14754
movl $0x0, -0x774(%rbp)
movzbl -0x362(%rbp), %eax
cmpl $0x3, %eax
jne 0x14c50
leaq -0x798(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15ea0
cmpl $0x504c5445, -0x780(%rbp) # imm = 0x504C5445
je 0x14b10
jmp 0x14754
cmpl $0x0, -0x77c(%rbp)
je 0x14b50
movl -0x77c(%rbp), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x14b50
movl -0x77c(%rbp), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movzbl -0x361(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jbe 0x14b55
jmp 0x14754
movl -0x77c(%rbp), %eax
movl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x774(%rbp)
movl $0x0, -0x79c(%rbp)
movl -0x79c(%rbp), %eax
cmpl -0x774(%rbp), %eax
jae 0x14c4e
leaq -0x798(%rbp), %rax
movq %rax, -0x170(%rbp)
movq $0x3, -0x178(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x1c70(%rbp)
movq 0x8(%rax), %rsi
movq -0x178(%rbp), %rdx
leaq -0x168(%rbp), %rdi
callq 0x5d70
movq -0x1c70(%rbp), %rax
movq -0x178(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x168(%rbp), %rcx
movq -0x160(%rbp), %rax
movq %rcx, -0x7b0(%rbp)
movq %rax, -0x7a8(%rbp)
leaq -0x7b0(%rbp), %rdi
callq 0x62c0
addq $-0x1, %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x204(%rbp)
movl -0x204(%rbp), %ecx
bswapl %ecx
orl $0xff000000, %ecx       # imm = 0xFF000000
movl -0x79c(%rbp), %eax
movl %ecx, -0x770(%rbp,%rax,4)
movl -0x79c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x79c(%rbp)
jmp 0x14b74
jmp 0x14c50
movzbl -0x362(%rbp), %eax
cmpl $0x4, %eax
setge %al
andb $0x1, %al
movb %al, -0x7b1(%rbp)
movb $0x0, -0x7b2(%rbp)
movl $0x0, -0x7b8(%rbp)
leaq -0x7d8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15ea0
cmpl $0x504c5445, -0x7c0(%rbp) # imm = 0x504C5445
jne 0x14cfa
movzbl -0x362(%rbp), %eax
cmpl $0x2, %eax
je 0x14cad
movzbl -0x362(%rbp), %eax
cmpl $0x6, %eax
jne 0x14cf8
leaq -0x7f8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15ea0
movq -0x7f8(%rbp), %rax
movq %rax, -0x7d8(%rbp)
movq -0x7f0(%rbp), %rax
movq %rax, -0x7d0(%rbp)
movq -0x7e8(%rbp), %rax
movq %rax, -0x7c8(%rbp)
movq -0x7e0(%rbp), %rax
movq %rax, -0x7c0(%rbp)
jmp 0x14cfa
leaq -0x818(%rbp), %rdi
callq 0x15f00
testb $0x1, -0x7b1(%rbp)
jne 0x15232
cmpl $0x74524e53, -0x7c0(%rbp) # imm = 0x74524E53
jne 0x15232
leaq -0x838(%rbp), %rdi
leaq -0x7d8(%rbp), %rsi
callq 0x15f20
movb $0x1, -0x7b1(%rbp)
movzbl -0x362(%rbp), %eax
cmpl $0x0, %eax
jne 0x14e4c
cmpl $0x2, -0x81c(%rbp)
je 0x14d5b
jmp 0x14754
leaq -0x838(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq $0x2, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x1c78(%rbp)
movq 0x8(%rax), %rsi
movq -0x98(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0x5d70
movq -0x1c78(%rbp), %rax
movq -0x98(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x88(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x62c0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x52(%rbp)
movw -0x52(%rbp), %ax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, -0x7b8(%rbp)
movl -0x7b8(%rbp), %eax
movzbl -0x361(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jb 0x14e24
jmp 0x14754
movzbl -0x361(%rbp), %eax
cmpl $0x8, %eax
jne 0x14e45
imull $0x10101, -0x7b8(%rbp), %eax # imm = 0x10101
addl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, -0x7b8(%rbp)
movb $0x1, -0x7b2(%rbp)
movzbl -0x362(%rbp), %eax
cmpl $0x2, %eax
jne 0x150db
cmpl $0x6, -0x81c(%rbp)
je 0x14e6a
jmp 0x14754
leaq -0x838(%rbp), %rax
movq %rax, -0x1c88(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq $0x2, -0xd0(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x1c98(%rbp)
movq 0x8(%rax), %rsi
movq -0xd0(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x5d70
movq -0x1c98(%rbp), %rax
movq -0xd0(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0xc0(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq %rcx, -0xe8(%rbp)
movq %rax, -0xe0(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x62c0
movq %rax, %rcx
movq -0x1c88(%rbp), %rax
movq %rcx, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movw (%rcx), %cx
movw %cx, -0x42(%rbp)
movw -0x42(%rbp), %cx
rolw $0x8, %cx
movw %cx, -0x83a(%rbp)
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x100(%rbp)
movq $0x2, -0x108(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0x1c90(%rbp)
movq 0x8(%rax), %rsi
movq -0x108(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x5d70
movq -0x1c90(%rbp), %rax
movq -0x108(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0xf8(%rbp), %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0x120(%rbp)
movq %rax, -0x118(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x62c0
movq %rax, %rcx
movq -0x1c88(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movw (%rcx), %cx
movw %cx, -0x32(%rbp)
movw -0x32(%rbp), %cx
rolw $0x8, %cx
movw %cx, -0x83c(%rbp)
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x138(%rbp)
movq $0x2, -0x140(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x1c80(%rbp)
movq 0x8(%rax), %rsi
movq -0x140(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x5d70
movq -0x1c80(%rbp), %rax
movq -0x140(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x130(%rbp), %rcx
movq -0x128(%rbp), %rax
movq %rcx, -0x158(%rbp)
movq %rax, -0x150(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x62c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movw (%rax), %ax
movw %ax, -0x22(%rbp)
movw -0x22(%rbp), %ax
rolw $0x8, %ax
movw %ax, -0x83e(%rbp)
movzwl -0x83a(%rbp), %eax
movzwl -0x83c(%rbp), %ecx
orl %ecx, %eax
movzwl -0x83e(%rbp), %ecx
orl %ecx, %eax
movzbl -0x361(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jl 0x150aa
jmp 0x14754
movzwl -0x83a(%rbp), %eax
shll $0x10, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movzwl -0x83c(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzwl -0x83e(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x7b8(%rbp)
movb $0x1, -0x7b2(%rbp)
movzbl -0x362(%rbp), %eax
cmpl $0x3, %eax
jne 0x151c3
cmpl $0x0, -0x81c(%rbp)
je 0x15102
movl -0x81c(%rbp), %eax
cmpl -0x774(%rbp), %eax
jbe 0x15107
jmp 0x14754
movb $0x1, -0x7b2(%rbp)
movq $0x0, -0x848(%rbp)
movq -0x848(%rbp), %rax
movl -0x81c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x151c1
leaq -0x838(%rbp), %rax
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x8(%rcx)
movb (%rax), %al
movb %al, -0x849(%rbp)
movzbl -0x849(%rbp), %eax
cmpl $0x0, %eax
je 0x1517c
movzbl -0x849(%rbp), %eax
cmpl $0xff, %eax
je 0x1517c
movb $0x0, -0x7b2(%rbp)
movq -0x848(%rbp), %rax
movl -0x770(%rbp,%rax,4), %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
movzbl -0x849(%rbp), %eax
shll $0x18, %eax
orl %eax, %ecx
movq -0x848(%rbp), %rax
movl %ecx, -0x770(%rbp,%rax,4)
movq -0x848(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x848(%rbp)
jmp 0x15119
jmp 0x151c3
movzbl -0x362(%rbp), %eax
cmpl $0x4, %eax
jne 0x151d4
jmp 0x14754
movzbl -0x362(%rbp), %eax
cmpl $0x6, %eax
jne 0x151e5
jmp 0x14754
leaq -0x870(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15ea0
movq -0x870(%rbp), %rax
movq %rax, -0x818(%rbp)
movq -0x868(%rbp), %rax
movq %rax, -0x810(%rbp)
movq -0x860(%rbp), %rax
movq %rax, -0x808(%rbp)
movq -0x858(%rbp), %rax
movq %rax, -0x800(%rbp)
jmp 0x1526a
movq -0x7d8(%rbp), %rax
movq %rax, -0x818(%rbp)
movq -0x7d0(%rbp), %rax
movq %rax, -0x810(%rbp)
movq -0x7c8(%rbp), %rax
movq %rax, -0x808(%rbp)
movq -0x7c0(%rbp), %rax
movq %rax, -0x800(%rbp)
movq -0x1c38(%rbp), %rax
movl -0x35c(%rbp), %ecx
shlq $0x2, %rcx
movl %ecx, 0xc(%rax)
movzbl -0x362(%rbp), %ecx
shll $0x2, %ecx
movl $0x4021301, %edx        # imm = 0x4021301
sarl %cl, %edx
movl %edx, %ecx
andl $0xf, %ecx
movl %ecx, -0x874(%rbp)
movzbl -0x361(%rbp), %ecx
imull -0x874(%rbp), %ecx
imull -0x35c(%rbp), %ecx
addl $0x7, %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
movq %rcx, -0x880(%rbp)
movl 0xc(%rax), %edi
movq -0x880(%rbp), %rsi
addq $0x4, %rsi
callq 0x15f60
movl -0x360(%rbp), %ecx
addl $0x2, %ecx
imull %ecx, %eax
movl %eax, %eax
addq $0x1c, %rax
movq %rax, -0x888(%rbp)
movq -0x888(%rbp), %rdi
callq 0x2d5e0
movq -0x1c38(%rbp), %rdi
movq %rax, -0x890(%rbp)
addq $0x18, %rdi
movq -0x890(%rbp), %rsi
callq 0x17060
movq -0x1c38(%rbp), %rdi
addq $0x18, %rdi
callq 0x170a0
movq %rax, %rcx
movq -0x1c38(%rbp), %rax
movq %rcx, 0x10(%rax)
testb $0x1, -0x7b1(%rbp)
je 0x15359
movb -0x7b2(%rbp), %dl
movl $0x5, %eax
movl $0x8, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x1c9c(%rbp)
jmp 0x15366
movl $0x6, %eax
movl %eax, -0x1c9c(%rbp)
jmp 0x15366
movq -0x1c38(%rbp), %rdi
movl -0x1c9c(%rbp), %eax
movl %eax, 0x8(%rdi)
addq $0x18, %rdi
callq 0x170a0
addq -0x888(%rbp), %rax
movq %rax, -0x898(%rbp)
movq -0x898(%rbp), %rax
movq -0x880(%rbp), %rdx
addq $0x1, %rdx
movl -0x360(%rbp), %ecx
imulq %rcx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x8a0(%rbp)
leaq -0x1b70(%rbp), %rdi
callq 0x170c0
movq -0x8a0(%rbp), %rsi
movq -0x898(%rbp), %rdx
movq -0x8a0(%rbp), %rax
subq %rax, %rdx
leaq -0x1b80(%rbp), %rdi
callq 0x5ed0
leaq -0x1b70(%rbp), %rdi
leaq -0x1b80(%rbp), %rsi
callq 0x170f0
movl $0x2, -0x1b84(%rbp)
xorl %eax, %eax
cmpl $0x49444154, -0x800(%rbp) # imm = 0x49444154
movb %al, -0x1c9d(%rbp)
jne 0x15429
cmpl $0x2, -0x1b84(%rbp)
sete %al
movb %al, -0x1c9d(%rbp)
movb -0x1c9d(%rbp), %al
testb $0x1, %al
jne 0x15438
jmp 0x1552b
movl -0x7fc(%rbp), %eax
leaq -0x818(%rbp), %rcx
movq %rcx, -0x190(%rbp)
movq %rax, -0x198(%rbp)
movq -0x190(%rbp), %rax
movq %rax, -0x1ca8(%rbp)
movq 0x8(%rax), %rsi
movq -0x198(%rbp), %rdx
leaq -0x188(%rbp), %rdi
callq 0x5d70
movq -0x1ca8(%rbp), %rax
movq -0x198(%rbp), %rdx
movq 0x8(%rax), %rcx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x188(%rbp), %rcx
movq -0x180(%rbp), %rax
movq %rcx, -0x1b98(%rbp)
movq %rax, -0x1b90(%rbp)
movq -0x1b98(%rbp), %rsi
movq -0x1b90(%rbp), %rdx
leaq -0x1b70(%rbp), %rdi
xorl %ecx, %ecx
callq 0x17130
leaq -0x1b70(%rbp), %rdi
callq 0x46570
movl %eax, -0x1b84(%rbp)
leaq -0x1bb8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15af0
movq -0x1bb8(%rbp), %rax
movq %rax, -0x818(%rbp)
movq -0x1bb0(%rbp), %rax
movq %rax, -0x810(%rbp)
movq -0x1ba8(%rbp), %rax
movq %rax, -0x808(%rbp)
movq -0x1ba0(%rbp), %rax
movq %rax, -0x800(%rbp)
jmp 0x15405
cmpl $0x2, -0x1b84(%rbp)
jne 0x15575
leaq -0x1bc8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x115f0
movq -0x1bc8(%rbp), %rsi
movq -0x1bc0(%rbp), %rdx
leaq -0x1b70(%rbp), %rdi
movl $0x1, %ecx
callq 0x17130
leaq -0x1b70(%rbp), %rdi
callq 0x46570
movl %eax, -0x1b84(%rbp)
cmpl $0x0, -0x1b84(%rbp)
je 0x15583
jmp 0x14754
movq -0x8a0(%rbp), %rax
movq %rax, -0x1cb0(%rbp)
leaq -0x1b70(%rbp), %rdi
callq 0x17180
movq %rax, %rcx
movq -0x1cb0(%rbp), %rax
addq %rcx, %rax
cmpq -0x898(%rbp), %rax
je 0x155b8
jmp 0x14754
leaq -0x1be8(%rbp), %rdi
leaq -0x818(%rbp), %rsi
callq 0x15f20
cmpl $0x49454e44, -0x1bd0(%rbp) # imm = 0x49454E44
je 0x15622
leaq -0x1c08(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x15ea0
movq -0x1c08(%rbp), %rax
movq %rax, -0x1be8(%rbp)
movq -0x1c00(%rbp), %rax
movq %rax, -0x1be0(%rbp)
movq -0x1bf8(%rbp), %rax
movq %rax, -0x1bd8(%rbp)
movq -0x1bf0(%rbp), %rax
movq %rax, -0x1bd0(%rbp)
cmpl $0x49454e44, -0x1bd0(%rbp) # imm = 0x49454E44
jne 0x15637
cmpl $0x0, -0x1bcc(%rbp)
je 0x1563c
jmp 0x14754
movzbl -0x365(%rbp), %eax
cmpl $0x1, %eax
jne 0x15659
leaq 0x4e29b(%rip), %rdi     # 0x638ea
callq 0x4580
jmp 0x14754
movq -0x880(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1c10(%rbp)
movq -0x898(%rbp), %rax
movl -0x360(%rbp), %ecx
movl %ecx, %edx
imulq -0x1c10(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
xorl %ecx, %ecx
subq -0x1c10(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x1c18(%rbp)
movq -0x8a0(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2, %eax
jl 0x156cd
movq -0x1c18(%rbp), %rdi
xorl %eax, %eax
subq -0x1c10(%rbp), %rax
addq %rax, %rdi
movq -0x1c10(%rbp), %rdx
xorl %esi, %esi
callq 0x4170
movzbl -0x361(%rbp), %eax
imull -0x874(%rbp), %eax
addl $0x7, %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
movq %rax, -0x1c20(%rbp)
movq -0x1c18(%rbp), %rdi
movq -0x1c10(%rbp), %rsi
movq -0x8a0(%rbp), %rdx
movq -0x1c20(%rbp), %rax
movl %eax, %ecx
movq -0x880(%rbp), %r8
movl -0x360(%rbp), %eax
movl %eax, %r9d
callq 0x15fa0
testb $0x1, %al
jne 0x1572b
jmp 0x14754
movq -0x1c18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1c18(%rbp)
movzbl -0x362(%rbp), %eax
cmpl $0x0, %eax
jne 0x15875
movzbl -0x361(%rbp), %eax
cmpl $0x1, %eax
jne 0x157a6
testb $0x1, -0x7b1(%rbp)
je 0x1577a
movl -0x7b8(%rbp), %eax
movl %eax, %ecx
leaq 0x4e10b(%rip), %rax     # 0x6387c
movl (%rax,%rcx,4), %eax
movl %eax, -0x7b8(%rbp)
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq 0x4e0e6(%rip), %rcx     # 0x6387c
movl $0x2, %r8d
callq 0x171a0
jmp 0x15870
movzbl -0x361(%rbp), %eax
cmpl $0x2, %eax
jne 0x157fc
testb $0x1, -0x7b1(%rbp)
je 0x157d3
movl -0x7b8(%rbp), %eax
movl %eax, %ecx
leaq 0x4e0c6(%rip), %rax     # 0x63890
movl (%rax,%rcx,4), %eax
movl %eax, -0x7b8(%rbp)
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq 0x4e0a1(%rip), %rcx     # 0x63890
movl $0x4, %r8d
callq 0x175c0
jmp 0x1586e
movzbl -0x361(%rbp), %eax
cmpl $0x4, %eax
jne 0x15852
testb $0x1, -0x7b1(%rbp)
je 0x15829
movl -0x7b8(%rbp), %eax
movl %eax, %ecx
leaq 0x4e080(%rip), %rax     # 0x638a0
movl (%rax,%rcx,4), %eax
movl %eax, -0x7b8(%rbp)
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq 0x4e05b(%rip), %rcx     # 0x638a0
movl $0x10, %r8d
callq 0x17870
jmp 0x1586c
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
callq 0x17ac0
jmp 0x1586e
jmp 0x15870
jmp 0x159f1
movzbl -0x362(%rbp), %eax
cmpl $0x2, %eax
jne 0x158a0
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
callq 0x17b80
jmp 0x159ef
movzbl -0x362(%rbp), %eax
cmpl $0x3, %eax
jne 0x159a9
movzbl -0x361(%rbp), %eax
cmpl $0x1, %eax
jne 0x158f2
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq -0x770(%rbp), %rcx
movl -0x774(%rbp), %r8d
callq 0x171a0
testb $0x1, %al
jne 0x158ed
jmp 0x14754
jmp 0x159a7
movzbl -0x361(%rbp), %eax
cmpl $0x2, %eax
jne 0x15931
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq -0x770(%rbp), %rcx
movl -0x774(%rbp), %r8d
callq 0x175c0
testb $0x1, %al
jne 0x1592f
jmp 0x14754
jmp 0x159a5
movzbl -0x361(%rbp), %eax
cmpl $0x4, %eax
jne 0x15970
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq -0x770(%rbp), %rcx
movl -0x774(%rbp), %r8d
callq 0x17870
testb $0x1, %al
jne 0x1596e
jmp 0x14754
jmp 0x159a3
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
leaq -0x770(%rbp), %rcx
movl -0x774(%rbp), %r8d
callq 0x17c40
testb $0x1, %al
jne 0x159a1
jmp 0x14754
jmp 0x159a3
jmp 0x159a5
jmp 0x159a7
jmp 0x159ed
movzbl -0x362(%rbp), %eax
cmpl $0x4, %eax
jne 0x159d1
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
callq 0x17e20
jmp 0x159eb
movq -0x1c38(%rbp), %rdi
movq -0x1c18(%rbp), %rsi
movq -0x1c10(%rbp), %rdx
callq 0x17ee0
jmp 0x159ed
jmp 0x159ef
jmp 0x159f1
cmpl $0xff000000, -0x7b8(%rbp) # imm = 0xFF000000
jb 0x15a89
movq -0x1c38(%rbp), %rdi
addq $0x18, %rdi
callq 0x170a0
movq %rax, -0x1c28(%rbp)
movq $0x0, -0x1c30(%rbp)
movq -0x1c30(%rbp), %rax
movl -0x35c(%rbp), %ecx
imull -0x360(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x15a87
movq -0x1c28(%rbp), %rax
movq -0x1c30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x7b8(%rbp), %eax
jne 0x15a71
movq -0x1c28(%rbp), %rax
movq -0x1c30(%rbp), %rcx
movl (%rax,%rcx,4), %edx
andl $0xffffff, %edx         # imm = 0xFFFFFF
movl %edx, (%rax,%rcx,4)
jmp 0x15a73
movq -0x1c30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1c30(%rbp)
jmp 0x15a23
jmp 0x15a89
movb $0x1, -0x2f1(%rbp)
movb -0x2f1(%rbp), %al
andb $0x1, %al
addq $0x1cb0, %rsp           # imm = 0x1CB0
popq %rbp
retq
nopw %cs:(%rax,%rax)