// File: /workspace/github_cpp_makefile_star2_O1/sangwoojun[P]rv32emulator/./linenoise.hpp
// Function: linenoise::linenoiseEdit(int, int, char*, int, char const*)
inline int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, int buflen, const char *prompt)
{
    struct linenoiseState l;

    /* Populate the linenoise state that we pass to functions implementing
     * specific editing functionalities. */
    l.ifd = stdin_fd;
    l.ofd = stdout_fd;
    l.buf = buf;
    l.buflen = buflen;
    l.prompt = prompt;
    l.oldcolpos = l.pos = 0;
    l.len = 0;
    l.cols = getColumns(stdin_fd, stdout_fd);
    l.maxrows = 0;
    l.history_index = 0;

    /* Buffer starts empty. */
    l.buf[0] = '\0';
    l.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. */
    AddHistory("");

    if (write(l.ofd,prompt, static_cast<int>(l.prompt.length())) == -1) return -1;
    while(1) {
        int c;
        char cbuf[4];
        int nread;
        char seq[3];

#ifdef _WIN32
        nread = win32read(&c);
        if (nread == 1) {
            cbuf[0] = c;
        }
#else
        nread = unicodeReadUTF8Char(l.ifd,cbuf,&c);
#endif
        if (nread <= 0) return (int)l.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) {
            nread = completeLine(&l,cbuf,&c);
            /* Return on errors */
            if (c < 0) return l.len;
            /* Read next character when 0 */
            if (c == 0) continue;
        }

        switch(c) {
        case ENTER:    /* enter */
            if (!history.empty()) history.pop_back();
            if (mlmode) linenoiseEditMoveEnd(&l);
            return (int)l.len;
        case CTRL_C:     /* ctrl-c */
            errno = EAGAIN;
            return -1;
        case BACKSPACE:   /* backspace */
        case 8:     /* ctrl-h */
            linenoiseEditBackspace(&l);
            break;
        case CTRL_D:     /* ctrl-d, remove char at right of cursor, or if the
                            line is empty, act as end-of-file. */
            if (l.len > 0) {
                linenoiseEditDelete(&l);
            } else {
                history.pop_back();
                return -1;
            }
            break;
        case CTRL_T:    /* ctrl-t, swaps current character with previous. */
            if (l.pos > 0 && l.pos < l.len) {
                char aux = buf[l.pos-1];
                buf[l.pos-1] = buf[l.pos];
                buf[l.pos] = aux;
                if (l.pos != l.len-1) l.pos++;
                refreshLine(&l);
            }
            break;
        case CTRL_B:     /* ctrl-b */
            linenoiseEditMoveLeft(&l);
            break;
        case CTRL_F:     /* ctrl-f */
            linenoiseEditMoveRight(&l);
            break;
        case CTRL_P:    /* ctrl-p */
            linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_PREV);
            break;
        case CTRL_N:    /* ctrl-n */
            linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_NEXT);
            break;
        case ESC:    /* escape sequence */
            /* Read the next two bytes representing the escape sequence.
             * Use two calls to handle slow terminals returning the two
             * chars at different times. */
            if (read(l.ifd,seq,1) == -1) break;
            if (read(l.ifd,seq+1,1) == -1) break;

            /* ESC [ sequences. */
            if (seq[0] == '[') {
                if (seq[1] >= '0' && seq[1] <= '9') {
                    /* Extended escape, read additional byte. */
                    if (read(l.ifd,seq+2,1) == -1) break;
                    if (seq[2] == '~') {
                        switch(seq[1]) {
                        case '3': /* Delete key. */
                            linenoiseEditDelete(&l);
                            break;
                        }
                    }
                } else {
                    switch(seq[1]) {
                    case 'A': /* Up */
                        linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_PREV);
                        break;
                    case 'B': /* Down */
                        linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_NEXT);
                        break;
                    case 'C': /* Right */
                        linenoiseEditMoveRight(&l);
                        break;
                    case 'D': /* Left */
                        linenoiseEditMoveLeft(&l);
                        break;
                    case 'H': /* Home */
                        linenoiseEditMoveHome(&l);
                        break;
                    case 'F': /* End*/
                        linenoiseEditMoveEnd(&l);
                        break;
                    }
                }
            }

            /* ESC O sequences. */
            else if (seq[0] == 'O') {
                switch(seq[1]) {
                case 'H': /* Home */
                    linenoiseEditMoveHome(&l);
                    break;
                case 'F': /* End*/
                    linenoiseEditMoveEnd(&l);
                    break;
                }
            }
            break;
        default:
            if (linenoiseEditInsert(&l,cbuf,nread)) return -1;
            break;
        case CTRL_U: /* Ctrl+u, delete the whole line. */
            buf[0] = '\0';
            l.pos = l.len = 0;
            refreshLine(&l);
            break;
        case CTRL_K: /* Ctrl+k, delete from current to end of line. */
            buf[l.pos] = '\0';
            l.len = l.pos;
            refreshLine(&l);
            break;
        case CTRL_A: /* Ctrl+a, go to the start of the line */
            linenoiseEditMoveHome(&l);
            break;
        case CTRL_E: /* ctrl+e, go to the end of the line */
            linenoiseEditMoveEnd(&l);
            break;
        case CTRL_L: /* ctrl+l, clear screen */
            linenoiseClearScreen();
            refreshLine(&l);
            break;
        case CTRL_W: /* ctrl+w, delete previous word */
            linenoiseEditDeletePrevWord(&l);
            break;
        }
    }
    return l.len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r8, %r14
