// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/deps/linenoise/linenoise.c
// Function: linenoiseEdit
static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t 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.plen = strlen(prompt);
    l.oldpos = 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. */
    linenoiseHistoryAdd("");

    if (write(l.ofd,prompt,l.plen) == -1) return -1;
    while(1) {
        char c;
        int nread;
        char seq[3];

        nread = read(l.ifd,&c,1);
        if (nread <= 0) return 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) {
            c = completeLine(&l);
            /* Return on errors */
            if (c < 0) return l.len;
            /* Read next character when 0 */
            if (c == 0) continue;
        }

        switch(c) {
        case ENTER:    /* enter */
            history_len--;
            free(history[history_len]);
            if (mlmode) linenoiseEditMoveEnd(&l);
            if (hintsCallback) {
                /* Force a refresh without hints to leave the previous
                 * line as the user typed it after a newline. */
                linenoiseHintsCallback *hc = hintsCallback;
                hintsCallback = NULL;
                refreshLine(&l);
                hintsCallback = hc;
            }
            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_len--;
                free(history[history_len]);
                return -1;
            }
            break;
        case CTRL_T:    /* ctrl-t, swaps current character with previous. */
            if (l.pos > 0 && l.pos < l.len) {
                int 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,c)) 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
subq $0xc0, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0x101a0
movq %rax, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movl -0x8(%rbp), %edi
movl -0xc(%rbp), %esi
callq 0x24210
cltq
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x78(%rbp), %rax
movb $0x0, (%rax)
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
leaq 0x6a578(%rip), %rdi     # 0x8e2e8
callq 0x23250
movl -0x7c(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x10150
cmpq $-0x1, %rax
jne 0x23d97
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x241fc
jmp 0x23d99
movl -0x80(%rbp), %edi
leaq -0x81(%rbp), %rsi
movl $0x1, %edx
callq 0x102b0
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
jg 0x23dc8
movq -0x48(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x241fc
movsbl -0x81(%rbp), %eax
cmpl $0x9, %eax
jne 0x23e15
cmpq $0x0, 0x7d854(%rip)     # 0xa1630
je 0x23e15
leaq -0x80(%rbp), %rdi
callq 0x24310
movb %al, -0x81(%rbp)
movsbl -0x81(%rbp), %eax
cmpl $0x0, %eax
jge 0x23e05
movq -0x48(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x241fc
movsbl -0x81(%rbp), %eax
cmpl $0x0, %eax
jne 0x23e13
jmp 0x23d99
jmp 0x23e15
movsbl -0x81(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0xa8(%rbp)
subl $0x7e, %eax
ja 0x24167
movq -0xa8(%rbp), %rax
leaq 0x6a1aa(%rip), %rcx     # 0x8dfe8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x7d7fb(%rip), %eax     # 0xa1648
addl $-0x1, %eax
movl %eax, 0x7d7f2(%rip)     # 0xa1648
movq 0x7d7f3(%rip), %rax     # 0xa1650
movslq 0x7d7e4(%rip), %rcx     # 0xa1648
movq (%rax,%rcx,8), %rdi
callq 0x10050
cmpl $0x0, 0x7d7b4(%rip)     # 0xa1628
je 0x23e7f
leaq -0x80(%rbp), %rdi
callq 0x22850
cmpq $0x0, 0x7d7b1(%rip)     # 0xa1638
je 0x23eb9
movq 0x7d7a8(%rip), %rax     # 0xa1638
movq %rax, -0x98(%rbp)
movq $0x0, 0x7d796(%rip) # 0xa1638
leaq -0x80(%rbp), %rdi
callq 0x22760
movq -0x98(%rbp), %rax
movq %rax, 0x7d77f(%rip)     # 0xa1638
movq -0x48(%rbp), %rax
movl %eax, -0x4(%rbp)
jmp 0x241fc
callq 0x10080
movl $0xb, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x241fc
leaq -0x80(%rbp), %rdi
callq 0x22a80
jmp 0x241f7
cmpq $0x0, -0x48(%rbp)
jbe 0x23efc
leaq -0x80(%rbp), %rdi
callq 0x229e0
jmp 0x23f2e
movl 0x7d746(%rip), %eax     # 0xa1648
addl $-0x1, %eax
movl %eax, 0x7d73d(%rip)     # 0xa1648
movq 0x7d73e(%rip), %rax     # 0xa1650
movslq 0x7d72f(%rip), %rcx     # 0xa1648
movq (%rax,%rcx,8), %rdi
callq 0x10050
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x241fc
jmp 0x241f7
cmpq $0x0, -0x58(%rbp)
jbe 0x23fad
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x23fad
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x9c(%rbp)
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
movb %dl, (%rax,%rcx)
movl -0x9c(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x23fa4
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x22760
jmp 0x241f7
leaq -0x80(%rbp), %rdi
callq 0x22790
jmp 0x241f7
leaq -0x80(%rbp), %rdi
callq 0x227d0
jmp 0x241f7
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0x22890
jmp 0x241f7
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x22890
jmp 0x241f7
movl -0x80(%rbp), %edi
leaq -0x8b(%rbp), %rsi
movl $0x1, %edx
callq 0x102b0
cmpq $-0x1, %rax
jne 0x24010
jmp 0x241f7
movl -0x80(%rbp), %edi
leaq -0x8b(%rbp), %rsi
addq $0x1, %rsi
movl $0x1, %edx
callq 0x102b0
cmpq $-0x1, %rax
jne 0x24033
jmp 0x241f7
movsbl -0x8b(%rbp), %eax
cmpl $0x5b, %eax
jne 0x2411d
movsbl -0x8a(%rbp), %eax
cmpl $0x30, %eax
jl 0x240a3
movsbl -0x8a(%rbp), %eax
cmpl $0x39, %eax
jg 0x240a3
movl -0x80(%rbp), %edi
leaq -0x8b(%rbp), %rsi
addq $0x2, %rsi
movl $0x1, %edx
callq 0x102b0
cmpq $-0x1, %rax
jne 0x2407e
jmp 0x241f7
movsbl -0x89(%rbp), %eax
cmpl $0x7e, %eax
jne 0x240a1
movb -0x8a(%rbp), %al
subb $0x33, %al
jne 0x2409f
jmp 0x24096
leaq -0x80(%rbp), %rdi
callq 0x229e0
jmp 0x240a1
jmp 0x2411b
movsbl -0x8a(%rbp), %eax
addl $-0x41, %eax
movl %eax, %ecx
movq %rcx, -0xb0(%rbp)
subl $0x7, %eax
ja 0x24119
movq -0xb0(%rbp), %rax
leaq 0x6a11b(%rip), %rcx     # 0x8e1e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
callq 0x22890
jmp 0x24119
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x22890
jmp 0x24119
leaq -0x80(%rbp), %rdi
callq 0x227d0
jmp 0x24119
leaq -0x80(%rbp), %rdi
callq 0x22790
jmp 0x24119
leaq -0x80(%rbp), %rdi
callq 0x22810
jmp 0x24119
leaq -0x80(%rbp), %rdi
callq 0x22850
jmp 0x2411b
jmp 0x24162
movsbl -0x8b(%rbp), %eax
cmpl $0x4f, %eax
jne 0x24160
movsbl -0x8a(%rbp), %eax
movl %eax, -0xb4(%rbp)
subl $0x46, %eax
je 0x24155
jmp 0x2413d
movl -0xb4(%rbp), %eax
subl $0x48, %eax
jne 0x2415e
jmp 0x2414a
leaq -0x80(%rbp), %rdi
callq 0x22810
jmp 0x2415e
leaq -0x80(%rbp), %rdi
callq 0x22850
jmp 0x24160
jmp 0x24162
jmp 0x241f7
leaq -0x80(%rbp), %rdi
movsbl -0x81(%rbp), %esi
callq 0x225d0
cmpl $0x0, %eax
je 0x24185
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x241fc
jmp 0x241f7
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x22760
jmp 0x241f7
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x22760
jmp 0x241f7
leaq -0x80(%rbp), %rdi
callq 0x22810
jmp 0x241f7
leaq -0x80(%rbp), %rdi
callq 0x22850
jmp 0x241f7
callq 0x22290
leaq -0x80(%rbp), %rdi
callq 0x22760
jmp 0x241f7
leaq -0x80(%rbp), %rdi
callq 0x22b30
jmp 0x23d99
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)