// File: /workspace/github_c_makefile_star2_O0/LeeKyuHyuk[P]gpt-parser/src/gpt-parser.c
// Function: main
int main(int argc, char const *argv[]) {
        int partition, name;

        if(argc != 2) {
                fprintf(stderr,"Usage: %s <file name>\n",argv[0]);
                return EXIT_FAILURE;
        }

        FILE *gptFile = fopen(argv[1], "r");
        if(gptFile == NULL) {
                fprintf(stderr, "Error opening gpt file\n");
                return EXIT_FAILURE;
        }
        gpt_t gpt;
        if(fread((void *)&gpt, 1, sizeof(gpt_t), gptFile) != sizeof(gpt_t)) {
                fprintf(stderr,"Error reading gpt\n");
                return EXIT_FAILURE;
        }

        printf("##### Primary GPT Header #####\n");
        printf("Signature : %s\n", gpt.primary_gpt_header.signature);
        printf("GPT Revision : %d\n", gpt.primary_gpt_header.gpt_revision);
        printf("Header Size : %d\n", gpt.primary_gpt_header.header_size);
        printf("Header CRC32 : 0x%08X\n", gpt.primary_gpt_header.header_crc32);
        printf("Current LBA : 0x%08lX\n", gpt.primary_gpt_header.current_lba);
        printf("Backup LBA : 0x%08lX\n", gpt.primary_gpt_header.backup_lba);
        printf("First Usable Partitions : 0x%08lX\n", gpt.primary_gpt_header.first_usable_partitions);
        printf("Last Usable Partitions : 0x%08lX\n", gpt.primary_gpt_header.last_usable_partitions);
        printf("Start Partition Entries : 0x%08lX\n", gpt.primary_gpt_header.start_partition_entries);
        printf("Number of Partition Entries : %d\n", gpt.primary_gpt_header.number_of_partition_entries);
        printf("Partition Entry Size : 0x%08x\n", gpt.primary_gpt_header.partition_entry_size);
        printf("Partition Array CRC32 : %#08x\n\n", gpt.primary_gpt_header.partition_array_crc32);

        for(partition = 0; partition < gpt.primary_gpt_header.number_of_partition_entries; partition++) {
                if(gpt.guid_partition_entries[partition].first_lba != 0x0 &&
                   gpt.guid_partition_entries[partition].last_lba != 0x00) {
                        printf("##### GUID Partition Entries [%d] #####\n", partition);
                        printf("First LBA : %ld\n", gpt.guid_partition_entries[partition].first_lba);
                        printf("\t=> Disk Offset : 0x%08lX\n", gpt.guid_partition_entries[partition].first_lba * LBA_SIZE);
                        printf("Last LBA : %ld\n", gpt.guid_partition_entries[partition].last_lba);
                        printf("\t=> Disk Offset : 0x%08lX\n", gpt.guid_partition_entries[partition].last_lba * LBA_SIZE);
                        printf("Partition Name : ");
                        for (name = 0; name < 72; name++)
                                printf("%c", gpt.guid_partition_entries[partition].partition_name[name]);
                        printf("\n\n");
                }
        }

        return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4420, %rsp           # imm = 0x4420
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x40170a
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x9690d(%rip), %rsi     # 0x498004
movb $0x0, %al
callq 0x40b8b0
movl $0x1, -0x4(%rbp)
jmp 0x401a35
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xadf6e(%rip), %rsi     # 0x4af687
callq 0x412300
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x40174d
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rdi
leaq 0x968e1(%rip), %rsi     # 0x49801b
movb $0x0, %al
callq 0x40b8b0
movl $0x1, -0x4(%rbp)
jmp 0x401a35
movq -0x20(%rbp), %rcx
leaq -0x4420(%rbp), %rdi
movl $0x1, %esi
movl $0x4400, %edx           # imm = 0x4400
callq 0x412400
cmpq $0x4400, %rax           # imm = 0x4400
je 0x401793
movq $0x4c86e8, %rax         # imm = 0x4C86E8
movq (%rax), %rdi
leaq 0x968b3(%rip), %rsi     # 0x498033
movb $0x0, %al
callq 0x40b8b0
movl $0x1, -0x4(%rbp)
jmp 0x401a35
leaq 0x968ac(%rip), %rdi     # 0x498046
movb $0x0, %al
callq 0x40b970
leaq -0x4420(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
leaq 0x968b0(%rip), %rdi     # 0x498066
movb $0x0, %al
callq 0x40b970
movl -0x4218(%rbp), %esi
leaq 0x968ac(%rip), %rdi     # 0x498076
movb $0x0, %al
callq 0x40b970
movl -0x4214(%rbp), %esi
leaq 0x968ab(%rip), %rdi     # 0x498089
movb $0x0, %al
callq 0x40b970
movl -0x4210(%rbp), %esi
leaq 0x968a9(%rip), %rdi     # 0x49809b
movb $0x0, %al
callq 0x40b970
movq -0x4208(%rbp), %rsi
leaq 0x968ab(%rip), %rdi     # 0x4980b2
movb $0x0, %al
callq 0x40b970
movq -0x4200(%rbp), %rsi
leaq 0x968ad(%rip), %rdi     # 0x4980c9
movb $0x0, %al
callq 0x40b970
movq -0x41f8(%rbp), %rsi
leaq 0x968ae(%rip), %rdi     # 0x4980df
movb $0x0, %al
callq 0x40b970
movq -0x41f0(%rbp), %rsi
leaq 0x968bc(%rip), %rdi     # 0x498102
movb $0x0, %al
callq 0x40b970
movq -0x41d8(%rbp), %rsi
leaq 0x968c9(%rip), %rdi     # 0x498124
movb $0x0, %al
callq 0x40b970
movl -0x41d0(%rbp), %esi
leaq 0x968d8(%rip), %rdi     # 0x498147
movb $0x0, %al
callq 0x40b970
movl -0x41cc(%rbp), %esi
leaq 0x968e6(%rip), %rdi     # 0x498169
movb $0x0, %al
callq 0x40b970
movl -0x41c8(%rbp), %esi
leaq 0x968f1(%rip), %rdi     # 0x498188
movb $0x0, %al
callq 0x40b970
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x41d0(%rbp), %eax
jae 0x401a2e
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
cmpq $0x0, 0x20(%rax)
je 0x401a1e
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
cmpq $0x0, 0x28(%rax)
je 0x401a1e
movl -0x14(%rbp), %esi
leaq 0x968a4(%rip), %rdi     # 0x4981a8
movb $0x0, %al
callq 0x40b970
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rsi
leaq 0x968a3(%rip), %rdi     # 0x4981d1
movb $0x0, %al
callq 0x40b970
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rsi
shlq $0x9, %rsi
leaq 0x96886(%rip), %rdi     # 0x4981e2
movb $0x0, %al
callq 0x40b970
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rsi
leaq 0x96877(%rip), %rdi     # 0x4981fd
movb $0x0, %al
callq 0x40b970
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rsi
shlq $0x9, %rsi
leaq 0x9682e(%rip), %rdi     # 0x4981e2
movb $0x0, %al
callq 0x40b970
leaq 0x9684b(%rip), %rdi     # 0x49820d
movb $0x0, %al
callq 0x40b970
movl $0x0, -0x18(%rbp)
cmpl $0x48, -0x18(%rbp)
jge 0x401a10
leaq -0x4420(%rbp), %rax
addq $0x400, %rax            # imm = 0x400
movslq -0x14(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movzbl 0x38(%rax,%rcx), %esi
leaq 0x96821(%rip), %rdi     # 0x49821f
movb $0x0, %al
callq 0x40b970
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4019d0
leaq 0xb21ef(%rip), %rdi     # 0x4b3c06
movb $0x0, %al
callq 0x40b970
jmp 0x401a20
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4018a5
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x4420, %rsp           # imm = 0x4420
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)