// File: /workspace/github_c_makefile_star2_O2/Zarh[P]regps3iso/iso.c
// Function: GetFileInfo
u8 GetFileInfo(char *iso, file_info_t **file_info, u32 *file_number)
{
    struct stat s;
    int n;
    
    *file_number = 0;
    
    file_info_t *local =NULL;
    
	char path1[0x420];
    char path2[0x420];
    int len_path2 = 0;

	strcpy(path1, iso);
    u8 *sectors = NULL;
    u8 *sectors2 = NULL;
    u8 *sectors3 = NULL;

    static char string[0x420];
    static char string2[0x420];
    static u16 wstring[1024];

    struct iso_primary_descriptor sect_descriptor;
    struct iso_directory_record * idr;
    int idx = -1;

	//u32 flba = 0;
	u32 lba;
	u32 p = 0;
	//u32 toc;
	u32 lba0;
	u32 size0;
    
	directory_iso2 = NULL;

    fp_split = NULL;
    fp_split0 = NULL;
    split_index = 0;

    // libc test
    if(sizeof(s.st_size) != 8) {
        printf("Error!: stat st_size must be a 64 bit number!  (size %i)\n\nPress ENTER key to exit\n\n", sizeof(s.st_size));
        return -1;
    }
    
    fixpath(path1);

    n = strlen(path1);

    sprintf(split_file[0].path, "%s", path1);
	
    if(stat(split_file[0].path, &s)<0) {
        printf("Error: ISO file don't exists!\n\nPress ENTER key to exit\n"); return -1;
    }
    split_file[0].size = s.st_size;
    split_file[1].size = 0; // split off

    FILE *fp = fopen(path1, "rb");
    if(!fp) {
        printf("Error!: Cannot open ISO file\n\nPress ENTER key to exit\n\n");
        return -1;
    }

    
    if(fseek(fp, 0x8800, SEEK_SET)<0) {
        printf("Error!: in sect_descriptor fseek\n\n");
        goto err;
    }

    if(fread((void *) &sect_descriptor, 1, 2048, fp) != 2048) {
        printf("Error!: reading sect_descriptor\n\n");
        goto err;
    }

    if(!(sect_descriptor.type[0] == 2 && !strncmp((const char *) &sect_descriptor.id[0], "CD001",5))) {
        printf("Error!: UTF16 descriptor not found\n\nPress ENTER key to exit\n\n");
        goto err;
    }

    //toc = isonum_733(&sect_descriptor.volume_space_size[0]);

    lba0 = isonum_731(&sect_descriptor.type_l_path_table[0]); // lba
    size0 = isonum_733(&sect_descriptor.path_table_size[0]); // tamaño
    //printf("lba0 %u size %u %u\n", lba0, size0, ((size0 + 2047)/2048) * 2048);
    
    if(fseek(fp, lba0 * 2048, SEEK_SET)<0) {
        printf("Error!: in path_table fseek\n\n");
        goto err;
    }

    directory_iso2 = (_directory_iso2 *) malloc((MAX_ISO_PATHS + 1) * sizeof(_directory_iso2));

    if(!directory_iso2) {
        printf("Error!: in directory_is malloc()\n\n");
        goto err;
    }

    memset(directory_iso2, 0, (MAX_ISO_PATHS + 1) * sizeof(_directory_iso2));
 
    sectors = (u8*) malloc(((size0 + 2047)/2048) * 2048);

    if(!sectors) {
        printf("Error!: in sectors malloc()\n\n");
        goto err;
    }

    sectors2 = (u8*) malloc(2048 * 2);

    if(!sectors2) {
        printf("Error!: in sectors2 malloc()\n\n");
        goto err;
    }

    sectors3 = (u8*) malloc(128 * 2048);

    if(!sectors3) {
        printf("Error!: in sectors3 malloc()\n\n");
        goto err;
    }

    if(fread((void *) sectors, 1, size0, fp) != size0) {
        printf("Error!: reading path_table\n\n");
        goto err;
    }

    string2[0] = 0;

    fp_split = NULL;
    fp_split0 = NULL;

    split_index = 0;
    
    idx = 0;

    directory_iso2[idx].name = NULL;

    while(p < size0) {
        u32 snamelen = isonum_721((char *) &sectors[p]);
        if(snamelen == 0) p= ((p/2048) * 2048) + 2048;
        p+=2;
        lba = isonum_731(&sectors[p]);
        p+=4;
        u32 parent =isonum_721((char *) &sectors[p]);
        p+=2;

        memset(wstring, 0, 512 * 2);
        memcpy(wstring, &sectors[p], snamelen);
        
        UTF16_to_UTF8(wstring, (u8 *) string);

        if(idx >= MAX_ISO_PATHS){
            printf("Too much folders (max %i)\n\n", MAX_ISO_PATHS);
            goto err;
        }

        directory_iso2[idx].name = (char *) malloc(strlen(string) + 2);
        if(!directory_iso2[idx].name) {
            printf("Error!: in directory_iso2.name malloc()\n\n");
            goto err;
        }

        strcpy(directory_iso2[idx].name, "/");
        strcat(directory_iso2[idx].name, string);
        
        directory_iso2[idx].parent = parent;
        
        get_iso_path(string2, idx);

        strcat(path2, string2);
		
        path2[len_path2] = 0;
   
        u32 file_lba = 0;
        u64 file_size = 0;

        char file_aux[0x420];

        file_aux[0] = 0;

        int q2 = 0;
        int size_directory = 0;

        while(1) {

            if(fseek(fp, ((u64) lba) * 2048ULL, SEEK_SET)<0) {
                printf("Error!: in directory_record fseek\n\n");
                goto err;
            }

            memset(sectors2 + 2048, 0, 2048);

            if(fread((void *) sectors2, 1, 2048, fp) != 2048) {
                printf("Error!: reading directory_record sector\n\n");
                goto err;
            }

            int q = 0;
            
            if(q2 == 0) {
                idr = (struct iso_directory_record *) &sectors2[q];
                if((int) idr->name_len[0] == 1 && idr->name[0]== 0 && (u64) lba == (u64) (isonum_731((unsigned char *) idr->extent)) && idr->flags[0] == 0x2) {
                    size_directory = isonum_733((unsigned char *) idr->size);
                 
                } else {
                    printf("Error!: Bad first directory record! (LBA %i)\n\n", lba);
                    goto err;
                }
            }

            int signal_idr_correction = 0;

            while(1) {

               
                if(signal_idr_correction) {
                    signal_idr_correction = 0;
                    q-= 2048; // sector correction
                    // copy next sector to first
                    memcpy(sectors2, sectors2 + 2048, 2048);
                    memset(sectors2 + 2048, 0, 2048);
                    lba++;

                    q2 += 2048;

                }

                if(q2 >= size_directory) goto end_dir_rec;
               
                idr = (struct iso_directory_record *) &sectors2[q];

                if(idr->length[0]!=0 && (idr->length[0] + q) > 2048) {

                    printf("Warning! Entry directory break the standard ISO 9660\n\nPress ENTER key\n\n");
                   
                    if(fseek(fp, lba * 2048 + 2048, SEEK_SET)<0) {
                        printf("Error!: in directory_record fseek\n\n");
                        goto err;
                    }

                    if(fread((void *) (sectors2 + 2048), 1, 2048, fp) != 2048) {
                        printf("Error!: reading directory_record sector\n\n");
                        goto err;
                    }

                    signal_idr_correction = 1;

                }

                if(idr->length[0] == 0 && (2048 - q) > 255) goto end_dir_rec;

                if((idr->length[0] == 0 && q != 0) || q == 2048)  { 
                    
                    lba++;
                    q2 += 2048;

                    if(q2 >= size_directory) goto end_dir_rec;

                    if(fseek(fp, (((u64) lba) * 2048ULL), SEEK_SET)<0) {
                        printf("Error!: in directory_record fseek\n\n");
                        goto err;
                    }

                    if(fread((void *) (sectors2), 1, 2048, fp) != 2048) {
                        printf("Error!: reading directory_record sector\n\n");
                        goto err;
                    }
                    memset(sectors2 + 2048, 0, 2048);

                    q = 0;
                    idr = (struct iso_directory_record *) &sectors2[q];

                    if(idr->length[0] == 0 || ((int) idr->name_len[0] == 1 && !idr->name[0])) goto end_dir_rec;
                    
                }

                if((int) idr->name_len[0] > 1 && idr->flags[0] != 0x2 &&
                    idr->name[idr->name_len[0] - 1]== '1' && idr->name[idr->name_len[0] - 3]== ';') { // skip directories
                    
                    memset(wstring, 0, 512 * 2);
                    memcpy(wstring, idr->name, idr->name_len[0]);
                
                    UTF16_to_UTF8(wstring, (u8 *) string); 

                    if(file_aux[0]) {
                        if(strcmp(string, file_aux)) {
    
                            printf("Error!: in batch file %s\n\nPress ENTER key to exit\n\n", file_aux);
                            goto err;
                        }

                        file_size += (u64) (u32) isonum_733(&idr->size[0]);
                        if(idr->flags[0] == 0x80) {// get next batch file
                            q+= idr->length[0]; 
                            continue;
                        } 

                        file_aux[0] = 0; // stop batch file

                    } else {

                        file_lba = isonum_733(&idr->extent[0]);
                        file_size = (u64) (u32) isonum_733(&idr->size[0]);
                        if(idr->flags[0] == 0x80) {
                            strcpy(file_aux, string);
                            q+= idr->length[0];
                            continue;  // get next batch file
                        }
                    }

                    int len = strlen(string);

                    string[len - 2] = 0; // break ";1" string
                    
                    len = strlen(string2);
					if(strcmp(string2, "/") != 0)	strcat(string2, "/");
                    strcat(string2, string);
					
					local = (file_info_t *) realloc(local, (*file_number + 1) * sizeof(file_info_t));
                    local[*file_number].sector = file_lba;
                    local[*file_number].size = file_size; 
                    local[*file_number].path = strcpy_malloc(string2);
					
					*file_number = *file_number + 1;
					                    
                    path2[len_path2] = 0;
                    string2[len] = 0;
                }

                q+= idr->length[0];
            }

            lba ++; 
            q2+= 2048;
            if(q2 >= size_directory) goto end_dir_rec;

        }

        end_dir_rec:

        p+= snamelen;
        if(snamelen & 1) p++;

        idx++;

    }

    if(fp) fclose(fp);
    if(split_index && fp_split) {fclose(fp_split); fp_split = NULL;}
    if(sectors) free(sectors);
    if(sectors2) free(sectors2);
    if(sectors3) free(sectors3);

    for(n = 0; n <= idx; n++)
        if(directory_iso2[n].name) {free(directory_iso2[n].name); directory_iso2[n].name = NULL;}
    
    if(directory_iso2) free(directory_iso2); 

	
    // sort
    *file_info = (file_info_t *) malloc((*file_number) * sizeof(file_info_t) );
	
    u32 i,j;
	u32 smallest_sector = 0;
	for(j=0; j<(*file_number); j++) {
		
		for(i=0; i<(*file_number); i++) {
			if( local[i].sector < local[smallest_sector].sector ) {
				smallest_sector = i;
			}
		}
		(*file_info)[j].size = local[smallest_sector].size;
		(*file_info)[j].sector = local[smallest_sector].sector;
		(*file_info)[j].path = strcpy_malloc(local[smallest_sector].path);
		
		local[smallest_sector].sector = -1; // MAX !
	}
	
	for(j=0; j<(*file_number); j++) FREE(local[j].path);
	FREE(local);
	
    return 0;

err:

    if(fp) fclose(fp);
    if(split_index && fp_split) {fclose(fp_split); fp_split = NULL;}

    if(sectors) free(sectors);
    if(sectors2) free(sectors2);
    if(sectors3) free(sectors3);

    for(n = 0; n <= idx; n++)
        if(directory_iso2[n].name) {free(directory_iso2[n].name); directory_iso2[n].name = NULL;}
    
    if(directory_iso2) free(directory_iso2);

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1178, %rsp           # imm = 0x1178
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %rsi
andl $0x0, (%rdx)
leaq 0x550(%rsp), %r14
movq %r14, %rdi
callq 0x401020
andq $0x0, 0xf41b1(%rip)     # 0x4f7420
cmpb $0x22, (%r14)
jne 0x4032ab
leaq 0x550(%rsp), %r12
movq %r12, %rdi
callq 0x4010f8
movb $0x0, 0x54f(%rsp,%rax)
leaq 0x551(%rsp), %r13
movq %r12, %rdi
callq 0x4010f8
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x401048
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x4032c3
testl %eax, %eax
je 0x4032d0
cmpl $0x22, %eax
je 0x4032cc
cmpb $0x20, %al
jae 0x4032c7
jmp 0x4032cc
movb $0x2f, (%r14)
incq %r14
jmp 0x4032ab
movb $0x0, (%r14)
leaq 0xf415d(%rip), %r14     # 0x4f7434
leaq 0x550(%rsp), %rsi
movq %r14, %rdi
callq 0x401020
leaq 0xa0(%rsp), %rsi
movq %r14, %rdi
callq 0x464cb0
testl %eax, %eax
js 0x40339a
movl 0xd0(%rsp), %eax
movl %eax, 0xf4124(%rip)     # 0x4f7430
andl $0x0, 0xf4541(%rip)     # 0x4f7854
leaq 0xbed0d(%rip), %rsi     # 0x4c2027
leaq 0x550(%rsp), %rdi
callq 0x41c7c0
testq %rax, %rax
je 0x4033a3
movq %rax, %r14
movl $0x8800, %esi           # imm = 0x8800
movq %rax, %rdi
xorl %edx, %edx
callq 0x41f220
testl %eax, %eax
js 0x4033b4
leaq 0x978(%rsp), %rdi
pushq $0x1
popq %rsi
movl $0x800, %edx            # imm = 0x800
movq %r14, %rcx
callq 0x41c9f0
cmpq $0x800, %rax            # imm = 0x800
jne 0x4033c3
cmpb $0x2, 0x978(%rsp)
jne 0x40338b
leaq 0x979(%rsp), %rdi
leaq 0xbeeea(%rip), %rsi     # 0x4c2265
pushq $0x5
popq %rdx
callq 0x401028
testl %eax, %eax
je 0x403449
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbf0f9(%rip), %rdi     # 0x4c2491
jmp 0x4033d0
leaq 0xbf170(%rip), %rdi     # 0x4c2511
jmp 0x4033aa
leaq 0xbef40(%rip), %rdi     # 0x4c22ea
callq 0x41cf70
jmp 0x403435
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbf12e(%rip), %rdi     # 0x4c24ef
jmp 0x4033d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbf0fe(%rip), %rdi     # 0x4c24ce
callq 0x41cf70
xorl %ebp, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x41c220
movq %r13, %rdi
callq 0x42ab60
movq %rbx, %rdi
callq 0x42ab60
movq %rbp, %rdi
callq 0x42ab60
movq 0xf401d(%rip), %rbx     # 0x4f7420
incl %r12d
shlq $0x4, %r12
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x40342d
movq 0x8(%rbx,%r14), %rdi
testq %rdi, %rdi
je 0x403427
callq 0x42ab60
andq $0x0, 0x8(%rbx,%r14)
addq $0x10, %r14
jmp 0x40340d
movq %rbx, %rdi
callq 0x42ab60
movb $-0x1, %al
addq $0x1178, %rsp           # imm = 0x1178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x9fc(%rsp), %r12d
movl 0xa04(%rsp), %esi
shll $0xb, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x41f220
testl %eax, %eax
js 0x403b2a
pushq $0x1
popq %rdi
movl $0x10010, %esi          # imm = 0x10010
callq 0x42bc70
movq %rax, 0xf3f9f(%rip)     # 0x4f7420
testq %rax, %rax
je 0x403b3c
leal 0x7ff(%r12), %edi
andl $0xfffff800, %edi       # imm = 0xFFFFF800
callq 0x42a820
testq %rax, %rax
je 0x403b4e
movq %rax, %r13
movl $0x1000, %edi           # imm = 0x1000
callq 0x42a820
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x403b60
movl $0x40000, %edi          # imm = 0x40000
callq 0x42a820
testq %rax, %rax
je 0x403b7b
movq %rax, %rbp
pushq $0x1
popq %rsi
movq %r13, %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x41c9f0
cmpq %r12, %rax
jne 0x403b91
movq %r12, 0x98(%rsp)
movb $0x0, 0xf3300(%rip)     # 0x4f6800
movq 0xf3f19(%rip), %rax     # 0x4f7420
andq $0x0, 0x8(%rax)
movq 0x8(%rsp), %rax
addq $0x800, %rax            # imm = 0x800
movq %rax, 0x48(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x68(%rsp)
xorl %r12d, %r12d
xorl %eax, %eax
movq $0x0, 0x30(%rsp)
movq %r15, 0x80(%rsp)
movq %rbx, 0x58(%rsp)
movq %rbp, 0x70(%rsp)
movq %r13, 0x40(%rsp)
cmpl 0x98(%rsp), %eax
jae 0x403c00
movl %eax, %ecx
movzwl (%r13,%rcx), %ecx
movl %eax, %r15d
andl $0xfffff800, %r15d      # imm = 0xFFFFF800
addl $0x800, %r15d           # imm = 0x800
testq %rcx, %rcx
movq %rcx, %rbx
cmovnel %eax, %r15d
leal 0x2(%r15), %eax
movl (%r13,%rax), %eax
movq %rax, 0x28(%rsp)
leal 0x6(%r15), %eax
movzwl (%r13,%rax), %eax
movl %eax, 0x4(%rsp)
addl $0x8, %r15d
movl $0x400, %edx            # imm = 0x400
leaq 0xf367b(%rip), %rdi     # 0x4f6c20
xorl %esi, %esi
callq 0x4010b8
movq %r15, 0x88(%rsp)
leaq (%r15,%r13), %rsi
leaq 0xf3661(%rip), %rdi     # 0x4f6c20
movq %rbx, %rdx
movq %rbx, 0x90(%rsp)
callq 0x401048
callq 0x403d86
cmpq $0x1000, %r12           # imm = 0x1000
je 0x403d42
leaq 0xf2df8(%rip), %rbx     # 0x4f63e0
movq %rbx, %rdi
callq 0x4010f8
leaq 0x2(%rax), %rdi
callq 0x42a820
movq 0xf3e20(%rip), %r13     # 0x4f7420
movq %r12, %rcx
shlq $0x4, %rcx
movq %rax, 0x8(%r13,%rcx)
testq %rax, %rax
je 0x403d5d
leaq (%rcx,%r13), %r15
addq $0x8, %r15
movw $0x2f, (%rax)
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x401060
movl 0x4(%rsp), %eax
movl %eax, -0x8(%r15)
movb $0x0, 0xf31c4(%rip)     # 0x4f6800
testq %r12, %r12
je 0x40368c
movl %r12d, %eax
leaq 0x130(%rsp), %r15
movslq %eax, %rbp
shlq $0x4, %rbp
movq 0x8(%r13,%rbp), %rsi
movq %r15, %rdi
callq 0x401020
movq %r15, %rdi
movq %r13, %rbx
leaq 0xf3193(%rip), %r13     # 0x4f6800
movq %r13, %rsi
callq 0x401060
movq %r13, %rdi
movq %rbx, %r13
movq %r15, %rsi
callq 0x401020
movl (%rbx,%rbp), %eax
decl %eax
jne 0x40364c
jmp 0x403695
movw $0x2f, 0xf316b(%rip)    # 0x4f6800
movb $0x0, 0x130(%rsp)
movq 0x28(%rsp), %rsi
shlq $0xb, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x41f220
testl %eax, %eax
js 0x403d6b
movl $0x800, %edx            # imm = 0x800
movq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x4010b8
movl $0x800, %edx            # imm = 0x800
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
pushq $0x1
popq %rsi
movq %r14, %rcx
callq 0x41c9f0
cmpq $0x800, %rax            # imm = 0x800
movq 0x70(%rsp), %rbp
movq 0x40(%rsp), %r13
jne 0x403be6
cmpb $0x1, 0x20(%rbx)
jne 0x403bb6
cmpb $0x0, 0x21(%rbx)
jne 0x403bb6
movslq 0x2(%rbx), %rax
cmpq %rax, 0x28(%rsp)
jne 0x403bb6
cmpb $0x2, 0x19(%rbx)
jne 0x403bb6
movl 0xa(%rbx), %eax
movl %eax, 0x3c(%rsp)
movq $0x0, 0x60(%rsp)
xorl %r8d, %r8d
xorl %r15d, %r15d
xorl %esi, %esi
xorl %ecx, %ecx
testl %ecx, %ecx
movq %r8, 0x18(%rsp)
je 0x403793
addl $0xfffff800, %esi       # imm = 0xFFFFF800
movl %esi, 0x4(%rsp)
movl $0x800, %edx            # imm = 0x800
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rbx
movq %rbx, %rsi
callq 0x401048
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4010b8
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %r8
movq 0x28(%rsp), %rcx
incl %ecx
movq %rcx, 0x28(%rsp)
addl $0x800, %r15d           # imm = 0x800
movl %r15d, 0x14(%rsp)
cmpl 0x3c(%rsp), %r15d
jge 0x403b07
movslq %esi, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %rdi
movb (%rcx,%rax), %al
testb %al, %al
setne %cl
movzbl %al, %edx
addl %esi, %edx
cmpl $0x801, %edx            # imm = 0x801
setge %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x403838
movq %rdi, %r15
movl %esi, 0x4(%rsp)
leaq 0xbebeb(%rip), %rdi     # 0x4c23c5
callq 0x41cf70
movq 0x28(%rsp), %rsi
shll $0xb, %esi
addl $0x800, %esi            # imm = 0x800
movq %r14, %rdi
xorl %edx, %edx
callq 0x41f220
testl %eax, %eax
js 0x403bad
movl $0x800, %edx            # imm = 0x800
movq 0x48(%rsp), %rdi
pushq $0x1
popq %rsi
movq %r14, %rcx
callq 0x41c9f0
cmpq $0x800, %rax            # imm = 0x800
jne 0x403bf7
movq %r15, %rdi
movb (%r15), %al
pushq $0x1
popq %rcx
movl %ecx, 0x24(%rsp)
movl 0x4(%rsp), %esi
movq 0x18(%rsp), %r8
jmp 0x403840
movl $0x0, 0x24(%rsp)
testb %al, %al
sete %cl
cmpl $0x701, %esi            # imm = 0x701
setl %dl
testb %dl, %cl
jne 0x403b07
testb %al, %al
sete %cl
testl %esi, %esi
setne %dl
testb %dl, %cl
jne 0x403874
cmpl $0x800, %esi            # imm = 0x800
je 0x403874
movb 0x20(%rdi), %cl
jmp 0x403909
movl 0x14(%rsp), %eax
addl $0x800, %eax            # imm = 0x800
movl %eax, 0x14(%rsp)
cmpl 0x3c(%rsp), %eax
jge 0x403b07
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
movl %eax, %esi
shlq $0xb, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x41f220
testl %eax, %eax
js 0x403bad
movl $0x800, %edx            # imm = 0x800
movq 0x8(%rsp), %rdi
movq %rdi, %rbx
pushq $0x1
popq %rsi
movq %r14, %rcx
callq 0x41c9f0
cmpq $0x800, %rax            # imm = 0x800
jne 0x403be6
movl $0x800, %edx            # imm = 0x800
movq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x4010b8
movb (%rbx), %al
testb %al, %al
movq 0x18(%rsp), %r8
je 0x403b07
movq 0x8(%rsp), %rdx
movb 0x20(%rdx), %cl
xorl %esi, %esi
cmpb $0x1, %cl
je 0x403af7
movq %rdx, %rdi
cmpb $0x2, %cl
jb 0x403aff
cmpb $0x2, 0x19(%rdi)
je 0x403aff
movzbl %cl, %ecx
leal -0x1(%rcx), %edx
cmpb $0x31, 0x21(%rdi,%rdx)
jne 0x403aff
leaq 0x21(%rdi), %rbx
movl %ecx, %r15d
cmpb $0x3b, -0x3(%r15,%rbx)
jne 0x403aff
movq %rdi, 0x50(%rsp)
movl %esi, 0x4(%rsp)
movl $0x400, %edx            # imm = 0x400
leaq 0xf32cb(%rip), %rdi     # 0x4f6c20
xorl %esi, %esi
callq 0x4010b8
leaq 0xf32bd(%rip), %rdi     # 0x4f6c20
movq %rbx, %rsi
movq %r15, %rdx
callq 0x401048
callq 0x403d86
cmpb $0x0, 0x130(%rsp)
je 0x4039c7
leaq 0xf2a5c(%rip), %rdi     # 0x4f63e0
leaq 0x130(%rsp), %rsi
callq 0x4010c8
testl %eax, %eax
jne 0x403bce
movq 0x50(%rsp), %rcx
movl 0xa(%rcx), %eax
movq 0x18(%rsp), %r8
addq %rax, %r8
xorl %eax, %eax
cmpb 0x19(%rcx), %al
jno 0x403a17
movzbl (%rcx), %eax
movl 0x4(%rsp), %esi
addl %eax, %esi
movl 0x14(%rsp), %r15d
movl 0x24(%rsp), %ecx
jmp 0x40373e
movq 0x50(%rsp), %r15
movl 0x2(%r15), %eax
movq %rax, 0x60(%rsp)
movl 0xa(%r15), %eax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
cmpb 0x19(%r15), %al
leaq 0xf29f5(%rip), %rsi     # 0x4f63e0
leaq 0x130(%rsp), %rdi
jno 0x403a24
callq 0x401020
movzbl (%r15), %eax
movl 0x4(%rsp), %esi
addl %eax, %esi
movl 0x14(%rsp), %r15d
movl 0x24(%rsp), %ecx
movq 0x18(%rsp), %r8
jmp 0x40373e
movq %r8, 0x18(%rsp)
movb $0x0, 0x130(%rsp)
leaq 0xf29b5(%rip), %rbx     # 0x4f63e0
movq %rbx, %rdi
callq 0x4010f8
addl $-0x2, %eax
cltq
movb $0x0, (%rax,%rbx)
leaq 0xf2dbd(%rip), %r15     # 0x4f6800
movq %r15, %rdi
callq 0x4010f8
movq %rax, 0x78(%rsp)
movq %r15, %rdi
cmpw $0x2f, 0xf2da5(%rip)    # 0x4f6800
je 0x403a76
callq 0x4010f8
leaq 0xf2d97(%rip), %rcx     # 0x4f6800
movw $0x2f, (%rax,%rcx)
leaq 0xf2d8a(%rip), %rdi     # 0x4f6800
leaq 0xf2963(%rip), %rsi     # 0x4f63e0
callq 0x401060
movq 0x58(%rsp), %rbx
movl (%rbx), %eax
incl %eax
imulq $0x18, %rax, %rsi
movq 0x30(%rsp), %rdi
callq 0x42aeb0
movq %rax, %r15
movl (%rbx), %ecx
imulq $0x18, %rcx, %rdx
movq 0x60(%rsp), %rcx
movl %ecx, 0x8(%rax,%rdx)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax,%rdx)
leaq 0xf2d44(%rip), %rdi     # 0x4f6800
callq 0x4031f4
movl (%rbx), %ecx
imulq $0x18, %rcx, %rdx
movq %r15, 0x30(%rsp)
movq %rax, (%r15,%rdx)
leal 0x1(%rcx), %eax
movl %eax, (%rbx)
movslq 0x78(%rsp), %rax
leaq 0xf2d1f(%rip), %rcx     # 0x4f6800
movb $0x0, (%rax,%rcx)
movq 0x18(%rsp), %r8
movq 0x50(%rsp), %rax
movb (%rax), %al
movl 0x4(%rsp), %esi
jmp 0x403aff
xorl %esi, %esi
cmpb $0x0, 0x21(%rdx)
je 0x403b07
movzbl %al, %eax
jmp 0x4039b7
movq 0x90(%rsp), %rcx
movl %ecx, %eax
andl $0x1, %eax
addl %ecx, %eax
addl 0x88(%rsp), %eax
incq %r12
incq 0x68(%rsp)
jmp 0x403549
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbe93d(%rip), %rdi     # 0x4c2474
jmp 0x4033d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbe7d8(%rip), %rdi     # 0x4c2321
jmp 0x4033d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbe7e8(%rip), %rdi     # 0x4c2343
jmp 0x4033d0
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbe7f3(%rip), %rdi     # 0x4c2360
callq 0x41cf70
xorl %ebp, %ebp
xorl %ebx, %ebx
jmp 0x4033dc
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbe7f6(%rip), %rdi     # 0x4c237e
callq 0x41cf70
xorl %ebp, %ebp
jmp 0x403ba3
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq 0xbe8ba(%rip), %rdi     # 0x4c2458
callq 0x41cf70
movq 0x8(%rsp), %rbx
jmp 0x4033dc
leaq 0xbe881(%rip), %rdi     # 0x4c2435
jmp 0x403b9e
leaq 0xbe6ca(%rip), %rdi     # 0x4c2287
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x40dcf0
jmp 0x4033dc
leaq 0xbe6e1(%rip), %rdi     # 0x4c22b6
leaq 0x130(%rsp), %rsi
xorl %eax, %eax
callq 0x40dcf0
jmp 0x403ba3
leaq 0xbe81f(%rip), %rdi     # 0x4c240c
callq 0x41cf70
jmp 0x4033dc
leaq 0xbe80e(%rip), %rdi     # 0x4c240c
jmp 0x403b9e
movq %r14, %rdi
callq 0x41c220
movq %r13, %rdi
callq 0x42ab60
movq 0x8(%rsp), %rdi
callq 0x42ab60
movq %rbp, %rdi
callq 0x42ab60
movq 0xf37f7(%rip), %r14     # 0x4f7420
leaq 0x8(%r14), %r12
movq 0x68(%rsp), %r13
subq $0x1, %r13
jb 0x403c51
movq (%r12), %rdi
testq %rdi, %rdi
je 0x403c4b
callq 0x42ab60
andq $0x0, (%r12)
addq $0x10, %r12
jmp 0x403c32
movq %r14, %rdi
callq 0x42ab60
movq 0x58(%rsp), %rbx
movl (%rbx), %r13d
imulq $0x18, %r13, %rdi
callq 0x42a820
movq 0x80(%rsp), %r15
movq %rax, (%r15)
movq 0x30(%rsp), %r9
leaq 0x8(%r9), %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movl %r13d, %eax
cmpq %rax, %r12
jae 0x403d06
movq 0x8(%rsp), %rcx
xorl %edx, %edx
movl %ebp, %esi
cmpq %rdx, %rax
je 0x403cba
movl (%rcx), %edi
imulq $0x18, %rsi, %r8
movl %edx, %esi
cmpl 0x8(%r9,%r8), %edi
jb 0x403caf
movl %ebp, %esi
incq %rdx
addq $0x18, %rcx
movl %esi, %ebp
jmp 0x403c97
imulq $0x18, %rsi, %r13
movq 0x10(%r9,%r13), %rax
movq (%r15), %rcx
imulq $0x18, %r12, %r14
movq %rax, 0x10(%rcx,%r14)
movq 0x30(%rsp), %rax
movl 0x8(%rax,%r13), %eax
movl %eax, 0x8(%rcx,%r14)
movq 0x30(%rsp), %rax
movq (%rax,%r13), %rdi
callq 0x4031f4
movq (%r15), %rcx
movq %rax, (%rcx,%r14)
movq 0x30(%rsp), %r9
orl $-0x1, 0x8(%r9,%r13)
incq %r12
movl (%rbx), %r13d
jmp 0x403c88
movq %r9, %r15
xorl %r14d, %r14d
movl %r13d, %eax
cmpq %rax, %r14
jae 0x403d31
movq (%r15), %rdi
testq %rdi, %rdi
je 0x403d28
callq 0x42ab60
andq $0x0, (%r15)
movl (%rbx), %r13d
incq %r14
addq $0x18, %r15
jmp 0x403d0c
movq 0x30(%rsp), %rdi
callq 0x42ab60
xorl %eax, %eax
jmp 0x403437
leaq 0xbe522(%rip), %rdi     # 0x4c226b
movl $0x1000, %esi           # imm = 0x1000
xorl %eax, %eax
callq 0x40dcf0
movl $0x1000, %r12d          # imm = 0x1000
jmp 0x403d7c
leaq 0xbe638(%rip), %rdi     # 0x4c239c
callq 0x41cf70
jmp 0x403d7c
leaq 0xbe6c3(%rip), %rdi     # 0x4c2435
callq 0x41cf70
movq 0x70(%rsp), %rbp
movq 0x40(%rsp), %r13
jmp 0x403ba3