// File: /workspace/github_c_makefile_star2_O0/Jesskas[P]decompisas/source/main.c
// Function: main
int main(int argc, char* argv[]) {

    // TODO: More advanced settings
    if (!argv[1] || !argv[2]) {
        printf("Usage:\n");
        printf("decopmisas [file] [action]\n");
        printf("[action] can be either --print, or --parse\n");
        return 0;
    }
    if (strcmp(argv[2], "--print") && strcmp(argv[2], "--parse")) {
        printf("Invalid [action].\n");
        printf("Only supported options so far are --parse and --print.\n");
        return 0;
    }

    FILE* fp = fopen(argv[1], "rb");
    if (fp == NULL) {
        printf("File not found.\n");
        return -1;
    }

    printf("Reading file...\n\n");

    fseek(fp, SEEK_SET, 0);
    long fileSize = ftell(fp);
    if (fseek(fp, 0l, SEEK_SET) != 0) {
        printf("Error seeking back to zero (main).\n");
    }

    if (argv[2]) {
        unsigned int width = 16; // TODO: Parameterize this
        if (!strcmp(argv[2], "--print")) {
            printHexWithAscii(fp, fileSize, width);
        } else if (!strcmp(argv[2], "--parse")) {
            parse(fp, fileSize);
        }
    }

    printf("\nFile read.\n");
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xbf7c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0xbfb2
leaq 0x2efa(%rip), %rdi      # 0xee7d
movb $0x0, %al
callq 0x1050
leaq 0x2ef4(%rip), %rdi      # 0xee85
movb $0x0, %al
callq 0x1050
leaq 0x2f02(%rip), %rdi      # 0xeea1
movb $0x0, %al
callq 0x1050
movl $0x0, -0x4(%rbp)
jmp 0xc10d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x2f0c(%rip), %rsi      # 0xeecd
callq 0x1070
cmpl $0x0, %eax
je 0xc00c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x2efb(%rip), %rsi      # 0xeed5
callq 0x1070
cmpl $0x0, %eax
je 0xc00c
leaq 0x2ef2(%rip), %rdi      # 0xeedd
movb $0x0, %al
callq 0x1050
leaq 0x2ef7(%rip), %rdi      # 0xeef0
movb $0x0, %al
callq 0x1050
movl $0x0, -0x4(%rbp)
jmp 0xc10d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2f0d(%rip), %rsi      # 0xef28
callq 0x10d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xc045
leaq 0x2ef9(%rip), %rdi      # 0xef2b
movb $0x0, %al
callq 0x1050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xc10d
leaq 0x2ef0(%rip), %rdi      # 0xef3c
movb $0x0, %al
callq 0x1050
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
movq -0x18(%rbp), %rdi
callq 0x1090
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
cmpl $0x0, %eax
je 0xc091
leaq 0x2ec4(%rip), %rdi      # 0xef4e
movb $0x0, %al
callq 0x1050
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xc0f8
movl $0x10, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x2e1b(%rip), %rsi      # 0xeecd
callq 0x1070
cmpl $0x0, %eax
jne 0xc0ce
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0xc120
jmp 0xc0f6
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x2df8(%rip), %rsi      # 0xeed5
callq 0x1070
cmpl $0x0, %eax
jne 0xc0f4
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xc2a0
jmp 0xc0f6
jmp 0xc0f8
leaq 0x2e73(%rip), %rdi      # 0xef72
movb $0x0, %al
callq 0x1050
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)