// File: sangwoojun[P]rv32emulator/./linenoise.hpp
// Function: linenoise::linenoiseEditInsert(linenoise::linenoiseState*, char const*, int)
inline int linenoiseEditInsert(struct linenoiseState *l, const char* cbuf, int clen) {
    if (l->len < l->buflen) {
        if (l->len == l->pos) {
            memcpy(&l->buf[l->pos],cbuf,clen);
            l->pos+=clen;
            l->len+=clen;;
            l->buf[l->len] = '\0';
            if ((!mlmode && unicodeColumnPos(l->prompt.c_str(), static_cast<int>(l->prompt.length()))+unicodeColumnPos(l->buf,l->len) < l->cols) /* || mlmode */) {
                /* Avoid a full update of the line in the
                 * trivial case. */
                if (write(l->ofd,cbuf,clen) == -1) return -1;
            } else {
                refreshLine(l);
            }
        } else {
            memmove(l->buf+l->pos+clen,l->buf+l->pos,l->len-l->pos);
            memcpy(&l->buf[l->pos],cbuf,clen);
            l->pos+=clen;
            l->len+=clen;
            l->buf[l->len] = '\0';
            refreshLine(l);
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x86b4
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jne 0x8618
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x2190
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x40(%rax), %ecx
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
movb $0x0, (%rax,%rcx)
testb $0x1, 0xa975(%rip)      # 0x12f05
jne 0x860a
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x20e0
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
callq 0x2350
movq -0x28(%rbp), %rdi
movl %eax, %esi
callq 0x96b0
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x40(%rax), %esi
callq 0x96b0
movl %eax, %ecx
movl -0x20(%rbp), %eax
addl %ecx, %eax
movq -0x10(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x860a
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x20a0
cmpq $-0x1, %rax
jne 0x8608
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x86bb
jmp 0x8613
movq -0x10(%rbp), %rdi
callq 0x8280
jmp 0x86b2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rax
addq %rax, %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0x40(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x38(%rcx), %eax
movslq %eax, %rdx
callq 0x23c0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x38(%rax), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x2190
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x38(%rax), %ecx
movl %ecx, 0x38(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x40(%rax), %ecx
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
callq 0x8280
jmp 0x86b4
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop