// File: /workspace/github_c_makefile_star2_O0/Zarh[P]regps3iso/main.c
// Function: get_plain_files
void get_plain_files(char *iso)
{
	FILE *f = fopen(iso, "rb");
	if( f == NULL ) {
		printf("Error : cannot fopen %s\n", iso);
		return;
	}
	
	u32 plain_n;
	fread(&plain_n, 4, 1, f);
	
	plain_n = SWAP_BE(plain_n);
	
	u32 start[plain_n];
	u32 end[plain_n];
	u32 i, j, k;
	
	fseek(f, 8, SEEK_SET);
	for(i=0; i < plain_n; i++) {
		fread(&start[i], 4, 1, f);
		fread(&end[i], 4, 1, f);
		
		start[i] = SWAP_BE(start[i]);
		end[i] = SWAP_BE(end[i]);
	}
	fclose(f);
	
	file_info_t *file_info=NULL;
	u32 file_number;
	
	GetFileInfo(iso, &file_info, &file_number);
	
	u32 files_n = 0;
	char **files=NULL;
	u32 *amount=NULL;
	
	char line[512];
	
	// read db
	FILE *l = fopen("plain_files.txt", "r+");
	if( l != NULL ) {
	
		while(fgets(line, 512, l) != NULL) {
			if(line[0]=='\r' || line[0]=='\n') continue;
			
			if(strstr(line, "\r") != NULL) strtok(line, "\r");
			if(strstr(line, "\n") != NULL) strtok(line, "\n");
			
			files = (char **) realloc(files, (files_n+1) * sizeof(char *));
			amount = (u32 *) realloc(amount, (files_n+1) * sizeof(u32));
			
			sscanf(line, "%08X", &amount[files_n]);
			files[files_n] = strcpy_malloc(line + 11);
			
			files_n++;
			
			memset(line, 0, 512);
		}
		
		
		fclose(l);
	}
	
	for(i=0; i < plain_n; i++) {	
		for(j=0; j<file_number; j++) {
			if( start[i] <= file_info[j].sector ) {
				if(end[i] <= file_info[j].sector ) break;
				
				u8 found = NO;
				for(k=0; k<files_n; k++) {
					if( memcmp(files[k], file_info[j].path, strlen(file_info[j].path)) == 0 ) {
						found = YES;
						amount[k]++;;
						break;
					}
				}
				if( found == NO ) {
					files = (char **) realloc(files, (files_n+1) * sizeof(char *));
					amount = (u32 *) realloc(amount, (files_n+1) * sizeof(u32));
					files[files_n] = strcpy_malloc(file_info[j].path);
					amount[files_n]=1;
					
					files_n++;
				}
			}
		}
	}
	
	// write db
	char str[512];
	l = fopen("plain_files.txt", "w");
	
	for(i=0; i<files_n; i++) {
	
		u32 max_amount = 0;	
		// search_max
		for( j = 0; j<files_n; j++) {
			if(amount[max_amount] < amount[j]) max_amount=j;
		}
		sprintf(str, "%08X | %s\n", amount[max_amount], files[max_amount]);
		fputs(str, l);
		
		amount[max_amount] = 0;
	}
	fclose(l);
	
	for(j=0; j < files_n; j++) {
		FREE(files[j]);
	}
	FREE(amount);
	FREE(files);
	
	for(j=0; j < file_number; j++) FREE(file_info[j].path)
	FREE(file_info);
	
	fclose(l);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xc23b7(%rip), %rsi     # 0x4c4041
callq 0x41ea50
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x401cb1
movq -0x8(%rbp), %rsi
leaq 0xc239f(%rip), %rdi     # 0x4c4044
movb $0x0, %al
callq 0x40ff80
jmp 0x402429
movq -0x10(%rbp), %rcx
leaq -0x14(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x41ec80
movw $0x1, -0x16(%rbp)
cmpb $0x0, -0x16(%rbp)
jne 0x401ce0
movl -0x14(%rbp), %eax
movq %rax, -0x480(%rbp)
jmp 0x401d1e
movl -0x14(%rbp), %eax
andl $0xff, %eax
shll $0x18, %eax
movl -0x14(%rbp), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
shll $0x8, %ecx
orl %ecx, %eax
movl -0x14(%rbp), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
shrl $0x8, %ecx
orl %ecx, %eax
movl -0x14(%rbp), %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x480(%rbp)
movq -0x480(%rbp), %rax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x490(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x488(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
xorl %edx, %edx
callq 0x421310
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x401f00
movq -0x490(%rbp), %rdi
movl -0x34(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x41ec80
movq -0x488(%rbp), %rdi
movl -0x34(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x41ec80
movw $0x1, -0x3e(%rbp)
cmpb $0x0, -0x3e(%rbp)
jne 0x401e02
movq -0x490(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x498(%rbp)
jmp 0x401e53
movq -0x490(%rbp), %rcx
movl -0x34(%rbp), %eax
movl (%rcx,%rax,4), %eax
andl $0xff, %eax
shll $0x18, %eax
movl -0x34(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff00, %edx           # imm = 0xFF00
shll $0x8, %edx
orl %edx, %eax
movl -0x34(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff0000, %edx         # imm = 0xFF0000
shrl $0x8, %edx
orl %edx, %eax
movl -0x34(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x498(%rbp)
movq -0x490(%rbp), %rax
movq -0x498(%rbp), %rcx
movl %ecx, %edx
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movw $0x1, -0x40(%rbp)
cmpb $0x0, -0x40(%rbp)
jne 0x401e8b
movq -0x488(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x4a0(%rbp)
jmp 0x401edc
movq -0x488(%rbp), %rcx
movl -0x34(%rbp), %eax
movl (%rcx,%rax,4), %eax
andl $0xff, %eax
shll $0x18, %eax
movl -0x34(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff00, %edx           # imm = 0xFF00
shll $0x8, %edx
orl %edx, %eax
movl -0x34(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff0000, %edx         # imm = 0xFF0000
shrl $0x8, %edx
orl %edx, %eax
movl -0x34(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x4a0(%rbp)
movq -0x488(%rbp), %rax
movq -0x4a0(%rbp), %rcx
movl %ecx, %edx
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x401d8c
movq -0x10(%rbp), %rdi
callq 0x41e4b0
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0x4046b0
movl $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
leaq 0xc211d(%rip), %rdi     # 0x4c405d
leaq 0xc2126(%rip), %rsi     # 0x4c406d
callq 0x41ea50
movq %rax, -0x268(%rbp)
cmpq $0x0, -0x268(%rbp)
je 0x40209b
jmp 0x401f63
leaq -0x260(%rbp), %rdi
movq -0x268(%rbp), %rdx
movl $0x200, %esi            # imm = 0x200
callq 0x41e7a0
cmpq $0x0, %rax
je 0x40208f
movsbl -0x260(%rbp), %eax
cmpl $0xd, %eax
je 0x401f9d
movsbl -0x260(%rbp), %eax
cmpl $0xa, %eax
jne 0x401f9f
jmp 0x401f63
leaq -0x260(%rbp), %rdi
leaq 0xc20c3(%rip), %rsi     # 0x4c4070
callq 0x401078
cmpq $0x0, %rax
je 0x401fcb
leaq -0x260(%rbp), %rdi
leaq 0xc20aa(%rip), %rsi     # 0x4c4070
callq 0x42fac0
leaq -0x260(%rbp), %rdi
leaq 0xc2af1(%rip), %rsi     # 0x4c4aca
callq 0x401078
cmpq $0x0, %rax
je 0x401ff7
leaq -0x260(%rbp), %rdi
leaq 0xc2ad8(%rip), %rsi     # 0x4c4aca
callq 0x42fac0
movq -0x58(%rbp), %rdi
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x42cfa0
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rdi
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x42cfa0
movq %rax, -0x60(%rbp)
leaq -0x260(%rbp), %rdi
movq -0x60(%rbp), %rdx
movl -0x50(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdx
leaq 0xc2029(%rip), %rsi     # 0x4c4072
movb $0x0, %al
callq 0x4101e0
leaq -0x260(%rbp), %rdi
addq $0xb, %rdi
callq 0x404620
movq %rax, %rdx
movq -0x58(%rbp), %rax
movl -0x50(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
leaq -0x260(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x4010b0
jmp 0x401f63
movq -0x268(%rbp), %rdi
callq 0x41e4b0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x402247
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x402237
movq -0x490(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x48(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x402227
movq -0x488(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x48(%rbp), %rcx
movl -0x38(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x40210a
jmp 0x402237
movb $0x0, -0x269(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x4021a8
movq -0x58(%rbp), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4b0(%rbp)
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x4a8(%rbp)
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x4010f0
movq -0x4b0(%rbp), %rdi
movq -0x4a8(%rbp), %rsi
movq %rax, %rdx
callq 0x401098
cmpl $0x0, %eax
jne 0x402198
movb $0x1, -0x269(%rbp)
movq -0x60(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x4021a8
jmp 0x40219a
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x402118
movzbl -0x269(%rbp), %eax
cmpl $0x0, %eax
jne 0x402225
movq -0x58(%rbp), %rdi
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x42cfa0
movq %rax, -0x58(%rbp)
movq -0x60(%rbp), %rdi
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x42cfa0
movq %rax, -0x60(%rbp)
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x404620
movq %rax, %rdx
movq -0x58(%rbp), %rax
movl -0x50(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
movl -0x50(%rbp), %ecx
movl $0x1, (%rax,%rcx,4)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x402227
jmp 0x402229
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4020b5
jmp 0x402239
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4020a2
leaq 0xc1e0f(%rip), %rdi     # 0x4c405d
leaq 0xc1e22(%rip), %rsi     # 0x4c4077
callq 0x41ea50
movq %rax, -0x268(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x40231e
movl $0x0, -0x474(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x4022bc
movq -0x60(%rbp), %rax
movl -0x474(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x60(%rbp), %rcx
movl -0x38(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0x4022af
movl -0x38(%rbp), %eax
movl %eax, -0x474(%rbp)
jmp 0x4022b1
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x402285
leaq -0x470(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x474(%rbp), %ecx
movl (%rax,%rcx,4), %edx
movq -0x58(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rcx
leaq 0xc1e5e(%rip), %rsi     # 0x4c4143
movb $0x0, %al
callq 0x410050
leaq -0x470(%rbp), %rdi
movq -0x268(%rbp), %rsi
callq 0x41eb50
movq -0x60(%rbp), %rax
movl -0x474(%rbp), %ecx
movl $0x0, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x402268
movq -0x268(%rbp), %rdi
callq 0x41e4b0
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x402373
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
je 0x402366
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x42cc50
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
jmp 0x402368
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x402331
cmpq $0x0, -0x60(%rbp)
je 0x40238b
movq -0x60(%rbp), %rdi
callq 0x42cc50
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x4023a3
movq -0x58(%rbp), %rdi
callq 0x42cc50
movq $0x0, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x4023fe
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x4023f1
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x42cc50
movq -0x48(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
jmp 0x4023f3
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4023aa
cmpq $0x0, -0x48(%rbp)
je 0x402416
movq -0x48(%rbp), %rdi
callq 0x42cc50
movq $0x0, -0x48(%rbp)
movq -0x268(%rbp), %rdi
callq 0x41e4b0
movq -0x20(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nop