// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4408, %rsp           # imm = 0x4408
cmpl $0x2, %edi
jne 0x4019d8
movq 0x8(%rsi), %rdi
leaq 0xade97(%rip), %rsi     # 0x4af667
callq 0x4122c0
testq %rax, %rax
je 0x4019e2
leaq -0x4428(%rbp), %rdi
movl $0x1, %esi
movl $0x4400, %edx           # imm = 0x4400
movq %rax, %rcx
callq 0x4123c0
cmpq $0x4400, %rax           # imm = 0x4400
jne 0x4019e9
leaq 0x969f5(%rip), %rdi     # 0x4981ff
callq 0x412790
leaq -0x4228(%rbp), %r14
leaq 0x96829(%rip), %rdi     # 0x498046
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0x40b930
movl 0x8(%r14), %esi
leaq 0x96822(%rip), %rdi     # 0x498056
xorl %eax, %eax
callq 0x40b930
movl 0xc(%r14), %esi
leaq 0x96823(%rip), %rdi     # 0x498069
xorl %eax, %eax
callq 0x40b930
movl 0x10(%r14), %esi
leaq 0x96823(%rip), %rdi     # 0x49807b
xorl %eax, %eax
callq 0x40b930
movq 0x18(%r14), %rsi
leaq 0x96828(%rip), %rdi     # 0x498092
xorl %eax, %eax
callq 0x40b930
movq 0x20(%r14), %rsi
leaq 0x9682d(%rip), %rdi     # 0x4980a9
xorl %eax, %eax
callq 0x40b930
movq 0x28(%r14), %rsi
leaq 0x96831(%rip), %rdi     # 0x4980bf
xorl %eax, %eax
callq 0x40b930
movq 0x30(%r14), %rsi
leaq 0x96842(%rip), %rdi     # 0x4980e2
xorl %eax, %eax
callq 0x40b930
movq 0x48(%r14), %rsi
leaq 0x96852(%rip), %rdi     # 0x498104
xorl %eax, %eax
callq 0x40b930
movl 0x50(%r14), %esi
leaq 0x96863(%rip), %rdi     # 0x498127
xorl %eax, %eax
callq 0x40b930
movl 0x54(%r14), %esi
leaq 0x96873(%rip), %rdi     # 0x498149
xorl %eax, %eax
callq 0x40b930
movl 0x58(%r14), %esi
leaq 0x96880(%rip), %rdi     # 0x498168
xorl %eax, %eax
callq 0x40b930
movl 0x50(%r14), %eax
testl %eax, %eax
je 0x4019f3
leaq -0x4028(%rbp), %r12
leaq -0x3ff0(%rbp), %r13
leaq 0x968b2(%rip), %r15     # 0x4981c2
xorl %ebx, %ebx
movq %rbx, %r14
shlq $0x7, %r14
cmpq $0x0, 0x20(%r12,%r14)
je 0x4019c2
addq %r12, %r14
cmpq $0x0, 0x28(%r14)
je 0x4019c2
leaq 0x9684e(%rip), %rdi     # 0x498188
movl %ebx, %esi
xorl %eax, %eax
callq 0x40b930
movq 0x20(%r14), %rsi
leaq 0x96863(%rip), %rdi     # 0x4981b1
xorl %eax, %eax
callq 0x40b930
movq 0x20(%r14), %rsi
shlq $0x9, %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x40b930
movq 0x28(%r14), %rsi
leaq 0x9686b(%rip), %rdi     # 0x4981dd
xorl %eax, %eax
callq 0x40b930
movq 0x28(%r14), %rsi
shlq $0x9, %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x40b930
leaq 0x9685b(%rip), %rdi     # 0x4981ed
xorl %eax, %eax
callq 0x40b930
xorl %r14d, %r14d
movzbl (%r13,%r14), %edi
callq 0x412930
incq %r14
cmpq $0x48, %r14
jne 0x40199c
leaq 0x96dd3(%rip), %rdi     # 0x49878a
callq 0x412790
movl -0x41d8(%rbp), %eax
incq %rbx
movl %eax, %ecx
subq $-0x80, %r13
cmpq %rcx, %rbx
jb 0x401912
xorl %ebx, %ebx
jmp 0x4019f3
movq %rsi, %rdi
callq 0x401100
jmp 0x4019ee
callq 0x401152
jmp 0x4019ee
callq 0x401123
movl $0x1, %ebx
movl %ebx, %eax
addq $0x4408, %rsp           # imm = 0x4408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw (%rax,%rax)