// File: /workspace/github_c_makefile_star2_O1/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, 0x89cb(%rip) # imm = 0xFFFFFFFF
callq 0x23fc
movq 0x8(%rbx), %rdi
callq 0x4f84
movq %rax, %r14
movq %rax, %rdi
callq 0x5203
movq %rax, %rdi
callq 0x20b0
leaq 0x3870(%rip), %rdi      # 0x608d
callq 0x40db
testq %rax, %rax
je 0x2a2f
movq %rax, %r15
movq %rbx, 0x8(%rsp)
leaq 0x10(%rsp), %rbp
leaq 0x3851(%rip), %r12      # 0x6090
leaq 0x3847(%rip), %r13      # 0x608d
cmpb $0x0, (%r15)
movq %rbp, %rbx
je 0x2881
movq %r15, %rdi
callq 0x4af2
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 0x289e
movb (%rbx), %r15b
cmpb $0x62, %r15b
jne 0x28bb
movq %rbx, %rdi
callq 0x266d
movq %r13, %rdi
callq 0x40db
movq %rax, %r15
testq %rax, %rax
jne 0x2846
jmp 0x2a2f
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x37a1(%rip), %rsi      # 0x606b
callq 0x2090
testl %eax, %eax
je 0x29c0
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x37b0(%rip), %rsi      # 0x6096
callq 0x2090
cmpb $0x63, %r15b
je 0x29cd
testl %eax, %eax
je 0x29cd
movl $0x6, %edx
movq %rbx, %rdi
leaq 0x3793(%rip), %rsi      # 0x609f
callq 0x2090
cmpb $0x6d, %r15b
je 0x29da
testl %eax, %eax
je 0x29da
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x3774(%rip), %rsi      # 0x60a6
callq 0x2090
testl %eax, %eax
je 0x29ea
movq %rbx, %rdi
leaq 0x3ba3(%rip), %rsi      # 0x64ec
callq 0x21c0
testl %eax, %eax
je 0x29ea
movl $0x9, %edx
movq %rbx, %rdi
leaq 0x3746(%rip), %rsi      # 0x60ab
callq 0x2090
cmpb $0x72, %r15b
je 0x29fc
testl %eax, %eax
je 0x29fc
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x372a(%rip), %rsi      # 0x60b5
callq 0x2090
testl %eax, %eax
je 0x2a11
movl $0x4, %edx
movq %rbx, %rdi
leaq 0x371a(%rip), %rsi      # 0x60bd
callq 0x2090
cmpb $0x73, %r15b
je 0x29b6
testl %eax, %eax
jne 0x28a6
movq %r14, %rdi
callq 0x24fc
jmp 0x29f2
movq %r14, %rdi
callq 0x277b
jmp 0x28a6
movq %r14, %rdi
callq 0x26fc
jmp 0x28a6
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2557
jmp 0x28a6
movq %r14, %rdi
callq 0x24d1
movq %r14, %rdi
callq 0x5203
jmp 0x2a04
movq %r14, %rdi
callq 0x516b
movq %rax, %rdi
callq 0x20b0
jmp 0x28a6
movq %r14, %rdi
callq 0x506a
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x4f84
movq %rax, %r14
jmp 0x28a6
movq %r14, %rdi
callq 0x506a
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq