// File: /workspace/github_cpp_makefile_star2_O3/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, 0x1b56c(%rip)     # 0x2e6a4
xorl %edi, %edi
callq 0x7620
testl %eax, %eax
je 0x13315
cmpq $0x0, 0x1b581(%rip)     # 0x2e6d0
je 0x1318a
movq 0x1b570(%rip), %rsi     # 0x2e6c8
leaq 0xdaa3(%rip), %rdi      # 0x20c02
xorl %eax, %eax
callq 0x7070
movq 0x1ae13(%rip), %rax     # 0x2df80
movq (%rax), %rdi
callq 0x73f0
movq $0x0, 0x1b550(%rip) # 0x2e6d0
movq 0x1b541(%rip), %rax     # 0x2e6c8
movb $0x0, (%rax)
leaq 0x8(%rsp), %r14
movl $0x5413, %esi           # imm = 0x5413
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x74f0
cmpl $-0x1, %eax
movzwl 0x2(%r14), %edx
movl $0x50, %eax
cmovel %eax, %edx
testl %edx, %edx
cmovel %eax, %edx
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x145c8
leaq 0xdae4(%rip), %rdi      # 0x20cb0
callq 0x7420
testq %rax, %rax
je 0x13201
movq %rax, %rbx
xorl %r14d, %r14d
leaq 0x1a24d(%rip), %r15     # 0x2d430
movq (%r14,%r15), %rsi
movq %rbx, %rdi
callq 0x7390
testl %eax, %eax
je 0x13369
addq $0x8, %r14
cmpq $0x18, %r14
jne 0x131e3
callq 0x11b2f
xorl %ebx, %ebx
cmpl $-0x1, %eax
je 0x133ba
leaq 0x1070(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movq $0xfff, 0x18(%rsp)      # imm = 0xFFF
movl %ebx, 0x20(%rsp)
movl %ebx, (%rax)
cmpq $0x0, 0x1b471(%rip)     # 0x2e6b0
je 0x13267
movq 0x1b460(%rip), %rsi     # 0x2e6a8
leaq 0x8(%rsp), %rdi
callq 0x147fc
movq $0x0, 0x1b453(%rip) # 0x2e6b0
movq 0x1b444(%rip), %rax     # 0x2e6a8
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x11bea
movl %eax, %ebx
cmpb $0x1, 0x1b481(%rip)     # 0x2e700
jne 0x132a0
leaq 0x1b47c(%rip), %rdx     # 0x2e704
xorl %edi, %edi
movl $0x1, %esi
callq 0x7470
cmpl $-0x1, %eax
je 0x132a0
movb $0x0, 0x1b460(%rip)     # 0x2e700
movl $0xa, %edi
callq 0x74d0
cmpl $-0x1, %ebx
je 0x133b8
movslq 0x1c(%rsp), %rax
leaq 0x1(,%rax,4), %rbx
movq %rbx, %rdi
callq 0x7030
movq %rax, %r14
movq $-0x4, %r8
cmpl $0x0, 0x1074(%rsp,%r8)
leaq 0x4(%r8), %r8
jne 0x132d2
sarq $0x2, %r8
leaq 0x28(%rsp), %rdx
leaq 0x1070(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x13860
movq %r14, %rdi
callq 0x7660
movq %rax, %rbx
movq %r14, %rdi
callq 0x7490
jmp 0x133ba
movl $0x1000, %edi           # imm = 0x1000
callq 0x7030
movq %rax, %r14
movq 0x1ac87(%rip), %rax     # 0x2dfb0
movq (%rax), %rdx
movq %r14, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x7570
testq %rax, %rax
je 0x133c6
movq %r14, %rdi
callq 0x7180
testl %eax, %eax
jle 0x1335c
decl %eax
cmpb $0xa, (%r14,%rax)
jne 0x1335c
movb $0x0, (%r14,%rax)
movq %r14, %rdi
callq 0x7660
movq %rax, %rbx
jmp 0x133c8
movq 0x38(%rsp), %rdi
movl 0x4c(%rsp), %esi
callq 0x101e3
cmpl $-0x1, %eax
je 0x133b8
movq 0x1abfd(%rip), %rax     # 0x2df80
movq (%rax), %rdi
callq 0x73f0
cmpq $0x0, 0x1b31d(%rip)     # 0x2e6b0
je 0x133e0
movq 0x1b30c(%rip), %r14     # 0x2e6a8
movq %r14, %rdi
callq 0x7660
movq %rax, %rbx
movq $0x0, 0x1b2fe(%rip) # 0x2e6b0
movb $0x0, (%r14)
jmp 0x133ba
xorl %ebx, %ebx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
jne 0x133cb
jmp 0x133d0
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x7490
movq %rbx, %rax
addq $0x5070, %rsp           # imm = 0x5070
popq %rbx
popq %r14
popq %r15
retq
movl $0x1000, %edi           # imm = 0x1000
callq 0x7030
movq %rax, %r14
movq 0x1abbc(%rip), %rax     # 0x2dfb0
movq (%rax), %rdx
movq %r14, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x7570
testq %rax, %rax
je 0x1343e
movq %r14, %rdi
callq 0x7180
testq %rax, %rax
je 0x132fd
movzbl -0x1(%r14,%rax), %ecx
cmpl $0xd, %ecx
je 0x1342e
cmpl $0xa, %ecx
jne 0x132fd
movb $0x0, -0x1(%r14,%rax)
decq %rax
jne 0x1341a
jmp 0x132fd
xorl %ebx, %ebx
jmp 0x13308
jmp 0x1345a
movq %rax, %rbx
movq %r14, %rdi
callq 0x7490
jmp 0x1345d
jmp 0x1345a
jmp 0x1345a
jmp 0x1345a
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x1346c
callq 0x7490
movq %rbx, %rdi
callq 0x7630