// File: /workspace/github_c_makefile_star2_O0/endeav0r[P]hvm/src/linenoise.c
// Function: completeLine
static int completeLine(int fd, const char *prompt, char *buf, size_t buflen, size_t *len, size_t *pos, size_t cols) {
    linenoiseCompletions lc = { 0, NULL };
    int nread, nwritten;
    char c = 0;

    completionCallback(buf,&lc);
    if (lc.len == 0) {
        beep();
    } else {
        size_t stop = 0, i = 0;
        size_t clen;

        while(!stop) {
            /* Show completion or original buffer */
            if (i < lc.len) {
                clen = strlen(lc.cvec[i]);
                refreshLine(fd,prompt,lc.cvec[i],clen,clen,cols);
            } else {
                refreshLine(fd,prompt,buf,*len,*pos,cols);
            }

            nread = read(fd,&c,1);
            if (nread <= 0) {
                freeCompletions(&lc);
                return -1;
            }

            switch(c) {
                case 9: /* tab */
                    i = (i+1) % (lc.len+1);
                    if (i == lc.len) beep();
                    break;
                case 27: /* escape */
                    /* Re-show original buffer */
                    if (i < lc.len) {
                        refreshLine(fd,prompt,buf,*len,*pos,cols);
                    }
                    stop = 1;
                    break;
                default:
                    /* Update buffer and return */
                    if (i < lc.len) {
                        nwritten = snprintf(buf,buflen,"%s",lc.cvec[i]);
                        *len = *pos = nwritten;
                    }
                    stop = 1;
                    break;
            }
        }
    }

    freeCompletions(&lc);
    return c; /* Return last read character */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x10(%rbp), %rax
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2150
movb $0x0, -0x49(%rbp)
movq 0x788a(%rip), %rax      # 0xe268
movq -0x18(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq *%rax
cmpq $0x0, -0x40(%rbp)
jne 0x69f9
callq 0x6df0
jmp 0x6b7a
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6a1c
jmp 0x6b78
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6a61
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2100
movq %rax, -0x68(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x68(%rbp), %rcx
movq -0x68(%rbp), %r8
movq 0x10(%rbp), %r9
callq 0x6ba0
jmp 0x6a83
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq 0x10(%rbp), %r9
callq 0x6ba0
movl -0x8(%rbp), %edi
leaq -0x49(%rbp), %rsi
movl $0x1, %edx
callq 0x2190
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jg 0x6ab2
leaq -0x40(%rbp), %rdi
callq 0x6d80
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x6b8a
movsbl -0x49(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x9, %eax
je 0x6aca
jmp 0x6ac0
movl -0x6c(%rbp), %eax
subl $0x1b, %eax
je 0x6af4
jmp 0x6b2a
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jne 0x6af2
callq 0x6df0
jmp 0x6b73
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6b20
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %r8
movq 0x10(%rbp), %r9
callq 0x6ba0
movq $0x1, -0x58(%rbp)
jmp 0x6b73
movq -0x60(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x6b6b
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x2acb(%rip), %rdx      # 0x961a
movb $0x0, %al
callq 0x2140
movl %eax, -0x48(%rbp)
movslq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq $0x1, -0x58(%rbp)
jmp 0x6a09
jmp 0x6b7a
leaq -0x40(%rbp), %rdi
callq 0x6d80
movsbl -0x49(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)