// File: /workspace/github_c_makefile_star2_O0/Zarh[P]regps3iso/main.c
// Function: read_region_info
void read_region_info(char *iso)
{
	FILE *f = fopen(iso, "rb");
	if( f == NULL ) {
		printf("Error : cannot fopen %s", iso);
		return;
	}
	
	char log[512];
	char str[1024]={0};
	sprintf(log, "%s.region.txt", iso);
	
	FILE *l = fopen(log, "wb");
	if( l == NULL ) {
		printf("Error : cannot fopen %s", log);
		fclose(f);
		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;
	
	sprintf(str, "Plain number = %d\n", plain_n); fputs(str, l);
	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]);
		
		if( i != 0 ) {
			sprintf(str, "0x%08X\n", start[i] - 1); 
			fputs(str, l);
		}
		
		sprintf(str, "Plain 0x%08X - 0x%08X\n", start[i], end[i]); fputs(str, l);
		if( i+1 < plain_n ) {
			sprintf(str, "**Enc 0x%08X - ", end[i] + 1); fputs(str, l);
		}
	}
	fclose(f);
	
	file_info_t *file_info=NULL;
	u32 file_number;
	
	GetFileInfo(iso, &file_info, &file_number);
	
	fputs("\n\n\n", l);
	
	fflush(l);
		
	for(i=0; i < plain_n; i++) {
			sprintf(str, "--- PLAIN               ---  %08X\n",  start[i]); fputs(str, l); fflush(l);
		if(i==0) fputs("\tsector 00000000 | Header\n", l); fflush(l);
				
		for(j=0; j<file_number; j++) {
			if( start[i] <= file_info[j].sector ) {
				if(end[i] <= file_info[j].sector ) break;
									
				sprintf(str, "\tsector %08X | %s\n", file_info[j].sector, file_info[j].path); fputs(str, l); fflush(l);
			}
		}
		if(i+1 == plain_n) {
			u64 footer = file_info[file_number-1].sector*0x800ULL  + file_info[file_number-1].size;
			footer = (footer + 2047)/2048;
			sprintf(str, "\tsector %08X | footer\n", footer); fputs(str, l); fflush(l);		
		}
			sprintf(str, "--- End of PLAIN        ---  %08X\n\n",  end[i]); fputs(str, l); fflush(l);
		if( i+1 < plain_n) {
			sprintf(str, "--- ENCRYPTED           ---  %08X\n",  end[i]+1); fputs(str, l); fflush(l);
			for(j=0; j<file_number; j++) {
				if( end[i]+1 <= file_info[j].sector ) {
					if(start[i+1] <= file_info[j].sector ) break;
										
					sprintf(str, "\tsector %08X | %s\n", file_info[j].sector, file_info[j].path); fputs(str, l); fflush(l);
				}
			}
			sprintf(str, "--- End of ENCRYPTED    ---  %08X\n\n",  start[i+1]-1); fputs(str, l); fflush(l);
		}
	}
	
	
	for(j=0; j < file_number; j++) FREE(file_info[j].path)
	FREE(file_info);
	
	fclose(l);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x690, %rsp            # imm = 0x690
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xc1167(%rip), %rsi     # 0x4c4041
callq 0x41ea50
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x402f01
movq -0x8(%rbp), %rsi
leaq 0xc11a1(%rip), %rdi     # 0x4c4096
movb $0x0, %al
callq 0x40ff80
jmp 0x40384d
leaq -0x610(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x4010b0
leaq -0x210(%rbp), %rdi
movq -0x8(%rbp), %rdx
leaq 0xc1188(%rip), %rsi     # 0x4c40ae
movb $0x0, %al
callq 0x410050
leaq -0x210(%rbp), %rdi
leaq 0xc1181(%rip), %rsi     # 0x4c40bc
callq 0x41ea50
movq %rax, -0x618(%rbp)
cmpq $0x0, -0x618(%rbp)
jne 0x402f74
leaq -0x210(%rbp), %rsi
leaq 0xc1137(%rip), %rdi     # 0x4c4096
movb $0x0, %al
callq 0x40ff80
movq -0x10(%rbp), %rdi
callq 0x41e4b0
jmp 0x40384d
movq -0x10(%rbp), %rcx
leaq -0x61c(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x41ec80
movw $0x1, -0x61e(%rbp)
cmpb $0x0, -0x61e(%rbp)
jne 0x402faf
movl -0x61c(%rbp), %eax
movq %rax, -0x668(%rbp)
jmp 0x402ff9
movl -0x61c(%rbp), %eax
andl $0xff, %eax
shll $0x18, %eax
movl -0x61c(%rbp), %ecx
andl $0xff00, %ecx           # imm = 0xFF00
shll $0x8, %ecx
orl %ecx, %eax
movl -0x61c(%rbp), %ecx
andl $0xff0000, %ecx         # imm = 0xFF0000
shrl $0x8, %ecx
orl %ecx, %eax
movl -0x61c(%rbp), %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x668(%rbp)
movq -0x668(%rbp), %rax
movl %eax, -0x61c(%rbp)
movl -0x61c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x628(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x678(%rbp)
movq %rcx, %rsp
movq %rax, -0x630(%rbp)
movl -0x61c(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x670(%rbp)
movq %rcx, %rsp
movq %rax, -0x638(%rbp)
leaq -0x610(%rbp), %rdi
movl -0x61c(%rbp), %edx
leaq 0xc1049(%rip), %rsi     # 0x4c40bf
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x10(%rbp), %rdi
movl $0x8, %esi
xorl %edx, %edx
callq 0x421310
movl $0x0, -0x63c(%rbp)
movl -0x63c(%rbp), %eax
cmpl -0x61c(%rbp), %eax
jae 0x40333a
movq -0x678(%rbp), %rdi
movl -0x63c(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x41ec80
movq -0x670(%rbp), %rdi
movl -0x63c(%rbp), %eax
shlq $0x2, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x41ec80
movw $0x1, -0x642(%rbp)
cmpb $0x0, -0x642(%rbp)
jne 0x403135
movq -0x678(%rbp), %rax
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x680(%rbp)
jmp 0x403192
movq -0x678(%rbp), %rcx
movl -0x63c(%rbp), %eax
movl (%rcx,%rax,4), %eax
andl $0xff, %eax
shll $0x18, %eax
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff00, %edx           # imm = 0xFF00
shll $0x8, %edx
orl %edx, %eax
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff0000, %edx         # imm = 0xFF0000
shrl $0x8, %edx
orl %edx, %eax
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x680(%rbp)
movq -0x678(%rbp), %rax
movq -0x680(%rbp), %rcx
movl %ecx, %edx
movl -0x63c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movw $0x1, -0x644(%rbp)
cmpb $0x0, -0x644(%rbp)
jne 0x4031d6
movq -0x670(%rbp), %rax
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq %rax, -0x688(%rbp)
jmp 0x403233
movq -0x670(%rbp), %rcx
movl -0x63c(%rbp), %eax
movl (%rcx,%rax,4), %eax
andl $0xff, %eax
shll $0x18, %eax
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff00, %edx           # imm = 0xFF00
shll $0x8, %edx
orl %edx, %eax
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %edx
andl $0xff0000, %edx         # imm = 0xFF0000
shrl $0x8, %edx
orl %edx, %eax
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrl $0x18, %ecx
orl %ecx, %eax
movl %eax, %eax
movq %rax, -0x688(%rbp)
movq -0x670(%rbp), %rax
movq -0x688(%rbp), %rcx
movl %ecx, %edx
movl -0x63c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x63c(%rbp)
je 0x403290
movq -0x678(%rbp), %rax
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
subl $0x1, %edx
leaq 0xc0e6b(%rip), %rsi     # 0x4c40e1
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x670(%rbp), %rax
movq -0x678(%rbp), %rcx
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %edx
movl (%rcx,%rdx,4), %edx
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
leaq 0xc0e14(%rip), %rsi     # 0x4c40d2
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movl -0x63c(%rbp), %eax
addl $0x1, %eax
cmpl -0x61c(%rbp), %eax
jae 0x403324
movq -0x670(%rbp), %rax
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0xc0ddf(%rip), %rsi     # 0x4c40e9
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
jmp 0x403326
movl -0x63c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x63c(%rbp)
jmp 0x4030aa
movq -0x10(%rbp), %rdi
callq 0x41e4b0
movq $0x0, -0x650(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x650(%rbp), %rsi
leaq -0x654(%rbp), %rdx
callq 0x4046b0
movq -0x618(%rbp), %rsi
leaq 0xc0d86(%rip), %rdi     # 0x4c40f9
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
movl $0x0, -0x63c(%rbp)
movl -0x63c(%rbp), %eax
cmpl -0x61c(%rbp), %eax
jae 0x40379a
movq -0x678(%rbp), %rax
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
leaq 0xc0d3f(%rip), %rsi     # 0x4c40fd
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
cmpl $0x0, -0x63c(%rbp)
jne 0x403400
movq -0x618(%rbp), %rsi
leaq 0xc0d25(%rip), %rdi     # 0x4c4120
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
movl $0x0, -0x640(%rbp)
movl -0x640(%rbp), %eax
cmpl -0x654(%rbp), %eax
jae 0x4034f8
movq -0x678(%rbp), %rax
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x650(%rbp), %rcx
movl -0x640(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x4034e2
movq -0x670(%rbp), %rax
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x650(%rbp), %rcx
movl -0x640(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x403480
jmp 0x4034f8
leaq -0x610(%rbp), %rdi
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0xc0c7f(%rip), %rsi     # 0x4c413b
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
jmp 0x4034e4
movl -0x640(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x640(%rbp)
jmp 0x403416
movl -0x63c(%rbp), %eax
addl $0x1, %eax
cmpl -0x61c(%rbp), %eax
jne 0x4035a4
movq -0x650(%rbp), %rax
movl -0x654(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shlq $0xb, %rax
movq -0x650(%rbp), %rcx
movl -0x654(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
addq 0x10(%rcx), %rax
movq %rax, -0x660(%rbp)
movq -0x660(%rbp), %rax
addq $0x7ff, %rax            # imm = 0x7FF
shrq $0xb, %rax
movq %rax, -0x660(%rbp)
leaq -0x610(%rbp), %rdi
movq -0x660(%rbp), %rdx
leaq 0xc0bd0(%rip), %rsi     # 0x4c414e
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
movq -0x670(%rbp), %rax
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
leaq 0xc0ba3(%rip), %rsi     # 0x4c4165
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
movl -0x63c(%rbp), %eax
addl $0x1, %eax
cmpl -0x61c(%rbp), %eax
jae 0x403784
movq -0x670(%rbp), %rax
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0xc0b6b(%rip), %rsi     # 0x4c4189
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
movl $0x0, -0x640(%rbp)
movl -0x640(%rbp), %eax
cmpl -0x654(%rbp), %eax
jae 0x403738
movq -0x670(%rbp), %rax
movl -0x63c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movq -0x650(%rbp), %rcx
movl -0x640(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x403722
movq -0x678(%rbp), %rax
movl -0x63c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movq -0x650(%rbp), %rcx
movl -0x640(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
ja 0x4036c0
jmp 0x403738
leaq -0x610(%rbp), %rdi
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
leaq 0xc0a3f(%rip), %rsi     # 0x4c413b
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
jmp 0x403724
movl -0x640(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x640(%rbp)
jmp 0x40364e
movq -0x678(%rbp), %rax
leaq -0x610(%rbp), %rdi
movl -0x63c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
subl $0x1, %edx
leaq 0xc0a4e(%rip), %rsi     # 0x4c41ac
movb $0x0, %al
callq 0x410050
leaq -0x610(%rbp), %rdi
movq -0x618(%rbp), %rsi
callq 0x41eb50
movq -0x618(%rbp), %rdi
callq 0x41e6a0
jmp 0x403786
movl -0x63c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x63c(%rbp)
jmp 0x40338e
movl $0x0, -0x640(%rbp)
movl -0x640(%rbp), %eax
cmpl -0x654(%rbp), %eax
jae 0x403816
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x403803
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x42cc50
movq -0x650(%rbp), %rax
movl -0x640(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
jmp 0x403805
movl -0x640(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x640(%rbp)
jmp 0x4037a4
cmpq $0x0, -0x650(%rbp)
je 0x403837
movq -0x650(%rbp), %rdi
callq 0x42cc50
movq $0x0, -0x650(%rbp)
movq -0x618(%rbp), %rdi
callq 0x41e4b0
movq -0x628(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)