movl %esi, %ebx
movl %edi, %r15d
leaq -0x68(%rbp), %r12
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
movl %edi, -0x28(%r13)
movl %esi, -0x24(%r13)
movq %rdx, -0x88(%rbp)
movq %rdx, -0x20(%r13)
movl %ecx, -0x18(%r13)
movq %r8, %rdi
callq 0x20f0
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
movq %r14, %rcx
movq %rax, %r8
callq 0x22f0
movq $0x0, -0x48(%rbp)
movl $0x0, -0x40(%rbp)
movl %r15d, %edi
movl %ebx, %esi
callq 0x5fae
movl %eax, -0x3c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x78(%rbp), %rax
movb $0x0, (%rax)
decl -0x70(%rbp)
movq 0x90f4(%rip), %rdi      # 0xeb30
cmpq %rdi, 0x90e5(%rip)      # 0xeb28
je 0x5a59
addq $-0x20, %rdi
leaq 0x5cb6(%rip), %rsi      # 0xb706
callq 0x2080
testl %eax, %eax
je 0x5ac3
movq 0x90d0(%rip), %rax      # 0xeb30
movq 0x90c1(%rip), %rsi      # 0xeb28
subq %rsi, %rax
cmpq $0xc80, %rax            # imm = 0xC80
jne 0x5a7e
leaq 0x90af(%rip), %rdi      # 0xeb28
callq 0x6e7c
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x5c76(%rip), %rdx      # 0xb706
leaq -0xa8(%rbp), %rdi
movq %rdx, %rsi
callq 0x7158
leaq 0x9082(%rip), %rdi      # 0xeb28
leaq -0xa8(%rbp), %rsi
callq 0x6eee
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x5ac3
callq 0x2180
movl -0x7c(%rbp), %edi
movslq -0x60(%rbp), %rdx
movq %r14, %rsi
callq 0x20a0
cmpq $-0x1, %rax
je 0x5f20
leaq -0xac(%rbp), %r12
leaq -0xa8(%rbp), %r13
movq -0x88(%rbp), %r15
movl -0x80(%rbp), %edi
movq %r12, %rsi
movq %r13, %rdx
callq 0x61aa
testl %eax, %eax
jle 0x5b69
cmpl $0x9, -0xa8(%rbp)
jne 0x5b30
cmpq $0x0, 0x9004(%rip)      # 0xeb18
je 0x5b30
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x62df
cmpl $0x0, -0xa8(%rbp)
js 0x5b69
je 0x5b77
movl -0xa8(%rbp), %edx
leal -0x1(%rdx), %ecx
cmpl $0x1a, %ecx
ja 0x5b81
movl $0x1, %ebx
leaq 0x594e(%rip), %rdx      # 0xb498
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x0, -0x48(%rbp)
je 0x5ef7
movl $0x0, -0x48(%rbp)
jmp 0x5eee
movl $0x1, %ebx
movl -0x40(%rbp), %r14d
jmp 0x5ef9
movl $0x2, %ebx
jmp 0x5ef9
cmpl $0x7f, %edx
jne 0x5bdc
movl -0x48(%rbp), %esi
testl %esi, %esi
jle 0x5ef7
cmpl $0x0, -0x40(%rbp)
jle 0x5ef7
movq -0x78(%rbp), %rdi
callq 0x685b
movl %eax, %ebx
movslq -0x48(%rbp), %rax
movq -0x78(%rbp), %rsi
addq %rax, %rsi
movslq %ebx, %r15
movq %rsi, %rdi
subq %r15, %rdi
movslq -0x40(%rbp), %rdx
subq %rax, %rdx
callq 0x2350
subl %ebx, -0x48(%rbp)
movslq -0x40(%rbp), %rax
subq %r15, %rax
movq -0x88(%rbp), %r15
jmp 0x5cf2
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x66e9
testl %eax, %eax
je 0x5ef7
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x1, %ebx
jmp 0x5ef9
movslq -0x48(%rbp), %rax
testq %rax, %rax
jle 0x5c27
movq -0x78(%rbp), %rcx
movl %eax, %edx
movl %edx, %esi
cmpb $0x20, -0x1(%rcx,%rsi)
jne 0x5c27
leal -0x1(%rdx), %esi
movl %esi, -0x48(%rbp)
cmpl $0x1, %edx
movl %esi, %edx
jg 0x5c11
movl -0x48(%rbp), %ebx
testl %ebx, %ebx
jle 0x5c4a
movq -0x78(%rbp), %rcx
movl %ebx, %edx
cmpb $0x20, -0x1(%rcx,%rdx)
je 0x5c4a
leal -0x1(%rbx), %edx
movl %edx, -0x48(%rbp)
cmpl $0x1, %ebx
movl %edx, %ebx
jg 0x5c32
xorl %ebx, %ebx
movq -0x78(%rbp), %rcx
movslq %ebx, %rdi
subl %eax, %ebx
addq %rcx, %rdi
movq %rax, %rsi
addq %rcx, %rsi
movl -0x40(%rbp), %ecx
subl %eax, %ecx
incl %ecx
movslq %ecx, %rdx
callq 0x2350
addl %ebx, -0x40(%rbp)
jmp 0x5eee
movq 0x8eb6(%rip), %rax      # 0xeb30
cmpq %rax, 0x8ea7(%rip)      # 0xeb28
je 0x5b6e
leaq -0x20(%rax), %rcx
movq %rcx, 0x8e9e(%rip)      # 0xeb30
movq -0x20(%rax), %rdi
addq $-0x10, %rax
cmpq %rax, %rdi
je 0x5b6e
callq 0x2180
jmp 0x5b6e
movl -0x40(%rbp), %esi
testl %esi, %esi
jle 0x5e7c
movl -0x48(%rbp), %edx
cmpl %esi, %edx
jge 0x5ef7
movq -0x78(%rbp), %rdi
callq 0x69ca
movslq -0x48(%rbp), %rdi
movslq %eax, %rbx
leal (%rbx,%rdi), %eax
addq -0x78(%rbp), %rdi
leaq (%rdi,%rbx), %rsi
movl -0x40(%rbp), %ecx
subl %eax, %ecx
movslq %ecx, %rdx
callq 0x2350
movslq -0x40(%rbp), %rax
subq %rbx, %rax
movl %eax, -0x40(%rbp)
movq -0x78(%rbp), %rcx
movb $0x0, (%rcx,%rax)
jmp 0x5eee
callq 0x2030
movl $0xb, (%rax)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x5ef9
movslq -0x48(%rbp), %rax
movb $0x0, (%r15,%rax)
movl %eax, -0x40(%rbp)
jmp 0x5eee
movl -0x48(%rbp), %esi
testl %esi, %esi
jle 0x5ef7
movq -0x78(%rbp), %rdi
callq 0x685b
subl %eax, -0x48(%rbp)
jmp 0x5eee
movb $0x0, (%r15)
xorl %eax, %eax
movl %eax, -0x40(%rbp)
jmp 0x5eeb
movl -0x48(%rbp), %ecx
movl -0x40(%rbp), %eax
testl %ecx, %ecx
setg %dl
cmpl %eax, %ecx
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x5ef7
movl %ecx, %ecx
rolw $0x8, -0x1(%r15,%rcx)
decl %eax
cmpl %eax, %ecx
je 0x5d85
incl %ecx
movl %ecx, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6b31
jmp 0x5ef7
movl -0x48(%rbp), %edx
movl -0x40(%rbp), %esi
cmpl %esi, %edx
je 0x5ef7
movq -0x78(%rbp), %rdi
callq 0x69ca
addl %eax, -0x48(%rbp)
jmp 0x5eee
movl $0x7, %edx
movl $0x1, %edi
leaq 0x5c8a(%rip), %rsi      # 0xba4d
callq 0x20a0
jmp 0x5eee
movl -0x80(%rbp), %edi
movl $0x1, %edx
leaq -0x2b(%rbp), %rsi
callq 0x22b0
cmpq $-0x1, %rax
je 0x5ef7
movl -0x80(%rbp), %edi
movl $0x1, %edx
leaq -0x2a(%rbp), %rsi
callq 0x22b0
cmpq $-0x1, %rax
je 0x5ef7
movzbl -0x2b(%rbp), %eax
cmpl $0x4f, %eax
je 0x5ea8
cmpl $0x5b, %eax
jne 0x5ef7
movzbl -0x2a(%rbp), %eax
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x5ebc
movl -0x80(%rbp), %edi
movl $0x1, %edx
leaq -0x29(%rbp), %rsi
callq 0x22b0
cmpq $-0x1, %rax
je 0x5ef7
cmpb $0x7e, -0x29(%rbp)
jne 0x5ef7
cmpb $0x33, -0x2a(%rbp)
jne 0x5ef7
movl -0x40(%rbp), %esi
testl %esi, %esi
jle 0x5ef7
movl -0x48(%rbp), %edx
cmpl %esi, %edx
jge 0x5ef7
movq -0x78(%rbp), %rdi
callq 0x69ca
jmp 0x5ccc
movq 0x8cad(%rip), %rax      # 0xeb30
leaq -0x20(%rax), %rcx
movq %rcx, 0x8ca2(%rip)      # 0xeb30
movq -0x20(%rax), %rdi
addq $-0x10, %rax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpq %rax, %rdi
je 0x5ef9
callq 0x2180
jmp 0x5ef9
movzbl -0x2a(%rbp), %eax
cmpl $0x46, %eax
je 0x5ee3
cmpl $0x48, %eax
je 0x5b53
jmp 0x5ef7
addl $-0x41, %eax
cmpl $0x7, %eax
ja 0x5ef7
leaq 0x5639(%rip), %rcx      # 0xb504
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %ebx, %ebx
leaq -0x80(%rbp), %rdi
movl %ebx, %esi
callq 0x65e6
jmp 0x5ef7
movl -0x40(%rbp), %eax
cmpl %eax, -0x48(%rbp)
je 0x5ef7
movl %eax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6b31
xorl %ebx, %ebx
testb $0x1, %bl
je 0x5af1
jmp 0x5f1a
leaq -0x80(%rbp), %rdi
callq 0x658d
jmp 0x5ef7
leaq -0x80(%rbp), %rdi
callq 0x65b8
jmp 0x5ef7
leaq -0x58(%rbp), %r13
jmp 0x5f26
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x5f34
callq 0x2180
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5f63
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0x5f66
callq 0x2180
jmp 0x5f66
jmp 0x5f63
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5f78
callq 0x2180
movq %rbx, %rdi
callq 0x2370