// File: /workspace/github_c_makefile_star2_O0/endeav0r[P]hvm/src/linenoise.c
// Function: linenoisePrompt
static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) {
    size_t plen = strlen(prompt);
    size_t pos = 0;
    size_t len = 0;
    size_t cols = getColumns();
    int history_index = 0;

    buf[0] = '\0';
    buflen--; /* Make sure there is always space for the nulterm */

    /* The latest history entry is always our current buffer, that
     * initially is just an empty string. */
    linenoiseHistoryAdd("");
    
    if (write(1,prompt,plen) == -1) return -1;
    while(1) {
        char c;
        int nread;
        char seq[2], seq2[2];

        nread = read(fd,&c,1);
        if (nread <= 0) return len;

        /* Only autocomplete when the callback is set. It returns < 0 when
         * there was an error reading from fd. Otherwise it will return the
         * character that should be handled next. */
        if (c == 9 && completionCallback != NULL) {
            c = completeLine(fd,prompt,buf,buflen,&len,&pos,cols);
            /* Return on errors */
            if (c < 0) return len;
            /* Read next character when 0 */
            if (c == 0) continue;
        }

        switch(c) {
        case 13:    /* enter */
            history_len--;
            free(history[history_len]);
            return (int)len;
        case 3:     /* ctrl-c */
            errno = EAGAIN;
            return -1;
        case 127:   /* backspace */
        case 8:     /* ctrl-h */
            if (pos > 0 && len > 0) {
                memmove(buf+pos-1,buf+pos,len-pos);
                pos--;
                len--;
                buf[len] = '\0';
                refreshLine(fd,prompt,buf,len,pos,cols);
            }
            break;
        case 4:     /* ctrl-d, remove char at right of cursor */
            if (len > 1 && pos < (len-1)) {
                memmove(buf+pos,buf+pos+1,len-pos);
                len--;
                buf[len] = '\0';
                refreshLine(fd,prompt,buf,len,pos,cols);
            } else if (len == 0) {
                history_len--;
                free(history[history_len]);
                return -1;
            }
            break;
        case 20:    /* ctrl-t */
            if (pos > 0 && pos < len) {
                int aux = buf[pos-1];
                buf[pos-1] = buf[pos];
                buf[pos] = aux;
                if (pos != len-1) pos++;
                refreshLine(fd,prompt,buf,len,pos,cols);
            }
            break;
        case 2:     /* ctrl-b */
            goto left_arrow;
        case 6:     /* ctrl-f */
            goto right_arrow;
        case 16:    /* ctrl-p */
            seq[1] = 65;
            goto up_down_arrow;
        case 14:    /* ctrl-n */
            seq[1] = 66;
            goto up_down_arrow;
            break;
        case 27:    /* escape sequence */
            if (read(fd,seq,2) == -1) break;
            if (seq[0] == 91 && seq[1] == 68) {
left_arrow:
                /* left arrow */
                if (pos > 0) {
                    pos--;
                    refreshLine(fd,prompt,buf,len,pos,cols);
                }
            } else if (seq[0] == 91 && seq[1] == 67) {
right_arrow:
                /* right arrow */
                if (pos != len) {
                    pos++;
                    refreshLine(fd,prompt,buf,len,pos,cols);
                }
            } else if (seq[0] == 91 && (seq[1] == 65 || seq[1] == 66)) {
up_down_arrow:
                /* up and down arrow: history */
                if (history_len > 1) {
                    /* Update the current history entry before to
                     * overwrite it with tne next one. */
                    free(history[history_len-1-history_index]);
                    history[history_len-1-history_index] = strdup(buf);
                    /* Show the new entry */
                    history_index += (seq[1] == 65) ? 1 : -1;
                    if (history_index < 0) {
                        history_index = 0;
                        break;
                    } else if (history_index >= history_len) {
                        history_index = history_len-1;
                        break;
                    }
                    strncpy(buf,history[history_len-1-history_index],buflen);
                    buf[buflen] = '\0';
                    len = pos = strlen(buf);
                    refreshLine(fd,prompt,buf,len,pos,cols);
                }
            } else if (seq[0] == 91 && seq[1] > 48 && seq[1] < 55) {
                /* extended escape */
                if (read(fd,seq2,2) == -1) break;
                if (seq[1] == 51 && seq2[0] == 126) {
                    /* delete */
                    if (len > 0 && pos < len) {
                        memmove(buf+pos,buf+pos+1,len-pos-1);
                        len--;
                        buf[len] = '\0';
                        refreshLine(fd,prompt,buf,len,pos,cols);
                    }
                }
            }
            break;
        default:
            if (len < buflen) {
                if (len == pos) {
                    buf[pos] = c;
                    pos++;
                    len++;
                    buf[len] = '\0';
                    if (plen+len < cols) {
                        /* Avoid a full update of the line in the
                         * trivial case. */
                        if (write(fd,&c,1) == -1) return -1;
                    } else {
                        refreshLine(fd,prompt,buf,len,pos,cols);
                    }
                } else {
                    memmove(buf+pos+1,buf+pos,len-pos);
                    buf[pos] = c;
                    len++;
                    pos++;
                    buf[len] = '\0';
                    refreshLine(fd,prompt,buf,len,pos,cols);
                }
            }
            break;
        case 21: /* Ctrl+u, delete the whole line. */
            buf[0] = '\0';
            pos = len = 0;
            refreshLine(fd,prompt,buf,len,pos,cols);
            break;
        case 11: /* Ctrl+k, delete from current to end of line. */
            buf[pos] = '\0';
            len = pos;
            refreshLine(fd,prompt,buf,len,pos,cols);
            break;
        case 1: /* Ctrl+a, go to the start of the line */
            pos = 0;
            refreshLine(fd,prompt,buf,len,pos,cols);
            break;
        case 5: /* ctrl+e, go to the end of the line */
            pos = len;
            refreshLine(fd,prompt,buf,len,pos,cols);
            break;
        case 12: /* ctrl+l, clear screen */
            linenoiseClearScreen();
            refreshLine(fd,prompt,buf,len,pos,cols);
        }
    }
    return len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2100
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
callq 0x6960
cltq
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
leaq 0x3778(%rip), %rdi      # 0x9888
callq 0x5c70
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl $0x1, %edi
callq 0x20e0
cmpq $-0x1, %rax
jne 0x6139
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x688f
jmp 0x613b
movl -0x8(%rbp), %edi
leaq -0x45(%rbp), %rsi
movl $0x1, %edx
callq 0x2190
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jg 0x6161
movq -0x38(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x688f
movsbl -0x45(%rbp), %eax
cmpl $0x9, %eax
jne 0x61bd
cmpq $0x0, 0x80f6(%rip)      # 0xe268
je 0x61bd
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
leaq -0x38(%rbp), %r8
leaq -0x30(%rbp), %r9
movq %rax, (%rsp)
callq 0x69a0
movb %al, -0x45(%rbp)
movsbl -0x45(%rbp), %eax
cmpl $0x0, %eax
jge 0x61b0
movq -0x38(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x688f
movsbl -0x45(%rbp), %eax
cmpl $0x0, %eax
jne 0x61bb
jmp 0x613b
jmp 0x61bd
movsbl -0x45(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x7e, %eax
ja 0x669e
movq -0x60(%rbp), %rax
leaq 0x3493(%rip), %rcx      # 0x9670
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x8084(%rip), %eax      # 0xe270
addl $-0x1, %eax
movl %eax, 0x807b(%rip)      # 0xe270
movq 0x8064(%rip), %rax      # 0xe260
movslq 0x806d(%rip), %rcx      # 0xe270
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x688f
callq 0x2070
movl $0xb, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x688f
cmpq $0x0, -0x30(%rbp)
jbe 0x629e
cmpq $0x0, -0x38(%rbp)
jbe 0x629e
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
addq $-0x1, %rdi
movq -0x10(%rbp), %rsi
addq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
subq -0x30(%rbp), %rdx
callq 0x2250
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x688a
cmpq $0x1, -0x38(%rbp)
jbe 0x6312
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x6312
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq -0x30(%rbp), %rsi
addq $0x1, %rsi
movq -0x38(%rbp), %rdx
subq -0x30(%rbp), %rdx
callq 0x2250
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x634d
cmpq $0x0, -0x38(%rbp)
jne 0x634b
movl 0x7f51(%rip), %eax      # 0xe270
addl $-0x1, %eax
movl %eax, 0x7f48(%rip)      # 0xe270
movq 0x7f31(%rip), %rax      # 0xe260
movslq 0x7f3a(%rip), %rcx      # 0xe270
movq (%rax,%rcx,8), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x688f
jmp 0x634d
jmp 0x688a
cmpq $0x0, -0x30(%rbp)
jbe 0x63dd
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x63dd
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
movl -0x54(%rbp), %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x63c1
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x688a
jmp 0x642b
jmp 0x6473
movb $0x41, -0x4d(%rbp)
jmp 0x64cf
movb $0x42, -0x4d(%rbp)
jmp 0x64cf
movl -0x8(%rbp), %edi
leaq -0x4e(%rbp), %rsi
movl $0x2, %edx
callq 0x2190
cmpq $-0x1, %rax
jne 0x6417
jmp 0x688a
movsbl -0x4e(%rbp), %eax
cmpl $0x5b, %eax
jne 0x645f
movsbl -0x4d(%rbp), %eax
cmpl $0x44, %eax
jne 0x645f
jmp 0x642b
cmpq $0x0, -0x30(%rbp)
jbe 0x645a
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x6699
movsbl -0x4e(%rbp), %eax
cmpl $0x5b, %eax
jne 0x64aa
movsbl -0x4d(%rbp), %eax
cmpl $0x43, %eax
jne 0x64aa
jmp 0x6473
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x64a5
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x6697
movsbl -0x4e(%rbp), %eax
cmpl $0x5b, %eax
jne 0x65d0
movsbl -0x4d(%rbp), %eax
cmpl $0x41, %eax
je 0x64cd
movsbl -0x4d(%rbp), %eax
cmpl $0x42, %eax
jne 0x65d0
jmp 0x64cf
cmpl $0x1, 0x7d9a(%rip)      # 0xe270
jle 0x65cb
movq 0x7d7d(%rip), %rax      # 0xe260
movl 0x7d87(%rip), %ecx      # 0xe270
subl $0x1, %ecx
subl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x10(%rbp), %rdi
callq 0x22c0
movq %rax, %rdx
movq 0x7d52(%rip), %rax      # 0xe260
movl 0x7d5c(%rip), %ecx      # 0xe270
subl $0x1, %ecx
subl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movsbl -0x4d(%rbp), %edx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl $0x41, %edx
cmovel %ecx, %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x654d
movl $0x0, -0x44(%rbp)
jmp 0x688a
movl -0x44(%rbp), %eax
cmpl 0x7d1a(%rip), %eax      # 0xe270
jl 0x6569
movl 0x7d12(%rip), %eax      # 0xe270
subl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x688a
jmp 0x656b
movq -0x10(%rbp), %rdi
movq 0x7cea(%rip), %rax      # 0xe260
movl 0x7cf4(%rip), %ecx      # 0xe270
subl $0x1, %ecx
subl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
movq -0x18(%rbp), %rdx
callq 0x2080
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
callq 0x2100
movq %rax, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x6695
movsbl -0x4e(%rbp), %eax
cmpl $0x5b, %eax
jne 0x6693
movsbl -0x4d(%rbp), %eax
cmpl $0x30, %eax
jle 0x6693
movsbl -0x4d(%rbp), %eax
cmpl $0x37, %eax
jge 0x6693
movl -0x8(%rbp), %edi
leaq -0x50(%rbp), %rsi
movl $0x2, %edx
callq 0x2190
cmpq $-0x1, %rax
jne 0x6613
jmp 0x688a
movsbl -0x4d(%rbp), %eax
cmpl $0x33, %eax
jne 0x6691
movsbl -0x50(%rbp), %eax
cmpl $0x7e, %eax
jne 0x6691
cmpq $0x0, -0x38(%rbp)
jbe 0x668f
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x668f
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq -0x30(%rbp), %rsi
addq $0x1, %rsi
movq -0x38(%rbp), %rdx
subq -0x30(%rbp), %rdx
subq $0x1, %rdx
callq 0x2250
movq -0x38(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x6691
jmp 0x6693
jmp 0x6695
jmp 0x6697
jmp 0x6699
jmp 0x688a
movq -0x38(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x67ae
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x673d
movb -0x45(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rax
addq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x671f
movl -0x8(%rbp), %edi
leaq -0x45(%rbp), %rsi
movl $0x1, %edx
callq 0x20e0
cmpq $-0x1, %rax
jne 0x671d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x688f
jmp 0x673b
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x67ac
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
addq $0x1, %rdi
movq -0x10(%rbp), %rsi
addq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
subq -0x30(%rbp), %rdx
callq 0x2250
movb -0x45(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x67ae
jmp 0x688a
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x688a
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x688a
movq $0x0, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x688a
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x688a
callq 0x5870
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x40(%rbp), %r9
callq 0x6ba0
jmp 0x613b
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)