// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, 0x38(%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, %ecx       # imm = 0xFFFFF800
andl %ecx, %eax
addl %r8d, %eax
addl %eax, %ecx
testb $0x40, %bpl
movl %eax, 0x64(%rsp)
cmovel %eax, %ecx
movl %r9d, %eax
andl $0x4, %eax
movl %eax, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
jne 0x5ec0
addl $-0x4, %r15d
testb $0x8, %bpl
jne 0x5f13
movl %r15d, %ebx
shrl $0x3, %ebx
movq %rbx, %rdi
shlq $0x4, %rdi
callq 0x5170
movq %rax, %r13
shll $0x3, %ebx
xorl %eax, %eax
testb $0x10, %bpl
jne 0x5e95
cmpq %rax, %rbx
je 0x5f5c
movq (%r14,%rax), %rcx
movl %ecx, (%r13,%rax,2)
movq %rcx, 0x4(%r13,%rax,2)
addq $0x8, %rax
jmp 0x5e78
cmpq %rax, %rbx
je 0x5f5c
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
jmp 0x5e95
addl $-0x4, %r15d
movl %r15d, %ebx
andl $-0x10, %ebx
movq %rbx, %rdi
callq 0x5170
movq %rax, %r13
xorl %eax, %eax
cmpq %rax, %rbx
je 0x5f0a
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
jmp 0x5ed7
testb $0x8, %bpl
sete %al
jmp 0x5f5e
xorl %r12d, %r12d
pushq $0xc
popq %rcx
movl %r15d, %eax
xorl %edx, %edx
divl %ecx
movl %eax, %ebx
shlq $0x4, %rbx
movq %rbx, %rdi
callq 0x5170
movq %rax, %r13
leaq 0x8(%r14), %rax
cmpq %r12, %rbx
je 0x5f64
movq -0x8(%rax), %xmm0
pshufd $0xe1, %xmm0, %xmm0     # xmm0 = xmm0[1,0,2,3]
movq %xmm0, (%r13,%r12)
movl (%rax), %ecx
movl %ecx, 0x8(%r13,%r12)
addq $0x10, %r12
addq $0xc, %rax
jmp 0x5f35
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x5f6c
movl $0x0, 0xc(%rsp)
leaq 0x26d0(%rip), %rdx      # 0x8643
leaq 0x70(%rsp), %rbx
pushq $0x40
popq %rsi
movq %rbx, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rcx
xorl %eax, %eax
callq 0x50e0
leaq 0x26b6(%rip), %rsi      # 0x864a
movq %rbx, %rdi
callq 0x51c0
movq %rax, %rbx
movl %r15d, %esi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rcx
callq 0x5230
movq %rbx, %rdi
callq 0x5090
leaq 0x268e(%rip), %rdi      # 0x864d
movq %r12, %rsi
xorl %eax, %eax
callq 0x50c0
movl %ebp, %eax
notl %eax
shll $0x4, %eax
andl $0x800, %eax            # imm = 0x800
movl %eax, 0x68(%rsp)
cmpl $0x1, 0x8(%rsp)
pushq $0x3
popq %rax
sbbl $0x0, %eax
movl %eax, 0x6c(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x30(%rsp)
xorl %r14d, %r14d
movl %ebp, 0x2c(%rsp)
movl %r14d, %r15d
shlq $0x4, %r15
movl 0x4(%r13,%r15), %edi
testl %edi, %edi
je 0x664e
addq %r13, %r15
movl 0x8(%r15), %eax
orl 0x8(%rsp), %eax
je 0x664e
movl %ebp, %esi
callq 0x58a4
movq %rax, 0x40(%rsp)
testb $0x10, %bpl
jne 0x6094
movl 0x4(%r15), %eax
movl $0x80fffffc, %ecx       # imm = 0x80FFFFFC
addl %ecx, %eax
cmpl $0xc, %eax
ja 0x6094
movl $0x1003, %ecx           # imm = 0x1003
btl %eax, %ecx
jae 0x6094
cmpl $0x0, 0x8(%rsp)
leaq 0x70(%rsp), %r12
jne 0x6178
movl 0x8(%r15), %ebx
movq %rbx, %rdi
callq 0x5170
movq %rax, %r15
movq %rbx, 0x20(%rsp)
movq %r12, %rdi
pushq $0x40
popq %rsi
leaq 0x25cf(%rip), %rdx      # 0x8652
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x50e0
jmp 0x61b3
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
pushq $0x40
popq %rsi
leaq 0x25b3(%rip), %rdx      # 0x8659
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x50e0
movq %rbx, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
btl $0x8, %ebp
movl 0x10(%rsp), %ebx
jb 0x6114
movl 0x8(%r15), %r15d
movq %r15, %rdi
callq 0x5170
movq %rax, %r12
movq %r15, 0x20(%rsp)
movq 0x38(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x51a0
movq 0x20(%rsp), %rsi
movq %r12, 0x48(%rsp)
movq %r12, %rdi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x5080
xorl %r12d, %r12d
jmp 0x640e
cmpl $0x0, 0x8(%rsp)
jne 0x6364
movl 0x8(%r15), %ebx
movq %rbx, %rdi
callq 0x5170
movq %rax, 0x48(%rsp)
movq %rbx, 0x20(%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, %ebx
subl %ecx, %ebx
addl $0x4, %ebx
testl %ecx, %ecx
cmovel %edx, %ebx
movl 0x8(%r13,%rax), %esi
addl 0x64(%rsp), %esi
movq 0x38(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x51a0
jmp 0x63a9
leal 0x1(%r14), %eax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %ebx
movq %rbx, %rdi
callq 0x5170
movq %rax, %r15
movq %rbx, 0x20(%rsp)
movq %r12, %rdi
pushq $0x40
popq %rsi
leaq 0x24b7(%rip), %rdx      # 0x8659
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x50e0
movq %r12, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5060
movq 0x10(%rsp), %rsi
addl 0x68(%rsp), %esi
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
xorl %edx, %edx
callq 0x51a0
movq 0x20(%rsp), %rsi
movq %r15, %r12
movq %r15, %rdi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x5080
addl $0x3, %r14d
movl %r14d, %r15d
leal -0x2(%r15), %r14d
movq %r14, %rax
shlq $0x4, %rax
leaq (%rax,%r13), %rbx
movl 0x4(%r13,%rax), %r8d
cmpl $0x7f000000, %r8d       # imm = 0x7F000000
je 0x6327
cmpb $0x0, 0xc(%rsp)
je 0x622d
movl (%rbx), %r8d
movl $0xffffff, %eax         # imm = 0xFFFFFF
andl %eax, %r8d
leal -0x1(%r15), %eax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %r14d
cmpl $0x0, 0x8(%rsp)
jne 0x6261
movl 0x8(%rbx), %ebx
subl %ebx, %r14d
testb $0x2, %bpl
jne 0x62ae
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
pushq $0x40
popq %rsi
leaq 0x240c(%rip), %rdx      # 0x866b
jmp 0x62c0
movzbl 0x3(%rbx), %esi
movl %r15d, %eax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %eax
subl %r14d, %eax
movq %rax, 0x30(%rsp)
movl %r8d, %edi
movl %ebp, %edx
callq 0x5979
movq %rax, %rbx
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
pushq $0x40
popq %rsi
leaq 0x23be(%rip), %rdx      # 0x8656
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
jmp 0x62d6
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
pushq $0x40
popq %rsi
leaq 0x239f(%rip), %rdx      # 0x865f
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x50e0
movq %r14, 0x30(%rsp)
movl %ebx, %r14d
xorl %ebx, %ebx
movq %rbp, %rdi
leaq 0x236a(%rip), %rsi      # 0x864a
callq 0x51c0
testq %rax, %rax
je 0x6629
movq %rax, %rbp
movq %r14, 0x58(%rsp)
movl %r14d, %edi
addq %r12, %rdi
movl 0x30(%rsp), %esi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x5230
movq %rbp, %rdi
callq 0x5090
movq %rbx, %rdi
callq 0x5030
incl %r15d
movl 0x2c(%rsp), %ebp
jmp 0x61fa
movq %r12, %rdi
callq 0x5030
decl %r15d
shlq $0x4, %r15
addq %r13, %r15
cmpl $0x0, 0x8(%rsp)
cmoveq %rbx, %r15
movq 0x10(%rsp), %rax
addl 0x8(%r15), %eax
testw $0x7ff, %ax             # imm = 0x7FF
je 0x6612
andl $0xfffff800, %eax       # imm = 0xFFFFF800
addl $0x800, %eax            # imm = 0x800
jmp 0x6612
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x51a0
incl %r14d
movq %r14, %r15
shlq $0x4, %r15
movl 0x8(%r13,%r15), %ebx
movq %rbx, %rdi
callq 0x5170
movq %rax, 0x48(%rsp)
movq %rbx, 0x20(%rsp)
movl 0xc(%r13,%r15), %ebx
testb $0x3, %bl
je 0x63a4
andl $-0x4, %ebx
addl $0x4, %ebx
movq 0x38(%rsp), %r15
movl %ebx, 0x54(%rsp)
movl %ebx, %ebx
movq %rbx, %rdi
callq 0x5170
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x5080
testb %bpl, %bpl
jns 0x63f1
movzwl (%r12), %eax
movl %eax, 0x4d61(%rip)      # 0xb13c
movl 0x54(%rsp), %esi
shrl $0x2, %esi
movq %r12, %rdi
callq 0x5b3c
addw $0x8f3, (%r12)          # imm = 0x8F3
movq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x50a0
testl %eax, %eax
jne 0x6664
movq %r12, 0xb0(%rsp)
movl %r14d, %ebp
leal 0x1(%rbp), %r14d
movq %r14, %rax
shlq $0x4, %rax
movl 0x4(%r13,%rax), %ebx
cmpl $0x7f000000, %ebx       # imm = 0x7F000000
je 0x65d6
addq %r13, %rax
movl (%rax), %ecx
movl %ecx, %r15d
andl $0xffffff, %r15d        # imm = 0xFFFFFF
movl %ecx, %edx
shrl $0x18, %edx
movl 0xc(%rsp), %r12d
testb %r12b, %r12b
cmovel %ecx, %r15d
cmovnel %edx, %ebx
cmpl $0x7d, %ebx
jne 0x64c0
movl %r15d, %edi
pushq $0x7d
popq %rsi
movl 0x2c(%rsp), %edx
callq 0x5979
movq %rax, %r15
leaq 0x70(%rsp), %rdi
pushq $0x40
popq %rsi
leaq 0x2261(%rip), %rdx      # 0x86df
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
addl $0x3, %ebp
testb %r12b, %r12b
je 0x656e
movl %ebp, %eax
shlq $0x4, %rax
movl 0x8(%r13,%rax), %eax
movl %eax, %r14d
andl $0xffffff, %r14d        # imm = 0xFFFFFF
shrl $0x18, %eax
movq %rax, 0x30(%rsp)
jmp 0x657f
leal 0x2(%rbp), %ecx
shlq $0x4, %rcx
addq %r13, %rcx
cmpl $0x0, 0x8(%rsp)
cmoveq %rax, %rcx
movl 0x8(%rcx), %r12d
addl 0x6c(%rsp), %ebp
shlq $0x4, %rbp
movl 0x8(%r13,%rbp), %ebp
movq 0x4af5(%rip), %rax      # 0xafe0
movq (%rax), %rdi
callq 0x5180
movl %r15d, %edi
movl %ebx, %esi
movl 0x2c(%rsp), %edx
callq 0x5979
movq %rax, %r15
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
pushq $0x40
popq %rsi
leaq 0x2140(%rip), %rdx      # 0x8656
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x50e0
movq %rbx, %rdi
leaq 0x2116(%rip), %rsi      # 0x864a
callq 0x51c0
testq %rax, %rax
je 0x6629
movq %rax, %rbx
subl %r12d, %ebp
movq %r12, 0x58(%rsp)
movq 0x48(%rsp), %rax
leaq (%rax,%r12), %rdi
movq %rbp, 0x30(%rsp)
movq %rbp, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x5230
movl %r14d, %ebp
jmp 0x65c1
leaq 0x2404(%rip), %rdi      # 0x8979
callq 0x5070
movq 0x58(%rsp), %r14
leaq 0x70(%rsp), %rdi
leaq 0x20bf(%rip), %rsi      # 0x864a
callq 0x51c0
testq %rax, %rax
je 0x6629
movq %rax, %rbx
movl %r14d, %r8d
shll $0xb, %r8d
movq %rax, %rdi
leaq 0x213f(%rip), %rsi      # 0x86ec
movq 0x30(%rsp), %rdx
movq %r14, 0x58(%rsp)
movl %r14d, %ecx
xorl %eax, %eax
callq 0x5150
movq %rbx, %rdi
callq 0x5090
movq %r15, %rdi
callq 0x5030
jmp 0x6419
movq 0xb0(%rsp), %rdi
callq 0x5030
movq 0x48(%rsp), %rdi
callq 0x5030
movl 0x54(%rsp), %eax
movl 0x2c(%rsp), %ebp
testb %bpl, %bpl
js 0x65fe
movl 0x20(%rsp), %eax
addl 0x10(%rsp), %eax
testw $0x7ff, %ax             # imm = 0x7FF
je 0x6612
andl $0xfffff800, %eax       # imm = 0xFFFFF800
addl $0x800, %eax            # imm = 0x800
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rdi
callq 0x5030
incl %r14d
jmp 0x6001
leaq 0x2049(%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
leaq 0x231f(%rip), %rdi      # 0x8974
callq 0x5070
movq %r13, %rdi
callq 0x5030
jmp 0x663c
movl %eax, %ebx
leaq 0x2022(%rip), %rdi      # 0x868f
xorl %eax, %eax
callq 0x50c0
addl $0x5, %ebx
cmpl $0x7, %ebx
ja 0x668e
movl %ebx, %eax
leaq 0x1a43(%rip), %rcx      # 0x80c8
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
jmp 0x6695
leaq 0x233c(%rip), %rdi      # 0x89d1
callq 0x5070
movq 0x20(%rsp), %rsi
leaq 0x2029(%rip), %rdi      # 0x86cf
jmp 0x6635