// File: /workspace/github_cpp_makefile_star2_O2/andrakis[P]alisp/contrib/linenoise-ng/src/linenoise.cpp
// Function: linenoise
char* linenoise(const char* prompt) {
#ifndef _WIN32
  gotResize = false;
#endif
  if (isatty(STDIN_FILENO)) {  // input is from a terminal
    char32_t buf32[LINENOISE_MAX_LINE];
    char charWidths[LINENOISE_MAX_LINE];
    if (!preloadErrorMessage.empty()) {
      printf("%s", preloadErrorMessage.c_str());
      fflush(stdout);
      preloadErrorMessage.clear();
    }
    PromptInfo pi(prompt, getScreenColumns());
    if (isUnsupportedTerm()) {
      if (!pi.write()) return 0;
      fflush(stdout);
      if (preloadedBufferContents.empty()) {
        unique_ptr<char[]> buf8(new char[LINENOISE_MAX_LINE]);
        if (fgets(buf8.get(), LINENOISE_MAX_LINE, stdin) == NULL) {
          return NULL;
        }
        size_t len = strlen(buf8.get());
        while (len && (buf8[len - 1] == '\n' || buf8[len - 1] == '\r')) {
          --len;
          buf8[len] = '\0';
        }
        return strdup(buf8.get());  // caller must free buffer
      } else {
        char* buf8 = strdup(preloadedBufferContents.c_str());
        preloadedBufferContents.clear();
        return buf8;  // caller must free buffer
      }
    } else {
      if (enableRawMode() == -1) {
        return NULL;
      }
      InputBuffer ib(buf32, charWidths, LINENOISE_MAX_LINE);
      if (!preloadedBufferContents.empty()) {
        ib.preloadBuffer(preloadedBufferContents.c_str());
        preloadedBufferContents.clear();
      }
      int count = ib.getInputLine(pi);
      disableRawMode();
      printf("\n");
      if (count == -1) {
        return NULL;
      }
      size_t bufferSize = sizeof(char32_t) * ib.length() + 1;
      unique_ptr<char[]> buf8(new char[bufferSize]);
      copyString32to8(buf8.get(), bufferSize, buf32);
      return strdup(buf8.get());  // caller must free buffer
    }
  } else {  // input not from a terminal, we should work with piped input, i.e.
            // redirected stdin
    unique_ptr<char[]> buf8(new char[LINENOISE_MAX_LINE]);
    if (fgets(buf8.get(), LINENOISE_MAX_LINE, stdin) == NULL) {
      return NULL;
    }

    // if fgets() gave us the newline, remove it
    int count = static_cast<int>(strlen(buf8.get()));
    if (count > 0 && buf8[count - 1] == '\n') {
      --count;
      buf8[count] = '\0';
    }
    return strdup(buf8.get());  // caller must free buffer
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x5070, %rsp           # imm = 0x5070
movq %rdi, %rbx
movb $0x0, 0x1abc3(%rip)     # 0x2b984
xorl %edi, %edi
callq 0x75f0
testl %eax, %eax
je 0x10f7f
cmpq $0x0, 0x1abd8(%rip)     # 0x2b9b0
je 0x10e10
movq 0x1abc7(%rip), %rsi     # 0x2b9a8
leaq 0xbdda(%rip), %rdi      # 0x1cbc2
xorl %eax, %eax
callq 0x7060
movq 0x1a19a(%rip), %rax     # 0x2af90
movq (%rax), %rdi
callq 0x73a0
andq $0x0, 0x1abaa(%rip)     # 0x2b9b0
movq 0x1ab9b(%rip), %rax     # 0x2b9a8
movb $0x0, (%rax)
callq 0x10c1c
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
movl %eax, %edx
callq 0x11fb4
leaq 0xbe4d(%rip), %rdi      # 0x1cc78
callq 0x73d0
testq %rax, %rax
je 0x10eae
movq %rax, %rbx
xorl %r14d, %r14d
leaq 0x195fe(%rip), %r15     # 0x2a440
cmpq $0x18, %r14
je 0x10eae
movq (%r14,%r15), %rsi
movq %rbx, %rdi
callq 0x7360
addq $0x8, %r14
testl %eax, %eax
jne 0x10e42
leaq 0x30(%rsp), %rdi
callq 0x11a0c
testb %al, %al
je 0x10fd5
movq 0x1a11b(%rip), %rax     # 0x2af90
movq (%rax), %rdi
callq 0x73a0
cmpq $0x0, 0x1ab0b(%rip)     # 0x2b990
je 0x11002
movq 0x1aaf6(%rip), %r14     # 0x2b988
movq %r14, %rdi
callq 0x7630
movq %rax, %rbx
andq $0x0, 0x1aaeb(%rip)     # 0x2b990
movb $0x0, (%r14)
jmp 0x10fd7
callq 0xf955
cmpl $-0x1, %eax
je 0x10fd5
leaq 0x1070(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x70(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq $0xfff, 0x20(%rsp)      # imm = 0xFFF
andl $0x0, 0x28(%rsp)
andl $0x0, (%rax)
cmpq $0x0, 0x1aaa4(%rip)     # 0x2b990
je 0x10f11
movq 0x1aa93(%rip), %rsi     # 0x2b988
leaq 0x10(%rsp), %rdi
callq 0x121bc
andq $0x0, 0x1aa89(%rip)     # 0x2b990
movq 0x1aa7a(%rip), %rax     # 0x2b988
movb $0x0, (%rax)
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xfa0c
movl %eax, %ebx
callq 0xf928
pushq $0xa
popq %rdi
callq 0x74a0
cmpl $-0x1, %ebx
je 0x10fd5
movslq 0x24(%rsp), %rax
leaq 0x1(,%rax,4), %r14
movq %r14, %rdi
callq 0x7030
movq %rax, %rbx
movq %rax, 0x8(%rsp)
leaq 0x1070(%rsp), %rdx
movq %rax, %rdi
movq %r14, %rsi
callq 0xf70e
movq %rbx, %rdi
callq 0x7630
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11a32
jmp 0x10fd7
movl $0x1000, %edi           # imm = 0x1000
callq 0x7030
movq %rax, %rbx
movq %rax, 0x1070(%rsp)
movq 0x1a01d(%rip), %rax     # 0x2afb8
movq (%rax), %rdx
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x7530
testq %rax, %rax
je 0x10fe3
movq %rbx, %rdi
callq 0x7170
testl %eax, %eax
jle 0x10fc8
decl %eax
cmpb $0xa, (%rbx,%rax)
jne 0x10fc8
movb $0x0, (%rbx,%rax)
movq %rbx, %rdi
callq 0x7630
movq %rax, %rbx
jmp 0x10fe5
xorl %ebx, %ebx
leaq 0x30(%rsp), %rdi
callq 0x118be
jmp 0x10ff2
xorl %ebx, %ebx
leaq 0x1070(%rsp), %rdi
callq 0x11a32
movq %rbx, %rax
addq $0x5070, %rsp           # imm = 0x5070
popq %rbx
popq %r14
popq %r15
retq
movl $0x1000, %edi           # imm = 0x1000
callq 0x7030
movq %rax, %rbx
movq %rax, 0x10(%rsp)
movq 0x19f9d(%rip), %rax     # 0x2afb8
movq (%rax), %rdx
movq %rbx, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x7530
testq %rax, %rax
je 0x11067
movq %rbx, %rdi
callq 0x7170
movq %rax, %rcx
subq $0x1, %rcx
jb 0x1105a
movzbl -0x1(%rbx,%rax), %edx
cmpl $0xd, %edx
je 0x11050
cmpl $0xa, %edx
jne 0x1105a
movb $0x0, -0x1(%rbx,%rax)
movq %rcx, %rax
jmp 0x1103b
movq %rbx, %rdi
callq 0x7630
movq %rax, %rbx
jmp 0x11069
xorl %ebx, %ebx
leaq 0x10(%rsp), %rdi
jmp 0x10f78
jmp 0x1108a
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x11a32
jmp 0x1108d
jmp 0x1108a
jmp 0x1108a
jmp 0x1108a
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x118be
movq %rbx, %rdi
callq 0x7600