// File: /workspace/github_cpp_makefile_star2_O1/sangwoojun[P]rv32emulator/./linenoise.hpp
// Function: linenoise::completeLine(linenoise::linenoiseState*, char*, int*)
inline int completeLine(struct linenoiseState *ls, char *cbuf, int *c) {
    std::vector<std::string> lc;
    int nread = 0, nwritten;
    *c = 0;

    completionCallback(ls->buf,lc);
    if (lc.empty()) {
        linenoiseBeep();
    } else {
        int stop = 0, i = 0;

        while(!stop) {
            /* Show completion or original buffer */
            if (i < static_cast<int>(lc.size())) {
                struct linenoiseState saved = *ls;

                ls->len = ls->pos = static_cast<int>(lc[i].size());
                ls->buf = &lc[i][0];
                refreshLine(ls);
                ls->len = saved.len;
                ls->pos = saved.pos;
                ls->buf = saved.buf;
            } else {
                refreshLine(ls);
            }

            //nread = read(ls->ifd,&c,1);
#ifdef _WIN32
            nread = win32read(c);
            if (nread == 1) {
                cbuf[0] = *c;
            }
#else
            nread = unicodeReadUTF8Char(ls->ifd,cbuf,c);
#endif
            if (nread <= 0) {
                *c = -1;
                return nread;
            }

            switch(*c) {
                case 9: /* tab */
                    i = (i+1) % (lc.size()+1);
                    if (i == static_cast<int>(lc.size())) linenoiseBeep();
                    break;
                case 27: /* escape */
                    /* Re-show original buffer */
                    if (i < static_cast<int>(lc.size())) refreshLine(ls);
                    stop = 1;
                    break;
                default:
                    /* Update buffer and return */
                    if (i < static_cast<int>(lc.size())) {
                        nwritten = snprintf(ls->buf,ls->buflen,"%s",&lc[i][0]);
                        ls->len = ls->pos = nwritten;
                    }
                    stop = 1;
                    break;
            }
        }
    }

    return nread;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, -0x58(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, (%rdx)
movq 0x8(%rdi), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, 0x87f9(%rip)      # 0xeb18
je 0x655a
movq %rdx, %rbx
movq %rdi, %r15
leaq 0x87d6(%rip), %rdi      # 0xeb08
leaq -0xb0(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq *0x87dd(%rip)           # 0xeb20
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x6515
leaq 0x38(%r15), %rax
movq %rax, -0x50(%rbp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %rbx, -0x48(%rbp)
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
shrq $0x5, %rax
cmpl %eax, %r13d
jge 0x6426
movl %r14d, %ebx
movl 0x10(%r15), %eax
movl %eax, -0xa0(%rbp)
movups (%r15), %xmm0
movaps %xmm0, -0xb0(%rbp)
leaq -0x88(%rbp), %r12
movq %r12, -0x98(%rbp)
movq 0x18(%r15), %rsi
movq 0x20(%r15), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %r14
movq %r14, %rdi
callq 0x67c2
movq -0x50(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x30(%r14)
movups (%rcx), %xmm0
movups %xmm0, 0x20(%r14)
movslq %r13d, %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rax
movl 0x8(%rcx,%rax), %edx
movl %edx, 0x38(%r15)
movl %edx, 0x40(%r15)
movq (%rcx,%rax), %rax
movq %rax, 0x8(%r15)
movq %r15, %rdi
callq 0x6b31
movl -0x70(%rbp), %eax
movl %eax, 0x40(%r15)
movl -0x78(%rbp), %eax
movl %eax, 0x38(%r15)
movq -0xa8(%rbp), %rax
movq %rax, 0x8(%r15)
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
movl %ebx, %r14d
je 0x6420
callq 0x2180
movq -0x48(%rbp), %rbx
jmp 0x642e
movq %r15, %rdi
callq 0x6b31
movl (%r15), %edi
movq -0x58(%rbp), %rsi
movq %rbx, %rdx
callq 0x61aa
movl %eax, %r12d
testl %eax, %eax
jle 0x6536
movl (%rbx), %eax
cmpl $0x1b, %eax
je 0x64a6
cmpl $0x9, %eax
jne 0x64c7
incl %r13d
movq -0x38(%rbp), %rcx
subq -0x40(%rbp), %rcx
movslq %r13d, %rax
sarq $0x5, %rcx
leaq 0x1(%rcx), %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r13
cmpl %ecx, %r13d
jne 0x650a
movq 0x7b46(%rip), %rax      # 0xdfc8
movl %r14d, %ebx
movq %rax, %r14
movq (%rax), %rsi
movl $0x7, %edi
callq 0x2240
movq (%r14), %rdi
movl %ebx, %r14d
movq -0x48(%rbp), %rbx
callq 0x21f0
jmp 0x650a
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
shrq $0x5, %rax
movl $0x1, %r14d
cmpl %eax, %r13d
jge 0x650a
movq %r15, %rdi
callq 0x6b31
jmp 0x650a
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
movl $0x1, %r14d
cmpl %ecx, %r13d
jge 0x650a
movq 0x8(%r15), %rdi
movslq 0x10(%r15), %rsi
movslq %r13d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rcx
leaq 0x51f4(%rip), %rdx      # 0xb6ef
xorl %eax, %eax
callq 0x2340
movl %eax, 0x38(%r15)
movl %eax, 0x40(%r15)
testl %r14d, %r14d
je 0x6363
jmp 0x653c
movq 0x7aac(%rip), %rbx      # 0xdfc8
movq (%rbx), %rsi
movl $0x7, %edi
callq 0x2240
movq (%rbx), %rdi
callq 0x21f0
xorl %r12d, %r12d
jmp 0x653c
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
leaq -0x40(%rbp), %rdi
callq 0x57c8
movl %r12d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20c0
jmp 0x6579
jmp 0x6579
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x657c
callq 0x2180
jmp 0x657c
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x57c8
movq %rbx, %rdi
callq 0x2370