// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xffffffff, 0xb810(%rip) # imm = 0xFFFFFFFF
callq 0x23e0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6ec0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x7310
movq %rax, %rsi
leaq 0x66ca(%rip), %rdi      # 0x90c3
movb $0x0, %al
callq 0x2130
leaq 0x66ff(%rip), %rdi      # 0x9106
callq 0x58a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x2a1b
jmp 0x2c9b
movq -0x20(%rbp), %rdi
callq 0x2100
cmpq $0x0, %rax
jne 0x2a34
leaq -0x60(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x2a5f
movq -0x20(%rbp), %rdi
callq 0x5c70
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x2150
leaq -0x60(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x3f, %edx
callq 0x2080
movq -0x20(%rbp), %rdi
leaq 0x669f(%rip), %rsi      # 0x9109
movl $0x5, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x2a93
movq -0x20(%rbp), %rdi
leaq 0x658b(%rip), %rsi      # 0x900f
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2aa1
movq -0x20(%rbp), %rdi
callq 0x2780
jmp 0x2c96
movq -0x20(%rbp), %rdi
leaq 0x661b(%rip), %rsi      # 0x90c7
movl $0x4, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2ac9
movq -0x18(%rbp), %rdi
callq 0x2930
jmp 0x2c94
movq -0x20(%rbp), %rdi
leaq 0x663b(%rip), %rsi      # 0x910f
movl $0x8, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x2afd
movq -0x20(%rbp), %rdi
leaq 0x662a(%rip), %rsi      # 0x9118
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2b0b
movq -0x18(%rbp), %rdi
callq 0x2850
jmp 0x2c92
movq -0x20(%rbp), %rdi
leaq 0x6604(%rip), %rsi      # 0x911a
movl $0x6, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x2b3f
movq -0x20(%rbp), %rdi
leaq 0x65f1(%rip), %rsi      # 0x9121
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2b51
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2620
jmp 0x2c90
movq -0x20(%rbp), %rdi
leaq 0x65c7(%rip), %rsi      # 0x9123
movl $0x4, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x2b80
movq -0x20(%rbp), %rdi
leaq 0x6a72(%rip), %rsi      # 0x95e8
callq 0x21b0
cmpl $0x0, %eax
jne 0x2ba8
movq -0x18(%rbp), %rdi
callq 0x2500
movq -0x18(%rbp), %rdi
callq 0x7310
movq %rax, %rsi
leaq 0x6527(%rip), %rdi      # 0x90c3
movb $0x0, %al
callq 0x2130
jmp 0x2c8e
movq -0x20(%rbp), %rdi
leaq 0x6575(%rip), %rsi      # 0x9128
movl $0x9, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x2bdc
movq -0x20(%rbp), %rdi
leaq 0x6a12(%rip), %rsi      # 0x95df
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2bfb
movq -0x18(%rbp), %rdi
callq 0x7230
movq %rax, %rsi
leaq 0x64d4(%rip), %rdi      # 0x90c3
movb $0x0, %al
callq 0x2130
jmp 0x2c8c
movq -0x20(%rbp), %rdi
leaq 0x652c(%rip), %rsi      # 0x9132
movl $0x7, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2c31
movq -0x18(%rbp), %rdi
callq 0x6fa0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x6ec0
movq %rax, -0x18(%rbp)
jmp 0x2c8a
movq -0x20(%rbp), %rdi
leaq 0x64fe(%rip), %rsi      # 0x913a
movl $0x4, %edx
callq 0x2090
cmpl $0x0, %eax
je 0x2c65
movq -0x20(%rbp), %rdi
leaq 0x69c5(%rip), %rsi      # 0x961b
movl $0x1, %edx
callq 0x2090
cmpl $0x0, %eax
jne 0x2c88
movq -0x18(%rbp), %rdi
callq 0x2560
movq -0x18(%rbp), %rdi
callq 0x7310
movq %rax, %rsi
leaq 0x6442(%rip), %rdi      # 0x90c3
movb $0x0, %al
callq 0x2130
jmp 0x2c8a
jmp 0x2c8c
jmp 0x2c8e
jmp 0x2c90
jmp 0x2c92
jmp 0x2c94
jmp 0x2c96
jmp 0x2a00
movq -0x18(%rbp), %rdi
callq 0x6fa0
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)