// File: /workspace/github_c_makefile_star2_O3/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
movl %r9d, %ebp
movq %rcx, 0x20(%rsp)
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, 0x50(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0xa0(%rsp)
movdqa %xmm0, 0x90(%rsp)
movdqa %xmm0, 0x80(%rsp)
movdqa %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, %bpl
movl %eax, 0x5c(%rsp)
cmovel %eax, %r12d
movl %r9d, %eax
andl $0x4, %eax
movl %eax, 0xc(%rsp)
movl %r9d, 0x8(%rsp)
movq %r12, 0x10(%rsp)
jne 0x5f53
addl $-0x4, %r15d
testb $0x8, %bpl
jne 0x5fab
movl %r15d, %ebx
shrl $0x3, %ebx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x5170
movq %rax, %r13
testb $0x10, %bpl
jne 0x6007
cmpl $0x8, %r15d
jb 0x603d
cmpl $0x1, %ebx
adcl $0x0, %ebx
shll $0x3, %ebx
xorl %eax, %eax
movq (%r14,%rax), %rcx
movl %ecx, (%r13,%rax,2)
movq %rcx, 0x4(%r13,%rax,2)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x5f37
jmp 0x603d
addl $-0x4, %r15d
movl %r15d, %r12d
andl $-0x10, %r12d
movq %r12, %rdi
callq 0x5170
movq %rax, %r13
cmpl $0x10, %r15d
jb 0x603d
xorl %eax, %eax
movl 0x4(%r14,%rax), %ecx
bswapl %ecx
movl %ecx, (%r13,%rax)
movl %ecx, 0x4(%r13,%rax)
movl 0x8(%r14,%rax), %ecx
bswapl %ecx
movl %ecx, 0xc(%r13,%rax)
movl (%r14,%rax), %ecx
bswapl %ecx
movl %ecx, 0x8(%r13,%rax)
addq $0x10, %rax
cmpq %rax, %r12
jne 0x5f75
jmp 0x603d
movl %r15d, %eax
movl $0xaaaaaaab, %ebx       # imm = 0xAAAAAAAB
imulq %rax, %rbx
shrq $0x23, %rbx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x5170
movq %rax, %r13
cmpl $0xc, %r15d
jb 0x603d
cmpl $0x1, %ebx
adcl $0x0, %ebx
leaq 0x8(%r14), %rax
shlq $0x4, %rbx
xorl %ecx, %ecx
movq -0x8(%rax), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, (%r13,%rcx)
movl (%rax), %edx
movl %edx, 0x8(%r13,%rcx)
addq $0xc, %rax
addq $0x10, %rcx
cmpq %rcx, %rbx
jne 0x5fe0
jmp 0x603d
cmpl $0x8, %r15d
jb 0x603d
cmpl $0x1, %ebx
adcl $0x0, %ebx
shll $0x3, %ebx
xorl %eax, %eax
movl (%r14,%rax), %ecx
bswapl %ecx
movl %ecx, (%r13,%rax,2)
movl %ecx, 0x4(%r13,%rax,2)
movl 0x4(%r14,%rax), %ecx
bswapl %ecx
movl %ecx, 0x8(%r13,%rax,2)
addq $0x8, %rax
cmpq %rax, %rbx
jne 0x6018
leaq 0x25ff(%rip), %rdx      # 0x8643
leaq 0x70(%rsp), %r12
movl $0x40, %esi
movq %r12, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x50e0
leaq 0x25e3(%rip), %rsi      # 0x864a
movq %r12, %rdi
callq 0x51c0
movq %rax, %r12
movl %r15d, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rax, %rcx
callq 0x5230
movq %r12, %rdi
callq 0x5090
leaq 0x25b9(%rip), %rdi      # 0x864d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x50c0
movl 0x4(%r13), %edi
testl %edi, %edi
je 0x67bf
movl 0x8(%rsp), %eax
notl %eax
shll $0x4, %eax
andl $0x800, %eax            # imm = 0x800
movl %eax, 0x60(%rsp)
cmpl $0x1, 0xc(%rsp)
movl $0x3, %eax
sbbl $0x0, %eax
movl %eax, 0x64(%rsp)
leaq 0x4(%r13), %r12
movq %r13, %r15
xorl %r14d, %r14d
movq $0x0, 0x18(%rsp)
movq $0x0, 0x38(%rsp)
movl 0x8(%r15), %eax
orl 0xc(%rsp), %eax
je 0x67bf
movl 0x8(%rsp), %ebx
movl %ebx, %esi
callq 0x5911
movq %rax, 0x40(%rsp)
testb $0x10, %bl
jne 0x617e
movl (%r12), %eax
movl $0x80fffffc, %ecx       # imm = 0x80FFFFFC
addl %ecx, %eax
cmpl $0xc, %eax
ja 0x617e
movl $0x1003, %ecx           # imm = 0x1003
btl %eax, %ecx
jae 0x617e
cmpl $0x0, 0xc(%rsp)
jne 0x6274
movl 0x8(%r15), %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, %r12
movq %r15, 0x28(%rsp)
movl $0x40, %esi
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
leaq 0x24f9(%rip), %rdx      # 0x8652
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x50e0
movq %rbx, %rdi
movq %r12, %rbx
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
leal 0x1(%r14), %ebp
jmp 0x62c6
movl $0x40, %esi
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
leaq 0x24c7(%rip), %rdx      # 0x8659
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x50e0
movq %rbx, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
btl $0x8, 0x8(%rsp)
movq 0x50(%rsp), %rbx
jb 0x6210
movl 0x8(%r15), %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, %r12
movq %r15, 0x28(%rsp)
movl 0x10(%rsp), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x51a0
movq 0x28(%rsp), %rsi
movl $0x1, %edx
movq %r12, 0x30(%rsp)
movq %r12, %rdi
movq %rbx, %rcx
callq 0x5080
movq $0x0, 0x68(%rsp)
movq 0x18(%rsp), %r12
movl 0x8(%rsp), %ebx
jmp 0x655f
cmpl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %r12
jne 0x64ac
movl 0x8(%r15), %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, 0x30(%rsp)
movq %r15, 0x28(%rsp)
incl %r14d
movq %r14, %rax
shlq $0x4, %rax
movl 0x4(%r13,%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(%r13,%rax), %esi
addl 0x5c(%rsp), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x51a0
jmp 0x64f1
leal 0x1(%r14), %ebp
movq %rbp, %rax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, %rbx
movq %r15, 0x28(%rsp)
movl $0x40, %esi
leaq 0x70(%rsp), %r15
movq %r15, %rdi
leaq 0x23b1(%rip), %rdx      # 0x8659
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x50e0
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
movq 0x10(%rsp), %r12
addl 0x60(%rsp), %r12d
movq 0x50(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x51a0
movq 0x28(%rsp), %rsi
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rcx
callq 0x5080
movq %rbp, %rax
shlq $0x4, %rax
movl 0x4(%r13,%rax), %r8d
cmpl $0x7f000000, %r8d       # imm = 0x7F000000
je 0x646d
movq %r12, 0x10(%rsp)
addq %r13, %rax
movq %rbx, 0x30(%rsp)
movl %ebp, %r12d
testb $0x8, 0x8(%rsp)
jne 0x6332
movl (%rax), %r8d
movl $0xffffff, %ecx         # imm = 0xFFFFFF
andl %ecx, %r8d
leal 0x2(%r14), %ecx
shlq $0x4, %rcx
movl 0x8(%r13,%rcx), %r15d
cmpl $0x0, 0xc(%rsp)
jne 0x6369
movl 0x8(%rax), %ebx
subl %ebx, %r15d
testb $0x2, 0x8(%rsp)
jne 0x63c0
movl $0x40, %esi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
leaq 0x2304(%rip), %rdx      # 0x866b
jmp 0x63d4
movzbl 0x3(%rax), %esi
addl $0x3, %r14d
shlq $0x4, %r14
movl 0x8(%r13,%r14), %eax
movq %r15, 0x38(%rsp)
subl %r15d, %eax
movq %rax, 0x18(%rsp)
movl %r8d, %edi
movl 0x8(%rsp), %edx
callq 0x59e8
movq %rax, %r15
movl $0x40, %esi
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
leaq 0x22ac(%rip), %rdx      # 0x8656
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
jmp 0x63f2
movl $0x40, %esi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
leaq 0x228b(%rip), %rdx      # 0x865f
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x50e0
movq %r15, 0x18(%rsp)
movl %ebx, %eax
movq %rax, 0x38(%rsp)
movq %r14, %rbx
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x224e(%rip), %rsi      # 0x864a
callq 0x51c0
testq %rax, %rax
je 0x67d5
movq %rax, %rbp
movl 0x38(%rsp), %edi
movq 0x30(%rsp), %rbx
addq %rbx, %rdi
movl 0x18(%rsp), %esi
movl $0x1, %edx
movq %rax, %rcx
callq 0x5230
movq %rbp, %rdi
callq 0x5090
testq %r15, %r15
je 0x643f
movq %r15, %rdi
callq 0x5030
leal 0x1(%r12), %ebp
movq %rbp, %rcx
shlq $0x4, %rcx
leaq (%rcx,%r13), %rax
movl 0x4(%r13,%rcx), %r8d
movl %r12d, %r14d
cmpl $0x7f000000, %r8d       # imm = 0x7F000000
jne 0x631d
leal -0x1(%rbp), %r14d
movq 0x10(%rsp), %r12
movq %rbx, %rdi
callq 0x5030
addl $0x2, %r14d
cmpl $0x0, 0xc(%rsp)
cmoveq %rbp, %r14
shlq $0x4, %r14
addl 0x8(%r13,%r14), %r12d
testl $0x7ff, %r12d           # imm = 0x7FF
je 0x64a2
andl $0xfffff800, %r12d      # imm = 0xFFFFF800
addl $0x800, %r12d           # imm = 0x800
movq %r12, 0x10(%rsp)
jmp 0x6791
movl 0x10(%rsp), %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x51a0
incl %r14d
movq %r14, %rbx
shlq $0x4, %rbx
movl 0x8(%r13,%rbx), %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movl 0xc(%r13,%rbx), %ebp
testb $0x3, %bpl
je 0x64ec
andl $-0x4, %ebp
addl $0x4, %ebp
movq 0x50(%rsp), %rbx
movl %ebp, 0x4c(%rsp)
movl %ebp, %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x5080
movl 0x8(%rsp), %ebx
testb %bl, %bl
jns 0x653d
movzwl (%rbp), %eax
movl %eax, 0x4c14(%rip)      # 0xb13c
movl 0x4c(%rsp), %esi
shrl $0x2, %esi
movq %rbp, %rdi
callq 0x5bc6
addw $0x8f3, (%rbp)          # imm = 0x8F3
movq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %rbp, 0x68(%rsp)
movq %rbp, %rdx
movq %r15, %rcx
callq 0x50a0
testl %eax, %eax
jne 0x67fa
leal 0x1(%r14), %ebp
movq %rbp, %rax
shlq $0x4, %rax
movl 0x4(%r13,%rax), %ecx
cmpl $0x7f000000, %ecx       # imm = 0x7F000000
je 0x674d
addq %r13, %rax
movq %r13, 0xb0(%rsp)
movq %rbp, 0x18(%rsp)
movl (%rax), %edx
movl %edx, %ebp
andl $0xffffff, %ebp         # imm = 0xFFFFFF
movl %edx, %r15d
shrl $0x18, %r15d
testb $0x8, %bl
cmovnel %edx, %ebp
cmovnel %ecx, %r15d
cmpl $0x7d, %r15d
jne 0x6618
movl %ebp, %edi
movl $0x7d, %esi
movl %ebx, %edx
callq 0x59e8
movq %rax, %rbp
movl $0x40, %esi
movl %ebx, %r15d
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
leaq 0x210b(%rip), %rdx      # 0x86df
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
addl $0x3, %r14d
testb $0x8, %r15b
jne 0x66d2
movl %r14d, %eax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %r12d
movl %r12d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movq %rax, 0x38(%rsp)
shrl $0x18, %r12d
jmp 0x66de
leal 0x2(%r14), %ecx
shlq $0x4, %rcx
addq %r13, %rcx
cmpl $0x0, 0xc(%rsp)
cmoveq %rax, %rcx
movq %r13, %rax
movl 0x8(%rcx), %r13d
addl 0x64(%rsp), %r14d
shlq $0x4, %r14
movl 0x8(%rax,%r14), %r12d
movq 0x4998(%rip), %rax      # 0xafe0
movq (%rax), %rdi
callq 0x5180
movl %ebp, %edi
movl %r15d, %esi
movl %ebx, %edx
callq 0x59e8
movq %rax, %rbp
movl $0x40, %esi
leaq 0x70(%rsp), %r14
movq %r14, %rdi
leaq 0x1fe3(%rip), %rdx      # 0x8656
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
movq %r14, %rdi
leaq 0x1fb9(%rip), %rsi      # 0x864a
callq 0x51c0
testq %rax, %rax
je 0x67d5
movq %rax, %r15
subl %r13d, %r12d
movq %r13, 0x38(%rsp)
movq 0x30(%rsp), %rax
leaq (%rax,%r13), %rdi
movl $0x1, %edx
movq %r12, %rsi
movq %r15, %rcx
callq 0x5230
movq 0x18(%rsp), %r14
movq 0xb0(%rsp), %r13
jmp 0x6719
leaq 0x22a0(%rip), %rdi      # 0x8979
callq 0x5070
movq %rbx, %rdi
leaq 0x1f62(%rip), %rsi      # 0x864a
callq 0x51c0
testq %rax, %rax
je 0x67d5
movq %rax, %r15
movq 0x38(%rsp), %rcx
movl %ecx, %r8d
shll $0xb, %r8d
movq %rax, %rdi
leaq 0x1fdd(%rip), %rsi      # 0x86ec
movl %r12d, %edx
xorl %eax, %eax
callq 0x5150
movq %r15, %rdi
callq 0x5090
movq %rbp, %rdi
callq 0x5030
leal 0x1(%r14), %ebp
movq %rbp, %rcx
shlq $0x4, %rcx
leaq (%rcx,%r13), %rax
movl 0x4(%r13,%rcx), %ecx
cmpl $0x7f000000, %ecx       # imm = 0x7F000000
movl 0x8(%rsp), %ebx
jne 0x6586
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x675c
callq 0x5030
movq 0x30(%rsp), %rdi
callq 0x5030
movl 0x4c(%rsp), %eax
testb %bl, %bl
js 0x6772
movl 0x28(%rsp), %eax
movq %r12, 0x18(%rsp)
addl 0x10(%rsp), %eax
testl $0x7ff, %eax            # imm = 0x7FF
je 0x678c
andl $0xfffff800, %eax       # imm = 0xFFFFF800
addl $0x800, %eax            # imm = 0x800
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
callq 0x5030
incl %ebp
movq %rbp, %rax
shlq $0x4, %rax
leaq (%rax,%r13), %r15
leaq (%rax,%r13), %r12
addq $0x4, %r12
movl (%r12), %edi
movl %ebp, %r14d
testl %edi, %edi
jne 0x60e9
leaq 0x21ae(%rip), %rdi      # 0x8974
callq 0x5070
movq %r13, %rdi
callq 0x5030
jmp 0x67e8
leaq 0x1e9d(%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 0x1e8c(%rip), %rdi      # 0x868f
xorl %eax, %eax
callq 0x50c0
addl $0x5, %ebp
cmpl $0x7, %ebp
ja 0x6824
movl %ebp, %eax
leaq 0x18ad(%rip), %rcx      # 0x80c8
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
jmp 0x682b
leaq 0x21a6(%rip), %rdi      # 0x89d1
callq 0x5070
movq 0x28(%rsp), %rsi
leaq 0x1e93(%rip), %rdi      # 0x86cf
jmp 0x67e1