// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x80, %rsp
testq %rdi, %rdi
je 0x13678
movq %rdi, %r14
callq 0x7180
incl %eax
movslq %eax, %r15
movq %r15, %rdi
callq 0x7030
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x71c0
movb (%rbx), %dl
testb %dl, %dl
je 0x135c5
movq %rbx, %rax
incq %rax
xorl %ecx, %ecx
xorl %ebp, %ebp
movq %rbx, %r14
cmpb $0xd, %dl
je 0x135ba
leal -0x9(%rdx), %esi
cmpb $0x2, %sil
jae 0x1358a
movb $0x1, %cl
jmp 0x135ba
cmpb $0x20, %dl
jb 0x135b0
movzbl %dl, %esi
addl $-0x7f, %esi
cmpl $0x20, %esi
jbe 0x135b0
testb $0x1, %cl
je 0x135a8
movb $0x20, (%r14)
incq %r14
xorl %ecx, %ecx
movb %dl, (%r14)
incq %r14
jmp 0x135ba
movb $0x20, (%r14)
incq %r14
movb $0x1, %bpl
movb (%rax), %dl
incq %rax
testb %dl, %dl
jne 0x13578
jmp 0x135ca
xorl %ebp, %ebp
movq %rbx, %r14
movb $0x0, (%r14)
subl %ebx, %r14d
cmpl $0x1000, %r14d          # imm = 0x1000
jl 0x135e1
movb $0x0, 0xfff(%rbx)
movq 0x1c3a8(%rip), %r15     # 0x2f990
leaq 0x1c399(%rip), %r12     # 0x2f988
movq %rbx, %rdi
callq 0x7180
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x7540
testb $0x1, %bpl
je 0x13623
leaq 0x1c391(%rip), %rdi     # 0x2f9a8
leaq 0xe563(%rip), %rsi      # 0x21b81
callq 0x7670
cmpl $0x1000, %r14d          # imm = 0x1000
jl 0x13670
leaq 0x1c375(%rip), %rdi     # 0x2f9a8
leaq 0xe584(%rip), %rsi      # 0x21bbe
callq 0x7670
leaq 0xe5a9(%rip), %rdx      # 0x21bef
movq %rsp, %r15
movl $0x80, %esi
movq %r15, %rdi
movl %r14d, %ecx
movl $0xfff, %r8d            # imm = 0xFFF
xorl %eax, %eax
callq 0x7590
leaq 0x1c340(%rip), %rdi     # 0x2f9a8
movq %r15, %rsi
callq 0x7670
movq %rbx, %rdi
callq 0x7480
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1368a
movq %rax, %r14
movq %rbx, %rdi
callq 0x7480
movq %r14, %rdi
callq 0x7620