// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rsi, -0x50(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, (%rdx)
movq 0x8(%rdi), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, 0x8899(%rip)      # 0xeb18
je 0x6488
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x8876(%rip), %rdi      # 0xeb08
leaq -0xa0(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq *0x887d(%rip)           # 0xeb20
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
je 0x6408
leaq -0x88(%rbp), %r13
leaq 0x38(%rbx), %rax
movq %rax, -0x48(%rbp)
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
shrq $0x5, %rax
cmpl %eax, %r12d
jge 0x6370
movl 0x10(%rbx), %eax
movl %eax, -0x90(%rbp)
movups (%rbx), %xmm0
movaps %xmm0, -0xa0(%rbp)
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq 0x18(%rbx), %rsi
movq 0x20(%rbx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x69e4
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x30(%r13)
movups (%rcx), %xmm0
movups %xmm0, 0x20(%r13)
movslq %r12d, %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rax
movl 0x8(%rcx,%rax), %edx
movl %edx, 0x38(%rbx)
movl %edx, 0x40(%rbx)
movq (%rcx,%rax), %rax
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
callq 0x6be1
movl -0x60(%rbp), %eax
movl %eax, 0x40(%rbx)
movl -0x68(%rbp), %eax
movl %eax, 0x38(%rbx)
movq -0x98(%rbp), %rax
movq %rax, 0x8(%rbx)
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x6378
callq 0x2180
jmp 0x6378
movq %rbx, %rdi
callq 0x6be1
movl (%rbx), %edi
movq -0x50(%rbp), %rsi
movq %r14, %rdx
callq 0x610f
movl %eax, %r13d
testl %eax, %eax
jle 0x6429
movl (%r14), %eax
cmpl $0x9, %eax
jne 0x63e8
incl %r12d
movq -0x38(%rbp), %rcx
subq -0x40(%rbp), %rcx
movslq %r12d, %rax
sarq $0x5, %rcx
leaq 0x1(%rcx), %rsi
xorl %edx, %edx
divq %rsi
movq %rdx, %r12
cmpl %ecx, %r12d
leaq -0x88(%rbp), %r13
jne 0x62c3
movq 0x7bfa(%rip), %r15      # 0xdfc8
movq (%r15), %rsi
movl $0x7, %edi
callq 0x2240
movq (%r15), %rdi
callq 0x21f0
jmp 0x62c3
cmpl $0x1b, %eax
jne 0x6432
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
shrq $0x5, %rax
cmpl %eax, %r12d
jge 0x646d
movq %rbx, %rdi
callq 0x6be1
jmp 0x646d
movq 0x7bb9(%rip), %rbx      # 0xdfc8
movq (%rbx), %rsi
movl $0x7, %edi
callq 0x2240
movq (%rbx), %rdi
callq 0x21f0
xorl %r13d, %r13d
jmp 0x646d
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
jmp 0x646d
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
shrq $0x5, %rcx
cmpl %ecx, %r12d
jge 0x646d
movq 0x8(%rbx), %rdi
movslq 0x10(%rbx), %rsi
movslq %r12d, %rcx
shlq $0x5, %rcx
movq (%rax,%rcx), %rcx
leaq 0x5229(%rip), %rdx      # 0xb689
xorl %eax, %eax
callq 0x2340
movl %eax, 0x38(%rbx)
movl %eax, 0x40(%rbx)
leaq -0x40(%rbp), %rdi
callq 0x57a8
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20c0
jmp 0x64ad
jmp 0x64ad
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x64b0
callq 0x2180
jmp 0x64b0
jmp 0x64ad
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x57a8
movq %rbx, %rdi
callq 0x2370