// File: /workspace/github_cpp_makefile_star2_O2/andrakis[P]alisp/contrib/linenoise-ng/src/linenoise.cpp
// Function: linenoisePreloadBuffer
void linenoisePreloadBuffer(const char* preloadText) {
  if (!preloadText) {
    return;
  }
  int bufferSize = static_cast<int>(strlen(preloadText) + 1);
  unique_ptr<char[]> tempBuffer(new char[bufferSize]);
  strncpy(&tempBuffer[0], preloadText, bufferSize);

  // remove characters that won't display correctly
  char* pIn = &tempBuffer[0];
  char* pOut = pIn;
  bool controlsStripped = false;
  bool whitespaceSeen = false;
  while (*pIn) {
    unsigned char c =
        *pIn++;       // we need unsigned so chars 0x80 and above are allowed
    if ('\r' == c) {  // silently skip CR
      continue;
    }
    if ('\n' == c || '\t' == c) {  // note newline or tab
      whitespaceSeen = true;
      continue;
    }
    if (isControlChar(
            c)) {  // remove other control characters, flag for message
      controlsStripped = true;
      *pOut++ = ' ';
      continue;
    }
    if (whitespaceSeen) {  // convert whitespace to a single space
      *pOut++ = ' ';
      whitespaceSeen = false;
    }
    *pOut++ = c;
  }
  *pOut = 0;
  int processedLength = static_cast<int>(pOut - tempBuffer.get());
  bool lineTruncated = false;
  if (processedLength > (LINENOISE_MAX_LINE - 1)) {
    lineTruncated = true;
    tempBuffer[LINENOISE_MAX_LINE - 1] = 0;
  }
  preloadedBufferContents = tempBuffer.get();
  if (controlsStripped) {
    preloadErrorMessage +=
        " [Edited line: control characters were converted to spaces]\n";
  }
  if (lineTruncated) {
    preloadErrorMessage += " [Edited line: the line length was reduced from ";
    char buf[128];
    snprintf(buf, sizeof(buf), "%d to %d]\n", processedLength,
             (LINENOISE_MAX_LINE - 1));
    preloadErrorMessage += buf;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
testq %rdi, %rdi
je 0x10d86
movq %rdi, %rbx
callq 0x7170
incl %eax
movslq %eax, %r15
movq %r15, %rdi
callq 0x7030
movq %rax, %r14
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x71c0
xorl %ebp, %ebp
movq %r14, %rbx
xorl %eax, %eax
movl %eax, %edx
movl %edx, %eax
movzbl (%r14), %ecx
testl %ecx, %ecx
je 0x10cf1
incq %r14
cmpb $0xd, %cl
je 0x10ca9
leal -0x9(%rcx), %esi
movb $0x1, %dl
cmpb $0x2, %sil
jb 0x10ca7
cmpb $0x20, %cl
jb 0x10ce6
movl %ecx, %edx
addl $-0x7f, %edx
cmpl $0x20, %edx
jbe 0x10ce6
testb $0x1, %al
je 0x10cdd
movb $0x20, (%rbx)
incq %rbx
movb %cl, (%rbx)
incq %rbx
xorl %edx, %edx
jmp 0x10ca7
movb $0x20, (%rbx)
incq %rbx
movb $0x1, %bpl
jmp 0x10ca5
movb $0x0, (%rbx)
movq 0x8(%rsp), %rsi
subl %esi, %ebx
cmpl $0x1000, %ebx           # imm = 0x1000
jl 0x10d0a
movb $0x0, 0xfff(%rsi)
leaq 0x1ac77(%rip), %rdi     # 0x2b988
callq 0x7660
testb $0x1, %bpl
je 0x10d2f
leaq 0x1ac85(%rip), %rdi     # 0x2b9a8
leaq 0xbe1f(%rip), %rsi      # 0x1cb49
callq 0x7650
cmpl $0x1000, %ebx           # imm = 0x1000
jl 0x10d7c
leaq 0x1ac6a(%rip), %rdi     # 0x2b9a8
leaq 0xbe41(%rip), %rsi      # 0x1cb86
callq 0x7650
leaq 0xbe66(%rip), %rdx      # 0x1cbb7
leaq 0x10(%rsp), %r14
movl $0x80, %esi
movq %r14, %rdi
movl %ebx, %ecx
movl $0xfff, %r8d            # imm = 0xFFF
xorl %eax, %eax
callq 0x7570
leaq 0x1ac34(%rip), %rdi     # 0x2b9a8
movq %r14, %rsi
callq 0x7650
leaq 0x8(%rsp), %rdi
callq 0x11a32
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10d96
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11a32
movq %rbx, %rdi
callq 0x7600