// File: sangwoojun[P]rv32emulator/./linenoise.hpp
// Function: linenoise::refreshSingleLine(linenoise::linenoiseState*)
inline void refreshSingleLine(struct linenoiseState *l) {
    char seq[64];
    int pcolwid = unicodeColumnPos(l->prompt.c_str(), static_cast<int>(l->prompt.length()));
    int fd = l->ofd;
    char *buf = l->buf;
    int len = l->len;
    int pos = l->pos;
    std::string ab;

    while((pcolwid+unicodeColumnPos(buf, pos)) >= l->cols) {
        int glen = unicodeGraphemeLen(buf, len, 0);
        buf += glen;
        len -= glen;
        pos -= glen;
    }
    while (pcolwid+unicodeColumnPos(buf, len) > l->cols) {
        len -= unicodePrevGraphemeLen(buf, len);
    }

    /* Cursor to left edge */
    snprintf(seq,64,"\r");
    ab += seq;
    /* Write the prompt and the current buffer content */
    ab += l->prompt;
    ab.append(buf, len);
    /* Erase to right */
    snprintf(seq,64,"\x1b[0K");
    ab += seq;
    /* Move cursor to original position. */
    snprintf(seq,64,"\r\x1b[%dC", (int)(unicodeColumnPos(buf, pos)+pcolwid));
    ab += seq;
    if (write(fd,ab.c_str(), static_cast<int>(ab.length())) == -1) {} /* Can't recover from write error. */
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
callq 0x20e0
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
callq 0x2350
movq -0xa0(%rbp), %rdi
movl %eax, %esi
callq 0x96b0
movl %eax, -0x54(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %eax
movl %eax, -0x68(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x22e0
movl -0x54(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x60(%rbp), %rdi
movl -0x68(%rbp), %esi
callq 0x96b0
movl %eax, -0xa4(%rbp)
jmp 0x9454
movl -0xa4(%rbp), %ecx
movl -0xa8(%rbp), %eax
addl %ecx, %eax
movq -0x8(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jl 0x94e5
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %esi
xorl %edx, %edx
callq 0x8e80
movl %eax, -0xac(%rbp)
jmp 0x9481
movl -0xac(%rbp), %eax
movl %eax, -0x98(%rbp)
movl -0x98(%rbp), %ecx
movq -0x60(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x98(%rbp), %ecx
movl -0x64(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0x98(%rbp), %ecx
movl -0x68(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x68(%rbp)
jmp 0x9437
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x2160
jmp 0x9698
jmp 0x94e7
movl -0x54(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x96b0
movl %eax, -0xb0(%rbp)
jmp 0x9504
movl -0xb0(%rbp), %ecx
movl -0xb4(%rbp), %eax
addl %ecx, %eax
movq -0x8(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jle 0x953f
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x8d30
movl %eax, -0xb8(%rbp)
jmp 0x952f
movl -0xb8(%rbp), %ecx
movl -0x64(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x64(%rbp)
jmp 0x94e7
leaq 0x2488(%rip), %rdx      # 0xb9ce
xorl %eax, %eax
leaq -0x50(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
movl $0x40, %esi
callq 0x23b0
movq -0xc0(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x21d0
jmp 0x9572
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
leaq -0x88(%rbp), %rdi
callq 0x2290
jmp 0x9588
movq -0x60(%rbp), %rsi
movslq -0x64(%rbp), %rdx
leaq -0x88(%rbp), %rdi
callq 0x2050
jmp 0x959e
leaq 0x2424(%rip), %rdx      # 0xb9c9
xorl %eax, %eax
leaq -0x50(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
movl $0x40, %esi
callq 0x23b0
movq -0xc8(%rbp), %rsi
leaq -0x88(%rbp), %rdi
callq 0x21d0
jmp 0x95d1
leaq -0x50(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x60(%rbp), %rdi
movl -0x68(%rbp), %esi
callq 0x96b0
movl %eax, -0xcc(%rbp)
jmp 0x95f0
movq -0xd8(%rbp), %rdi
movl -0xcc(%rbp), %ecx
movl -0x54(%rbp), %eax
addl %eax, %ecx
leaq 0x23cd(%rip), %rdx      # 0xb9d6
xorl %eax, %eax
movl $0x40, %esi
callq 0x23b0
leaq -0x88(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x21d0
jmp 0x9627
movl -0x58(%rbp), %eax
movl %eax, -0xec(%rbp)
leaq -0x88(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x20e0
movq -0xf8(%rbp), %rdi
movq %rax, -0xe8(%rbp)
callq 0x2350
movl -0xec(%rbp), %edi
movq -0xe8(%rbp), %rsi
movslq %eax, %rdx
callq 0x20a0
movq %rax, -0xe0(%rbp)
jmp 0x9674
movq -0xe0(%rbp), %rax
cmpq $-0x1, %rax
jne 0x9683
jmp 0x9683
leaq -0x88(%rbp), %rdi
callq 0x2160
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x23e0
nopw %cs:(%rax,%rax)
nop