// File: /workspace/github_c_makefile_star2_O3/endeav0r[P]hvm/src/debugger.c
// Function: main
int main (int argc, char * argv [])
{
    struct _vm * vm;
    char * command;
    char last_command[64];

    breakpoints[0] = -1;

    read_piped_input();

    vm = vm_load(argv[1]);

    printf("%s\n", vm_ins_str(vm));

    while (1) {
        if ((command = linenoise("> ")) == 0)
            break;
        if (strlen(command) == 0)
            command = last_command;
        else {
            linenoiseHistoryAdd(command);
            memset(last_command, 0, 64);
            strncpy(last_command, command, 63);
        }

        if (    (strncmp(command, "break", 5) == 0)
             || (strncmp(command, "b", 1)     == 0)) {
            set_breakpoint(command);
        }
        else if (strncmp(command, "core", 4) == 0) {
            dump_core(vm);
        }
        else if (    (strncmp(command, "continue", 8) == 0)
                  || (strncmp(command, "c", 1)        == 0)) {
            debug_continue(vm);
        }
        else if (    (strncmp(command, "memory", 6) == 0)
                  || (strncmp(command, "m", 1)      == 0)){
            debug_memory(vm, command);
        }
        else if (    (strncmp(command, "next", 4) == 0)
                  || (strcmp(command, "n")        == 0)) {
            debug_next(vm);
            printf("%s\n", vm_ins_str(vm));
        }
        else if (    (strncmp(command, "registers", 9) == 0)
                  || (strncmp(command, "r", 1)         == 0)) {
            printf("%s\n", vm_registers_str(vm));
        }
        else if (strncmp(command, "restart", 7) == 0) {
            vm_destroy(vm);
            vm = vm_load(argv[1]);
        }
        else if (    (strncmp(command, "step", 4) == 0)
                  || (strncmp(command, "s", 1)    == 0)) {
            debug_step(vm);
            printf("%s\n", vm_ins_str(vm));
        }
    }

    vm_destroy(vm);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl $0xffffffff, 0x89d1(%rip) # imm = 0xFFFFFFFF
callq 0x23ec
movq 0x8(%rbx), %rdi
callq 0x4db1
movq %rax, %r14
movq %rax, %rdi
callq 0x5026
movq %rax, %rdi
callq 0x20b0
leaq 0x3886(%rip), %rdi      # 0x608d
callq 0x4047
testq %rax, %rax
je 0x2a12
movq %rax, %r15
movq %rbx, 0x8(%rsp)
leaq 0x10(%rsp), %rbp
leaq 0x3867(%rip), %r12      # 0x6090
leaq 0x385d(%rip), %r13      # 0x608d
cmpb $0x0, (%r15)
movq %rbp, %rbx
je 0x286b
movq %r15, %rdi
callq 0x4999
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movl $0x3f, %edx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2080
movq %r15, %rbx
movl $0x5, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2090
testl %eax, %eax
je 0x2888
movb (%rbx), %r15b
cmpb $0x62, %r15b
jne 0x28a5
movq %rbx, %rdi
callq 0x265d
movq %r13, %rdi
callq 0x4047
movq %rax, %r15
testq %rax, %rax
jne 0x2830
jmp 0x2a12
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x37b7(%rip), %rsi      # 0x606b
callq 0x2090
testl %eax, %eax
je 0x29a3
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x37c6(%rip), %rsi      # 0x6096
callq 0x2090
cmpb $0x63, %r15b
je 0x29b0
testl %eax, %eax
je 0x29b0
movl $0x6, %edx
movq %rbx, %rdi
leaq 0x37a9(%rip), %rsi      # 0x609f
callq 0x2090
cmpb $0x6d, %r15b
je 0x29bd
testl %eax, %eax
je 0x29bd
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x378a(%rip), %rsi      # 0x60a6
callq 0x2090
testl %eax, %eax
je 0x29cd
cmpb $0x6e, %r15b
jne 0x2939
cmpb $0x0, 0x1(%rbx)
je 0x29cd
movl $0x9, %edx
movq %rbx, %rdi
leaq 0x3763(%rip), %rsi      # 0x60ab
callq 0x2090
cmpb $0x72, %r15b
je 0x29df
testl %eax, %eax
je 0x29df
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x3747(%rip), %rsi      # 0x60b5
callq 0x2090
testl %eax, %eax
je 0x29f4
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x3737(%rip), %rsi      # 0x60bd
callq 0x2090
cmpb $0x73, %r15b
je 0x2999
testl %eax, %eax
jne 0x2890
movq %r14, %rdi
callq 0x24ec
jmp 0x29d5
movq %r14, %rdi
callq 0x2765
jmp 0x2890
movq %r14, %rdi
callq 0x26ec
jmp 0x2890
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2547
jmp 0x2890
movq %r14, %rdi
callq 0x24c1
movq %r14, %rdi
callq 0x5026
jmp 0x29e7
movq %r14, %rdi
callq 0x4f8e
movq %rax, %rdi
callq 0x20b0
jmp 0x2890
movq %r14, %rdi
callq 0x4e8d
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4db1
movq %rax, %r14
jmp 0x2890
movq %r14, %rdi
callq 0x4e8d
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop