// File: /workspace/github_c_makefile_star2_O1/Joy-Division[P]tools-mgs/dat-extract_enc.c
// Function: processInfoWithStage
void processInfoWithStage(FILE *f, stageinfo info, tocStageEntry stage, unsigned int flags) {
	FILE *o = NULL;
	char outputname[64] = {0};
	char *foldername = NULL, *filename = NULL;
	uint32_t folderhash = 0;
	uint32_t name = 0, extension = 0, offset = 0, size = 0;
	fileinfoverybig *verybigfiles = NULL;
	fileinfobig *bigfiles = NULL;
	fileinfosmall *smallfiles = NULL;
	fileinfo *files = NULL;
	
	unsigned int i, j, dataoffset = stage.offset*0x800, unpackedoffset, toread, numentries;
	long unsigned int towrite;
	
	if(info.size%0x800) dataoffset += info.size + (0x800-(info.size%0x800));
	else dataoffset += info.size;
	
	/* the trial requires a shift in offsets */
	unpackedoffset = (flags & TRIALSTAGE) ? (dataoffset-0x800) : dataoffset;
	
	if(flags & IS_VERYBIGENTRY) {
		verybigfiles = (fileinfoverybig *)info.data;
		numentries = (info.size-4)/16;
		files = malloc(sizeof(fileinfo)*numentries);
		for(i = 0; i < numentries; i++) {
			files[i].hash = bswap_32(verybigfiles[i].hash);
			files[i].extension = bswap_32(verybigfiles[i].hash);
			files[i].compressed = bswap_32(verybigfiles[i].compressed);
			files[i].offset = bswap_32(verybigfiles[i].offset);
		}
	}
	
	else if(flags & IS_BIGENTRY) {
		bigfiles = (fileinfobig *)info.data;
		numentries = (info.size-4)/12;
		files = malloc(sizeof(fileinfo)*numentries);
		for(i = 0; i < numentries; i++) {
			files[i].hash = bigfiles[i].hash;
			files[i].extension = bigfiles[i].extension;
			files[i].offset = bigfiles[i].offset;
		}
	}
			
	else {
		smallfiles = (fileinfosmall *)info.data;
		numentries = (info.size-4)/8;
		files = malloc(sizeof(fileinfo)*numentries);
		if(flags & IS_BIGENDIAN) {
			for(i = 0; i < numentries; i++) {
				files[i].hash = bswap_32(smallfiles[i].hash);
				files[i].extension = bswap_32(smallfiles[i].hash);
				files[i].offset = bswap_32(smallfiles[i].offset);
			}
		}
		else {
			for(i = 0; i < numentries; i++) {
				files[i].hash = smallfiles[i].hash;
				files[i].extension = smallfiles[i].hash;
				files[i].offset = smallfiles[i].offset;
			}
		}
	}
	
	unsigned char *comdata = NULL, *uncomdata = NULL;
	uint32_t *comvalues = NULL;
	
	snprintf(outputname, 64, "%s.hdr", stage.name);
	o = fopen(outputname, "wb");
	fwrite(info.data, info.size-4, 1, o);
	fclose(o);
	
	printf("%s: ", stage.name);
	
	i = 0;
	
	while((files[i].extension && files[i].offset) || ((flags & IS_VERYBIGENTRY) && files[i].extension)) {
		
		folderhash = files[i].extension;
		foldername = getFolderNameFromHash(folderhash, flags);
		
		if(!(flags & GAME_TTS) && ((files[i].extension == 0x7F000010) || (files[i].extension == 0x7F000005) || (files[i].extension == 0x7F000004))) {
			//~ printf("extracting plain...");
			if(flags & IS_VERYBIGENTRY) {
				uncomdata = malloc(files[i+1].offset);
				towrite = files[i+1].offset;
				snprintf(outputname, 64, "%s/%s", stage.name, foldername);
				createDirectory(outputname);
			}
			else {
				uncomdata = malloc(files[i].offset);
				towrite = files[i].offset;
				snprintf(outputname, 64, "%s/", stage.name);
				createDirectory(outputname);
			}
			
			i++;
			
			/* in unencrypted and trial files, this seems to be a thing */
			if(!(flags & ENCRYPTED) && !(flags & GAME_TTS)) unpackedoffset += 0x800;
			
			fseek(f, unpackedoffset, SEEK_SET);
			fread(uncomdata, towrite, 1, f);
			while(files[i].extension != 0x7F000000) {
				if(flags & IS_BIGENTRY) name = files[i].extension;
				else name = files[i].hash & 0x00FFFFFF;
				if(flags & IS_VERYBIGENTRY) {
					extension = files[i].hash >> 24;
					offset = files[i+1].offset;
					size = files[i+2].offset - files[i+1].offset;
					filename = getFileNameFromHashes(name, extension, flags);
				}
				else {
					offset = files[i].offset;
					size = files[i+1].offset - files[i].offset;
				}
				
				if(flags & IS_VERYBIGENTRY) snprintf(outputname, 64, "%s/%s/%s", stage.name, foldername, filename);
				else if(flags & GAME_MGS3) snprintf(outputname, 64, "%s/%05x.psq", stage.name, name);
				else snprintf(outputname, 64, "%s/pk%06x.sdx", stage.name, name);
				if( !(o = fopen( outputname, "wb" ))) {
					printf("Couldnt open file %s\n", outputname);
					return;
				}
				fwrite(uncomdata+offset, size, 1, o);
				fclose(o);
				i++;
				if(filename) {
					free(filename);
					filename = NULL;
				}
			}
			free(uncomdata);
			uncomdata = NULL;
			if(flags & IS_VERYBIGENTRY) unpackedoffset += files[i+1].offset;
			else unpackedoffset += files[i].offset;
			if(unpackedoffset%0x800) unpackedoffset += 0x800-(unpackedoffset%0x800);
		}
		else {
			snprintf(outputname, 64, "%s/%s", stage.name, foldername);
			createDirectory(outputname);
			
			if(flags & COMPRESSED) {
				if(flags & IS_VERYBIGENTRY) {
					fseek(f, unpackedoffset, SEEK_SET);
					
					i++;
					uncomdata = malloc(files[i].offset);
					towrite = files[i].offset;
					if(files[i].compressed%4) toread = files[i].compressed + (4-(files[i].compressed%4));
					else toread = files[i].compressed;
				}
				else {
					uncomdata = malloc(files[i].offset);
					towrite = files[i].offset;
					i++;
					if((files[i].extension&0x00FFFFFF)%4) toread = (files[i].extension&0x00FFFFFF) + (4-((files[i].extension&0x00FFFFFF)%4));
					else toread = (files[i].extension&0x00FFFFFF);
					fseek(f, dataoffset+files[i].offset, SEEK_SET);
				}
				
				comdata = malloc(toread);
				
				comvalues = (uint32_t *)comdata;
				fread(comdata, toread, 1, f);
				
				if(flags & ENCRYPTED) {
					//~ printf("decrypting...");
					key5 = comvalues[0] & 0x0000FFFF;
					decryptContent(comdata, toread/4);
					
					j = comvalues[0] & 0x0000FFFF;
					j += 0x8F3;
					comvalues[0] = (comvalues[0] & 0xFFFF0000) | (j & 0x0000FFFF);
				}
				//~ printf("decompressing...");
				if((j = uncompress(uncomdata, &towrite, comdata, toread)) != Z_OK) {
					printf("\n=====================================couldnt decompress data :");
					switch(j) {
						case Z_MEM_ERROR: {
							printf("memory error\n");
							break;
						}
						case Z_NEED_DICT: {
							printf("need dictionary\n");
							break;
						}
						case Z_DATA_ERROR: {
							printf("input corrupted\n");
							//~ printf("%s\n", strm.msg);
							break;
						}
						case Z_STREAM_ERROR: {
							printf("broken stream\n");
							break;
						}
						case Z_BUF_ERROR: {
							printf("buffer error\n");
							break;
						}
						default: {
							printf("unknown error\n");
							break;
						}
					}
					printf("\ntowrite %08lx\n", towrite);
					return;
				}
				i++;
			}
			else {
				uncomdata = malloc(files[i].offset);
				towrite = files[i].offset;
				fseek(f, unpackedoffset, SEEK_SET);
				fread(uncomdata, towrite, 1, f);
				i++;
			}
			
			//~ printf("extracting decompressed...");
			
			while(files[i].extension != 0x7F000000) {
				if(flags & IS_BIGENTRY) {
					name = files[i].hash;
					extension = files[i].extension;
				}
				else {
					name = files[i].hash & 0x00FFFFFF;
					extension = files[i].hash >> 24;
				}
				
				if(extension == 0x7D) { // slot file
					//~ printf("hash %08x - extension %08x - offset %08x - compressed %08x\n", files[i].hash, files[i].extension, files[i].offset, files[i].compressed);
		//~ printf("%s - i %d\n", stage.name, i);
					//~ printf("encountered subdir\n");
					//~ subdirhash = name;
					// name.slot
					
					filename = getFileNameFromHashes(name, extension, flags);
					
					snprintf(outputname, 64, "%s/%s/%s.txt", stage.name, foldername, filename);
					
					//~ offset = files[i].offset;
					//~ snprintf(outputname, 64, "%s/%s/%06x/", stage.name, foldername, subdirhash);
					//~ createDirectory(outputname);
					//~ snprintf(outputname, 64, "%s/%s/%06x.%02x", stage.name, foldername, name, extension);
					i++;
					// blank
					//~ printf("hash %08x - extension %08x - offset %08x - compressed %08x\n", files[i].hash, files[i].extension, files[i].offset, files[i].compressed);
		//~ printf("%s - i %d\n", stage.name, i);
					/*subdiritems = files[i].offset >> 24;
					subdirsize = files[i].offset & 0x00FFFFFF;*/
					//~ printf("Subdir found: size %06x - items %02x (%d)\n\t%s\n", subdirsize, subdiritems, subdiritems, outputname);
					i++;
					// has group and offset in offset
					//~ printf("hash %08x - extension %08x - offset %08x - compressed %08x\n", files[i].hash, files[i].extension, files[i].offset, files[i].compressed);
					
					
					if(flags & IS_BIGENTRY) {
						printf("!!!UNDEFINED!!!\n");
						//~ name = files[i].hash;
						//~ extension = files[i].extension;
					}
					else {
						offset = files[i].offset & 0x00FFFFFF;
						size = files[i].offset >> 24;
					}
					
					
					if( !(o = fopen( outputname, "wb" ))) {
						printf("Couldnt open file %s\n", outputname);
						return;
					}
					
					fprintf(o, "Info for SLOT file:\nGroupno: %d\nOffset (sectors): 0x%06X\nOffset (bytes): 0x%08X", size, offset, offset*0x800);
					fclose(o);
					
					free(filename);
					filename = NULL;
					i++;
					continue;
				}
				
				if(flags & IS_VERYBIGENTRY) {
					/* this looks like an off by one, gz konani */
					offset = files[i+1].offset;
					size = files[i+2].offset - files[i+1].offset;
				}
				else {
					offset = files[i].offset;
					size = files[i+1].offset - files[i].offset;
				}
				fflush(stdout);
				filename = getFileNameFromHashes(name, extension, flags);
				snprintf(outputname, 64, "%s/%s/%s", stage.name, foldername, filename);
				
				if( !(o = fopen( outputname, "wb" ))) {
					printf("Couldnt open file %s\n", outputname);
					return;
				}
				fwrite(uncomdata+offset, size, 1, o);
				fclose(o);
				free(filename);
				filename = NULL;
				i++;
			}
			if(comdata) free(comdata);
			comdata = NULL;
			comvalues = NULL;
			free(uncomdata);
			uncomdata = NULL;
			if(flags & ENCRYPTED) unpackedoffset += toread;
			else unpackedoffset += towrite;
			if(unpackedoffset%0x800) unpackedoffset += 0x800-(unpackedoffset%0x800);
		}
		free(foldername);
		i++;
	}
	printf("done\n");
	free(files);
	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rcx, 0x18(%rsp)
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
shll $0xb, %r8d
leal 0x7ff(%r15), %eax
movl $0xfffff800, %r12d      # imm = 0xFFFFF800
andl %r12d, %eax
addl %r8d, %eax
addl %eax, %r12d
testb $0x40, %r9b
movl %eax, 0x58(%rsp)
cmovel %eax, %r12d
testb $0x4, %r9b
movl %r9d, 0xc(%rsp)
movq %r12, 0x10(%rsp)
jne 0x5f78
leal -0x4(%r15), %ebp
testb $0x8, %r9b
jne 0x5fd6
movl %r9d, %r12d
movl %ebp, %ebx
shrl $0x3, %ebx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x5160
movq %rax, (%rsp)
testb $0x10, %r12b
jne 0x6030
cmpl $0x8, %ebp
jb 0x6065
cmpl $0x1, %ebx
adcl $0x0, %ebx
shll $0x3, %ebx
xorl %eax, %eax
movq (%rsp), %rdx
movl (%r14,%rax), %ecx
movl %ecx, (%rdx,%rax,2)
movl %ecx, 0x4(%rdx,%rax,2)
movl 0x4(%r14,%rax), %ecx
movl %ecx, 0x8(%rdx,%rax,2)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x5f56
jmp 0x6065
leal -0x4(%r15), %ebx
movl %ebx, %edi
andl $-0x10, %edi
callq 0x5160
movq %rax, (%rsp)
cmpl $0x10, %ebx
jb 0x6065
shrl $0x4, %ebx
cmpl $0x1, %ebx
adcl $0x0, %ebx
shll $0x4, %ebx
xorl %eax, %eax
movq (%rsp), %rdx
movl 0x4(%r14,%rax), %ecx
bswapl %ecx
movl %ecx, (%rdx,%rax)
movl %ecx, 0x4(%rdx,%rax)
movl 0x8(%r14,%rax), %ecx
bswapl %ecx
movl %ecx, 0xc(%rdx,%rax)
movl (%r14,%rax), %ecx
bswapl %ecx
movl %ecx, 0x8(%rdx,%rax)
addq $0x10, %rax
cmpq %rax, %rbx
jne 0x5fa5
jmp 0x6065
movl %ebp, %eax
movl $0xaaaaaaab, %ebx       # imm = 0xAAAAAAAB
imulq %rax, %rbx
shrq $0x23, %rbx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x5160
movq %rax, (%rsp)
cmpl $0xc, %ebp
jb 0x6065
cmpl $0x1, %ebx
adcl $0x0, %ebx
leaq 0x8(%r14), %rax
shlq $0x4, %rbx
xorl %ecx, %ecx
movq (%rsp), %rsi
movl -0x4(%rax), %edx
movl %edx, (%rsi,%rcx)
movl -0x8(%rax), %edx
movl %edx, 0x4(%rsi,%rcx)
movl (%rax), %edx
movl %edx, 0x8(%rsi,%rcx)
addq $0xc, %rax
addq $0x10, %rcx
cmpq %rcx, %rbx
jne 0x600e
jmp 0x6065
cmpl $0x8, %ebp
jb 0x6065
cmpl $0x1, %ebx
adcl $0x0, %ebx
shll $0x3, %ebx
xorl %eax, %eax
movq (%rsp), %rdx
movl (%r14,%rax), %ecx
bswapl %ecx
movl %ecx, (%rdx,%rax,2)
movl %ecx, 0x4(%rdx,%rax,2)
movl 0x4(%r14,%rax), %ecx
bswapl %ecx
movl %ecx, 0x8(%rdx,%rax,2)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x6044
leaq 0x25d7(%rip), %rdx      # 0x8643
leaq 0x70(%rsp), %r12
movl $0x40, %esi
movq %r12, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x50e0
leaq 0x25bb(%rip), %rsi      # 0x864a
movq %r12, %rdi
callq 0x51b0
movq %rax, %r12
addl $-0x4, %r15d
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rcx
callq 0x5220
movq %r12, %rdi
callq 0x5090
leaq 0x258d(%rip), %rdi      # 0x864d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x50c0
movq (%rsp), %rax
movl 0x4(%rax), %edi
testl %edi, %edi
sete %al
movl 0xc(%rsp), %ebx
je 0x67ef
movq (%rsp), %r15
leaq 0x4(%r15), %r12
movl %ebx, %ecx
andl $0x4, %ecx
movl %ebx, %edx
notl %edx
shll $0x4, %edx
andl $0x800, %edx            # imm = 0x800
movl %edx, 0x5c(%rsp)
cmpl $0x1, %ecx
movl $0x3, %edx
sbbl $0x0, %edx
movl %edx, 0x64(%rsp)
shrl $0x2, %ecx
movl %ecx, 0x60(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x28(%rsp)
movq $0x0, 0x40(%rsp)
xorb $0x1, %al
testb %al, 0x60(%rsp)
jne 0x613c
cmpl $0x0, 0x8(%r15)
je 0x67ef
movl %ebx, %esi
callq 0x58e7
movq %rax, 0x38(%rsp)
testb $0x10, %bl
jne 0x61a9
movl (%r12), %eax
movl $0x80fffffc, %ecx       # imm = 0x80FFFFFC
addl %ecx, %eax
cmpl $0xc, %eax
ja 0x61a9
movl $0x1003, %ecx           # imm = 0x1003
btl %eax, %ecx
jae 0x61a9
testb $0x4, %bl
jne 0x6299
movl 0x8(%r15), %r12d
movq %r12, %rdi
callq 0x5160
movq %rax, %r13
movq %r12, 0x20(%rsp)
movl $0x40, %esi
leaq 0x70(%rsp), %r15
movq %r15, %rdi
leaq 0x24ba(%rip), %rdx      # 0x8652
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x50e0
jmp 0x62df
movl $0x40, %esi
leaq 0x70(%rsp), %r12
movq %r12, %rdi
leaq 0x249c(%rip), %rdx      # 0x8659
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %r8
xorl %eax, %eax
callq 0x50e0
movq %r12, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
btl $0x8, %ebx
jb 0x6235
movl 0x8(%r15), %r12d
movq %r12, %rdi
callq 0x5160
movq %rax, %r15
movq %r12, 0x20(%rsp)
movl 0x10(%rsp), %esi
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x5190
movq 0x20(%rsp), %rsi
movl $0x1, %edx
movq %r15, 0x48(%rsp)
movq %r15, %rdi
movq %rbx, %rcx
callq 0x5080
movq $0x0, 0x68(%rsp)
movq 0x28(%rsp), %r13
jmp 0x657f
testb $0x4, %bl
jne 0x64bf
movl 0x8(%r15), %r12d
movq %r12, %rdi
callq 0x5160
movq %rax, 0x48(%rsp)
movq %r12, 0x20(%rsp)
incl %r14d
movq %r14, %rax
shlq $0x4, %rax
movq (%rsp), %rsi
movl 0x4(%rsi,%rax), %ecx
movl %ecx, %edx
andl $0xffffff, %edx         # imm = 0xFFFFFF
andl $0x3, %ecx
movl %edx, %ebp
subl %ecx, %ebp
addl $0x4, %ebp
testl %ecx, %ecx
cmovel %edx, %ebp
movl 0x8(%rsi,%rax), %esi
addl 0x58(%rsp), %esi
movq 0x30(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x5190
jmp 0x650e
leal 0x1(%r14), %eax
shlq $0x4, %rax
movq (%rsp), %rcx
movl 0x8(%rcx,%rax), %r12d
movq %r12, %rdi
callq 0x5160
movq %rax, %r13
movq %r12, 0x20(%rsp)
movl $0x40, %esi
leaq 0x70(%rsp), %r15
movq %r15, %rdi
leaq 0x238b(%rip), %rdx      # 0x8659
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %r8
xorl %eax, %eax
callq 0x50e0
movq 0x30(%rsp), %rbx
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
movq 0x10(%rsp), %rsi
addl 0x5c(%rsp), %esi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
xorl %edx, %edx
callq 0x5190
movq 0x20(%rsp), %rsi
movl $0x1, %edx
movq %r13, %rdi
movq %rbx, %rcx
callq 0x5080
leal 0x1(%r14), %ebx
movq %rbx, %rax
shlq $0x4, %rax
movq (%rsp), %rcx
movl 0x4(%rcx,%rax), %r12d
cmpl $0x7f000000, %r12d      # imm = 0x7F000000
jne 0x6343
movq %rbx, %r15
jmp 0x647e
addq (%rsp), %rax
movl 0xc(%rsp), %ebx
testb $0x8, %bl
jne 0x635b
movl (%rax), %r12d
movl $0xffffff, %ecx         # imm = 0xFFFFFF
andl %ecx, %r12d
leal 0x2(%r14), %r15d
movq %r15, %rcx
shlq $0x4, %rcx
movq (%rsp), %rdx
movl 0x8(%rdx,%rcx), %ecx
testb $0x4, %bl
jne 0x6386
movl 0x8(%rax), %eax
subl %eax, %ecx
movq %rcx, 0x28(%rsp)
xorl %ebp, %ebp
movq %rax, 0x40(%rsp)
jmp 0x63b3
movzbl 0x3(%rax), %esi
leal 0x3(%r14), %eax
shlq $0x4, %rax
movq (%rsp), %rdx
movl 0x8(%rdx,%rax), %eax
movq %rcx, 0x40(%rsp)
subl %ecx, %eax
movq %rax, 0x28(%rsp)
movl %r12d, %edi
movl %ebx, %edx
callq 0x59be
movq %rax, %rbp
movl $0x40, %esi
testb $0x4, %bl
jne 0x63d0
leaq 0x70(%rsp), %rdi
testb $0x2, %bl
jne 0x63f5
leaq 0x229d(%rip), %rdx      # 0x866b
jmp 0x63fc
leaq 0x70(%rsp), %r12
movq %r12, %rdi
leaq 0x2277(%rip), %rdx      # 0x8656
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x50e0
jmp 0x640e
leaq 0x2263(%rip), %rdx      # 0x865f
movq 0x18(%rsp), %rcx
movl %r12d, %r8d
movq %rdi, %r12
xorl %eax, %eax
callq 0x50e0
movq %r12, %rdi
leaq 0x2232(%rip), %rsi      # 0x864a
callq 0x51b0
testq %rax, %rax
je 0x6806
movq %rax, %r12
movl 0x40(%rsp), %edi
addq %r13, %rdi
movl 0x28(%rsp), %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x5220
movq %r12, %rdi
callq 0x5090
testq %rbp, %rbp
je 0x6456
movq %rbp, %rdi
callq 0x5030
movq %r15, %rcx
shlq $0x4, %rcx
movq (%rsp), %rdx
leaq (%rdx,%rcx), %rax
movl 0x4(%rdx,%rcx), %r12d
incl %r14d
cmpl $0x7f000000, %r12d      # imm = 0x7F000000
jne 0x634b
leal 0x1(%r14), %ebx
movq %r13, %rdi
callq 0x5030
addl $0x2, %r14d
testb $0x4, 0xc(%rsp)
cmoveq %r15, %r14
shlq $0x4, %r14
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
addl 0x8(%rcx,%r14), %eax
testl $0x7ff, %eax            # imm = 0x7FF
je 0x67b1
andl $0xfffff800, %eax       # imm = 0xFFFFF800
addl $0x800, %eax            # imm = 0x800
jmp 0x67b1
movl 0x10(%rsp), %esi
movq 0x30(%rsp), %rdi
xorl %edx, %edx
callq 0x5190
incl %r14d
movq %r14, %rbx
shlq $0x4, %rbx
movq (%rsp), %r15
movl 0x8(%r15,%rbx), %r12d
movq %r12, %rdi
callq 0x5160
movq %rax, 0x48(%rsp)
movq %r12, 0x20(%rsp)
movl 0xc(%r15,%rbx), %ebp
testb $0x3, %bpl
je 0x6505
andl $-0x4, %ebp
addl $0x4, %ebp
movl 0xc(%rsp), %ebx
movq 0x30(%rsp), %r15
movl %ebp, 0x54(%rsp)
movl %ebp, %r12d
movq %r12, %rdi
callq 0x5160
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0x5080
testb %bl, %bl
jns 0x6558
movzwl (%r13), %eax
movl %eax, 0x4bfa(%rip)      # 0xb13c
movl 0x54(%rsp), %esi
shrl $0x2, %esi
movq %r13, %rdi
callq 0x5bd5
addw $0x8f3, (%r13)          # imm = 0x8F3
movq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r13, 0x68(%rsp)
movq %r13, %rdx
movq %r12, %rcx
callq 0x50a0
testl %eax, %eax
movq 0x28(%rsp), %r13
jne 0x682b
leal 0x1(%r14), %ebx
movq %rbx, %rax
shlq $0x4, %rax
movq (%rsp), %rcx
movl 0x4(%rcx,%rax), %ecx
cmpl $0x7f000000, %ecx       # imm = 0x7F000000
je 0x676c
addq (%rsp), %rax
movl (%rax), %edx
movl %edx, %ebp
andl $0xffffff, %ebp         # imm = 0xFFFFFF
movl %edx, %r12d
shrl $0x18, %r12d
movl 0xc(%rsp), %r15d
testb $0x8, %r15b
cmovnel %edx, %ebp
cmovnel %ecx, %r12d
cmpl $0x7d, %r12d
jne 0x6637
movl %ebp, %edi
movl $0x7d, %esi
movl %r15d, %edx
callq 0x59be
movq %rax, %rbp
movl $0x40, %esi
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
leaq 0x20f0(%rip), %rdx      # 0x86df
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
addl $0x3, %r14d
testb $0x8, %r15b
jne 0x66f2
movl %r14d, %eax
shlq $0x4, %rax
movq (%rsp), %rcx
movl 0x8(%rcx,%rax), %r13d
movl %r13d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movq %rax, 0x40(%rsp)
shrl $0x18, %r13d
jmp 0x66fe
movq %rbx, 0x28(%rsp)
leal 0x2(%r14), %ecx
shlq $0x4, %rcx
movq (%rsp), %rdx
addq %rdx, %rcx
testb $0x4, %r15b
cmoveq %rax, %rcx
movl 0x8(%rcx), %r13d
addl 0x64(%rsp), %r14d
shlq $0x4, %r14
movl 0x8(%rdx,%r14), %ebx
movq 0x4974(%rip), %rax      # 0xafe0
movq (%rax), %rdi
callq 0x5170
movl %ebp, %edi
movl %r12d, %esi
movl %r15d, %edx
callq 0x59be
movq %rax, %rbp
movl $0x40, %esi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
leaq 0x1fbe(%rip), %rdx      # 0x8656
movq 0x18(%rsp), %rcx
movq 0x38(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
movq %r14, %rdi
leaq 0x1f94(%rip), %rsi      # 0x864a
callq 0x51b0
testq %rax, %rax
je 0x6806
movq %rax, %r12
subl %r13d, %ebx
movq %r13, 0x40(%rsp)
movq 0x48(%rsp), %rax
leaq (%rax,%r13), %rdi
movl $0x1, %edx
movq %rbx, %rsi
movq %r12, %rcx
callq 0x5220
movq 0x28(%rsp), %r14
movq %rbx, %r13
jmp 0x6739
leaq 0x2280(%rip), %rdi      # 0x8979
callq 0x5070
movq %rbx, %rdi
leaq 0x1f42(%rip), %rsi      # 0x864a
callq 0x51b0
testq %rax, %rax
je 0x6806
movq %rax, %r12
movq 0x40(%rsp), %rcx
movl %ecx, %r8d
shll $0xb, %r8d
movq %rax, %rdi
leaq 0x1fbd(%rip), %rsi      # 0x86ec
movl %r13d, %edx
xorl %eax, %eax
callq 0x5140
movq %r12, %rdi
callq 0x5090
movq %rbp, %rdi
callq 0x5030
leal 0x1(%r14), %ebx
movq %rbx, %rcx
shlq $0x4, %rcx
movq (%rsp), %rdx
leaq (%rdx,%rcx), %rax
movl 0x4(%rdx,%rcx), %ecx
cmpl $0x7f000000, %ecx       # imm = 0x7F000000
jne 0x65a2
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x677b
callq 0x5030
movq 0x48(%rsp), %rdi
callq 0x5030
movl 0x54(%rsp), %eax
cmpb $0x0, 0xc(%rsp)
movq 0x10(%rsp), %rcx
js 0x6799
movl 0x20(%rsp), %eax
addl %ecx, %eax
testl $0x7ff, %eax            # imm = 0x7FF
movq %r13, 0x28(%rsp)
je 0x67b1
andl $0xfffff800, %eax       # imm = 0xFFFFF800
addl $0x800, %eax            # imm = 0x800
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rdi
callq 0x5030
incl %ebx
movq %rbx, %rax
shlq $0x4, %rax
movq (%rsp), %rcx
leaq (%rcx,%rax), %r15
leaq (%rcx,%rax), %r12
addq $0x4, %r12
movl (%r12), %edi
movl %ebx, %r14d
testl %edi, %edi
sete %al
movl 0xc(%rsp), %ebx
jne 0x6129
leaq 0x217e(%rip), %rdi      # 0x8974
callq 0x5070
movq (%rsp), %rdi
callq 0x5030
jmp 0x6819
leaq 0x1e6c(%rip), %rdi      # 0x8679
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x50c0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ebp
leaq 0x1e5b(%rip), %rdi      # 0x868f
xorl %eax, %eax
callq 0x50c0
addl $0x5, %ebp
cmpl $0x7, %ebp
ja 0x6855
movl %ebp, %eax
leaq 0x187c(%rip), %rcx      # 0x80c8
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
jmp 0x685c
leaq 0x2175(%rip), %rdi      # 0x89d1
callq 0x5070
movq 0x20(%rsp), %rsi
leaq 0x1e62(%rip), %rdi      # 0x86cf
jmp 0x6812