// File: /workspace/github_cpp_makefile_star2_O1/andrakis[P]alisp/contrib/linenoise-ng/src/linenoise.cpp
// Function: dynamicRefresh(PromptBase&, char32_t*, int, int)
static void dynamicRefresh(PromptBase& pi, char32_t* buf32, int len, int pos) {
  // calculate the position of the end of the prompt
  int xEndOfPrompt, yEndOfPrompt;
  calculateScreenPosition(0, 0, pi.promptScreenColumns, pi.promptChars,
                          xEndOfPrompt, yEndOfPrompt);
  pi.promptIndentation = xEndOfPrompt;

  // calculate the position of the end of the input line
  int xEndOfInput, yEndOfInput;
  calculateScreenPosition(xEndOfPrompt, yEndOfPrompt, pi.promptScreenColumns,
                          calculateColumnPosition(buf32, len), xEndOfInput,
                          yEndOfInput);

  // calculate the desired position of the cursor
  int xCursorPos, yCursorPos;
  calculateScreenPosition(xEndOfPrompt, yEndOfPrompt, pi.promptScreenColumns,
                          calculateColumnPosition(buf32, pos), xCursorPos,
                          yCursorPos);

#ifdef _WIN32
  // position at the start of the prompt, clear to end of previous input
  CONSOLE_SCREEN_BUFFER_INFO inf;
  GetConsoleScreenBufferInfo(console_out, &inf);
  inf.dwCursorPosition.X = 0;
  inf.dwCursorPosition.Y -= pi.promptCursorRowOffset /*- pi.promptExtraLines*/;
  SetConsoleCursorPosition(console_out, inf.dwCursorPosition);
  DWORD count;
  FillConsoleOutputCharacterA(console_out, ' ',
                              pi.promptPreviousLen + pi.promptPreviousInputLen,
                              inf.dwCursorPosition, &count);
  pi.promptPreviousLen = pi.promptIndentation;
  pi.promptPreviousInputLen = len;

  // display the prompt
  if (!pi.write()) return;

  // display the input line
  if (write32(1, buf32, len) == -1) return;

  // position the cursor
  GetConsoleScreenBufferInfo(console_out, &inf);
  inf.dwCursorPosition.X = xCursorPos;  // 0-based on Win32
  inf.dwCursorPosition.Y -= yEndOfInput - yCursorPos;
  SetConsoleCursorPosition(console_out, inf.dwCursorPosition);
#else  // _WIN32
  char seq[64];
  int cursorRowMovement = pi.promptCursorRowOffset - pi.promptExtraLines;
  if (cursorRowMovement > 0) {  // move the cursor up as required
    snprintf(seq, sizeof seq, "\x1b[%dA", cursorRowMovement);
    if (write(1, seq, strlen(seq)) == -1) return;
  }
  // position at the start of the prompt, clear to end of screen
  snprintf(seq, sizeof seq, "\x1b[1G\x1b[J");  // 1-based on VT100
  if (write(1, seq, strlen(seq)) == -1) return;

  // display the prompt
  if (!pi.write()) return;

  // display the input line
  if (write32(1, buf32, len) == -1) return;

  // we have to generate our own newline on line wrap
  if (xEndOfInput == 0 && yEndOfInput > 0)
    if (write(1, "\n", 1) == -1) return;

  // position the cursor
  cursorRowMovement = yEndOfInput - yCursorPos;
  if (cursorRowMovement > 0) {  // move the cursor up as required
    snprintf(seq, sizeof seq, "\x1b[%dA", cursorRowMovement);
    if (write(1, seq, strlen(seq)) == -1) return;
  }
  // position the cursor within the line
  snprintf(seq, sizeof seq, "\x1b[%dG", xCursorPos + 1);  // 1-based on VT100
  if (write(1, seq, strlen(seq)) == -1) return;
#endif

  pi.promptCursorRowOffset =
      pi.promptExtraLines + yCursorPos;  // remember row for next pass
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %ecx, %r12d
movl %edx, %r14d
movq %rsi, 0x18(%rsp)
movl 0x18(%rdi), %eax
movq %rdi, 0x10(%rsp)
movl 0x34(%rdi), %ebx
xorl %edx, %edx
movl $0x0, %ecx
movl $0x0, %ebp
testl %eax, %eax
jle 0x11cf2
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl %ebx, %eax
movl %ebx, %ecx
cmovll %eax, %ecx
incl %ebp
subl %ecx, %eax
jg 0x11ce5
xorl %eax, %eax
cmpl %ebx, %ecx
cmovnel %ecx, %edx
movq %rdx, 0x8(%rsp)
sete %al
movq %rax, 0x28(%rsp)
leal (%rbp,%rax), %r13d
movq 0x10(%rsp), %rax
movl %edx, 0x24(%rax)
movslq %r14d, %rsi
movq 0x18(%rsp), %rdi
callq 0x1575d
movq 0x8(%rsp), %rcx
cmpl $-0x1, %eax
movl %r14d, 0x24(%rsp)
cmovel %r14d, %eax
movl %ecx, %r14d
movl %r13d, %r15d
testl %eax, %eax
jle 0x11d67
movq 0x28(%rsp), %rdx
leal (%rdx,%rbp), %r15d
decl %r15d
movl %ecx, %edx
movl %edx, %ecx
leal (%rax,%rcx), %edx
movl %ebx, %r14d
subl %ecx, %r14d
cmpl %ebx, %edx
cmovll %eax, %r14d
incl %r15d
xorl %edx, %edx
subl %r14d, %eax
jg 0x11d49
addl %ecx, %r14d
cmpl %ebx, %r14d
sete 0x3(%rsp)
movq 0x10(%rsp), %rax
movl 0x34(%rax), %eax
movl %eax, 0x4(%rsp)
movslq %r12d, %r12
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x1575d
cmpl $-0x1, %eax
cmovnel %eax, %r12d
testl %r12d, %r12d
jle 0x11dcc
movq 0x28(%rsp), %rax
leal (%rax,%rbp), %r13d
decl %r13d
movq 0x8(%rsp), %rdx
movl 0x4(%rsp), %esi
movl %edx, %eax
leal (%r12,%rax), %edx
movl %esi, %ecx
subl %eax, %ecx
cmpl %esi, %edx
cmovll %r12d, %ecx
incl %r13d
xorl %edx, %edx
subl %ecx, %r12d
jg 0x11dac
addl %eax, %ecx
movl %ecx, %eax
jmp 0x11dd5
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %esi
movq %rax, 0x8(%rsp)
cmpl %esi, %eax
sete %bpl
movq 0x10(%rsp), %rax
movl 0x30(%rax), %ecx
subl 0x20(%rax), %ecx
jle 0x11e2a
leaq 0xfd30(%rip), %rdx      # 0x21b24
leaq 0x30(%rsp), %r12
movl $0x40, %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x7590
movq %r12, %rdi
callq 0x7180
movl $0x1, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7130
cmpq $-0x1, %rax
je 0x11f73
movabsq $0x4a5b1b47315b1b, %rax # imm = 0x4A5B1B47315B1B
leaq 0x30(%rsp), %r12
movq %rax, (%r12)
movq %r12, %rdi
callq 0x7180
movl $0x1, %edi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7130
cmpq $-0x1, %rax
je 0x11f73
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movl 0x1c(%rax), %esi
callq 0x10581
cmpl $-0x1, %eax
je 0x11f73
movq 0x18(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x10581
cmpl $-0x1, %eax
je 0x11f73
xorl %eax, %eax
movb 0x3(%rsp), %cl
movb %cl, %al
addl %eax, %r15d
cmpl %ebx, %r14d
setne %al
testl %r14d, %r14d
setne %cl
testb %cl, %al
jne 0x11ed0
testl %r15d, %r15d
jle 0x11ed0
leaq 0xfd6f(%rip), %rsi      # 0x21c26
movl $0x1, %edx
movl $0x1, %edi
callq 0x7130
cmpq $-0x1, %rax
je 0x11f73
xorl %eax, %eax
movb %bpl, %al
addl %eax, %r13d
subl %r13d, %r15d
jle 0x11f19
leaq 0xfc40(%rip), %rdx      # 0x21b24
leaq 0x30(%rsp), %r14
movl $0x40, %esi
movq %r14, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x7590
movq %r14, %rdi
callq 0x7180
movl $0x1, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7130
cmpq $-0x1, %rax
je 0x11f73
movq 0x8(%rsp), %rax
leal 0x1(%rax), %ecx
cmpl 0x4(%rsp), %eax
movl $0x1, %eax
cmovel %eax, %ecx
leaq 0xfbff(%rip), %rdx      # 0x21b33
leaq 0x30(%rsp), %r14
movl $0x40, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x7590
movq %r14, %rdi
callq 0x7180
movl $0x1, %edi
movq %r14, %rsi
movq %rax, %rdx
callq 0x7130
cmpq $-0x1, %rax
je 0x11f73
movq 0x10(%rsp), %rax
addl 0x20(%rax), %r13d
movl %r13d, 0x30(%rax)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq