// File: /workspace/github_c_makefile_star2_O2/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
orl $-0x1, 0x89ef(%rip)     # 0xb1b0
callq 0x23cc
movq %rbx, 0x8(%rsp)
movq 0x8(%rbx), %rdi
callq 0x4c0b
movq %rax, (%rsp)
movq %rax, %rdi
callq 0x4e0c
movq %rax, %rdi
callq 0x20b0
leaq 0x389e(%rip), %r15      # 0x608d
leaq 0x10(%rsp), %r14
leaq 0x3895(%rip), %r13      # 0x6090
pushq $0x5
popq %rbp
movq %r15, %rdi
callq 0x3e55
testq %rax, %rax
je 0x29e0
movq %rax, %r12
cmpb $0x0, (%rax)
movq %r14, %rbx
je 0x284a
movq %r12, %rdi
callq 0x47e7
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
movq %r14, %rdi
movq %r12, %rsi
pushq $0x3f
popq %rdx
callq 0x2080
movq %r12, %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x2090
testl %eax, %eax
je 0x2865
movb (%rbx), %r12b
cmpb $0x62, %r12b
jne 0x286f
movq %rbx, %rdi
callq 0x2624
jmp 0x27fe
movq %rbx, %rdi
leaq 0x37f2(%rip), %rsi      # 0x606b
pushq $0x4
popq %rdx
callq 0x2090
testl %eax, %eax
je 0x2967
movq %rbx, %rdi
leaq 0x3803(%rip), %rsi      # 0x6096
pushq $0x8
popq %rdx
callq 0x2090
cmpb $0x63, %r12b
je 0x2975
testl %eax, %eax
je 0x2975
movq %rbx, %rdi
leaq 0x37e8(%rip), %rsi      # 0x609f
pushq $0x6
popq %rdx
callq 0x2090
cmpb $0x6d, %r12b
je 0x2983
testl %eax, %eax
je 0x2983
movq %rbx, %rdi
leaq 0x37cb(%rip), %rsi      # 0x60a6
pushq $0x4
popq %rdx
callq 0x2090
testl %eax, %eax
je 0x2994
cmpb $0x6e, %r12b
jne 0x28fb
cmpb $0x0, 0x1(%rbx)
je 0x2994
movq %rbx, %rdi
leaq 0x37a6(%rip), %rsi      # 0x60ab
pushq $0x9
popq %rdx
callq 0x2090
cmpb $0x72, %r12b
je 0x29aa
testl %eax, %eax
je 0x29aa
movq %rbx, %rdi
leaq 0x378c(%rip), %rsi      # 0x60b5
pushq $0x7
popq %rdx
callq 0x2090
testl %eax, %eax
je 0x29c0
movq %rbx, %rdi
leaq 0x377a(%rip), %rsi      # 0x60bd
pushq $0x4
popq %rdx
callq 0x2090
cmpb $0x73, %r12b
je 0x2959
testl %eax, %eax
jne 0x27fe
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x24bf
jmp 0x29a0
movq (%rsp), %rdi
callq 0x2736
jmp 0x27fe
movq (%rsp), %rdi
callq 0x26b2
jmp 0x27fe
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x251b
jmp 0x27fe
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x2494
movq %rbx, %rdi
callq 0x4e0c
jmp 0x29b3
movq (%rsp), %rdi
callq 0x4d74
movq %rax, %rdi
callq 0x20b0
jmp 0x27fe
movq (%rsp), %rdi
callq 0x4caa
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4c0b
movq %rax, (%rsp)
jmp 0x27fe
movq (%rsp), %rdi
callq 0x4caa
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop