// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/deps/linenoise/linenoise.c
// Function: refreshMultiLine
static void refreshMultiLine(struct linenoiseState *l) {
    char seq[64];
    int plen = strlen(l->prompt);
    int rows = (plen+l->len+l->cols-1)/l->cols; /* rows used by current buf. */
    int rpos = (plen+l->oldpos+l->cols)/l->cols; /* cursor relative row. */
    int rpos2; /* rpos after refresh. */
    int col; /* colum position, zero-based. */
    int old_rows = l->maxrows;
    int fd = l->ofd, j;
    struct abuf ab;

    /* Update maxrows if needed. */
    if (rows > (int)l->maxrows) l->maxrows = rows;

    /* First step: clear all the lines used before. To do so start by
     * going to the last row. */
    abInit(&ab);
    if (old_rows-rpos > 0) {
        lndebug("go down %d", old_rows-rpos);
        snprintf(seq,64,"\x1b[%dB", old_rows-rpos);
        abAppend(&ab,seq,strlen(seq));
    }

    /* Now for every row clear it, go up. */
    for (j = 0; j < old_rows-1; j++) {
        lndebug("clear+up");
        snprintf(seq,64,"\r\x1b[0K\x1b[1A");
        abAppend(&ab,seq,strlen(seq));
    }

    /* Clean the top line. */
    lndebug("clear");
    snprintf(seq,64,"\r\x1b[0K");
    abAppend(&ab,seq,strlen(seq));

    /* Write the prompt and the current buffer content */
    abAppend(&ab,l->prompt,strlen(l->prompt));
    abAppend(&ab,l->buf,l->len);

    /* Show hits if any. */
    refreshShowHints(&ab,l,plen);

    /* If we are at the very end of the screen with our prompt, we need to
     * emit a newline and move the prompt to the first column. */
    if (l->pos &&
        l->pos == l->len &&
        (l->pos+plen) % l->cols == 0)
    {
        lndebug("<newline>");
        abAppend(&ab,"\n",1);
        snprintf(seq,64,"\r");
        abAppend(&ab,seq,strlen(seq));
        rows++;
        if (rows > (int)l->maxrows) l->maxrows = rows;
    }

    /* Move cursor to right position. */
    rpos2 = (plen+l->pos+l->cols)/l->cols; /* current cursor relative row. */
    lndebug("rpos2 %d", rpos2);

    /* Go up till we reach the expected positon. */
    if (rows-rpos2 > 0) {
        lndebug("go-up %d", rows-rpos2);
        snprintf(seq,64,"\x1b[%dA", rows-rpos2);
        abAppend(&ab,seq,strlen(seq));
    }

    /* Set column. */
    col = (plen+(int)l->pos) % (int)l->cols;
    lndebug("set col %d", 1+col);
    if (col)
        snprintf(seq,64,"\r\x1b[%dC", col);
    else
        snprintf(seq,64,"\r");
    abAppend(&ab,seq,strlen(seq));

    lndebug("\n");
    l->oldpos = l->pos;

    if (write(fd,ab.b,ab.len) == -1) {} /* Can't recover from write error. */
    abFree(&ab);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x101a0
movl %eax, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x8(%rbp), %rcx
addq 0x38(%rcx), %rax
movq -0x8(%rbp), %rcx
addq 0x40(%rcx), %rax
subq $0x1, %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x40(%rcx)
movl %eax, -0x58(%rbp)
movslq -0x54(%rbp), %rax
movq -0x8(%rbp), %rcx
addq 0x30(%rcx), %rax
movq -0x8(%rbp), %rcx
addq 0x40(%rcx), %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x40(%rcx)
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x58(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl %ecx, %eax
jle 0x236d5
movslq -0x58(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
leaq -0x80(%rbp), %rdi
callq 0x23c10
movl -0x68(%rbp), %eax
subl -0x5c(%rbp), %eax
cmpl $0x0, %eax
jle 0x2372c
leaq -0x50(%rbp), %rdi
movl -0x68(%rbp), %ecx
subl -0x5c(%rbp), %ecx
movl $0x40, %esi
leaq 0x6aba1(%rip), %rdx     # 0x8e2a0
movb $0x0, %al
callq 0x101e0
leaq -0x50(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
movq -0x88(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
movl -0x68(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x23788
leaq -0x50(%rbp), %rdi
movl $0x40, %esi
leaq 0x6ab56(%rip), %rdx     # 0x8e2a6
movb $0x0, %al
callq 0x101e0
leaq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
movq -0x90(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x23733
leaq -0x50(%rbp), %rdi
movl $0x40, %esi
leaq 0x68677(%rip), %rdx     # 0x8be0f
movb $0x0, %al
callq 0x101e0
leaq -0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
movq -0xa0(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x101a0
movq -0x98(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movq -0x8(%rbp), %rsi
movl -0x54(%rbp), %edx
leaq -0x80(%rbp), %rdi
callq 0x223e0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x238da
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x238da
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x54(%rbp), %rcx
addq %rcx, %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x40(%rcx)
cmpq $0x0, %rdx
jne 0x238da
leaq -0x80(%rbp), %rdi
leaq 0x68b2e(%rip), %rsi     # 0x8c39b
movl $0x1, %edx
callq 0x22550
leaq -0x50(%rbp), %rdi
movl $0x40, %esi
leaq 0x685a0(%rip), %rdx     # 0x8be27
movb $0x0, %al
callq 0x101e0
leaq -0x50(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
movq -0xa8(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl %ecx, %eax
jle 0x238d8
movslq -0x58(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x238da
movslq -0x54(%rbp), %rax
movq -0x8(%rbp), %rcx
addq 0x28(%rcx), %rax
movq -0x8(%rbp), %rcx
addq 0x40(%rcx), %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x40(%rcx)
movl %eax, -0x60(%rbp)
movl -0x58(%rbp), %eax
subl -0x60(%rbp), %eax
cmpl $0x0, %eax
jle 0x23949
leaq -0x50(%rbp), %rdi
movl -0x58(%rbp), %ecx
subl -0x60(%rbp), %ecx
movl $0x40, %esi
leaq 0x6a994(%rip), %rdx     # 0x8e2b0
movb $0x0, %al
callq 0x101e0
leaq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
movq -0xb0(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movl -0x54(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movq 0x40(%rcx), %rcx
cltd
idivl %ecx
movl %edx, -0x64(%rbp)
cmpl $0x0, -0x64(%rbp)
je 0x23986
leaq -0x50(%rbp), %rdi
movl -0x64(%rbp), %ecx
movl $0x40, %esi
leaq 0x6a939(%rip), %rdx     # 0x8e2b6
movb $0x0, %al
callq 0x101e0
jmp 0x2399d
leaq -0x50(%rbp), %rdi
movl $0x40, %esi
leaq 0x68491(%rip), %rdx     # 0x8be27
movb $0x0, %al
callq 0x101e0
leaq -0x50(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x101a0
movq -0xb8(%rbp), %rsi
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x22550
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x6c(%rbp), %edi
movq -0x80(%rbp), %rsi
movslq -0x78(%rbp), %rdx
callq 0x10150
cmpq $-0x1, %rax
jne 0x239eb
jmp 0x239eb
leaq -0x80(%rbp), %rdi
callq 0x23c30
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)