// File: /workspace/github_cpp_makefile_star2_O1/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, 0x1c2d1(%rip)     # 0x2f984
xorl %edi, %edi
callq 0x7610
testl %eax, %eax
je 0x138b9
cmpq $0x0, 0x1c2e6(%rip)     # 0x2f9b0
je 0x13705
movq 0x1c2d5(%rip), %rsi     # 0x2f9a8
leaq 0xe520(%rip), %rdi      # 0x21bfa
xorl %eax, %eax
callq 0x7070
movq 0x1b898(%rip), %rax     # 0x2ef80
movq (%rax), %rdi
callq 0x73e0
movq $0x0, 0x1c2b5(%rip) # 0x2f9b0
movq 0x1c2a6(%rip), %rax     # 0x2f9a8
movb $0x0, (%rax)
leaq 0x8(%rsp), %r14
movl $0x5413, %esi           # imm = 0x5413
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x74e0
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 0x14afe
leaq 0xe569(%rip), %rdi      # 0x21cb0
callq 0x7410
testq %rax, %rax
je 0x1379c
movq %rax, %rbx
leaq 0xe55a(%rip), %rsi      # 0x21cb5
movq %rax, %rdi
callq 0x7380
testl %eax, %eax
je 0x1390d
xorl %ecx, %ecx
leaq 0x1acbc(%rip), %r14     # 0x2e430
cmpq $0x2, %rcx
je 0x1379c
movq %rcx, %r15
movq 0x8(%r14,%rcx,8), %rsi
movq %rbx, %rdi
callq 0x7380
leaq 0x1(%r15), %rcx
testl %eax, %eax
jne 0x13774
cmpq $0x2, %r15
jne 0x1390d
callq 0x11f82
xorl %ebx, %ebx
cmpl $-0x1, %eax
je 0x1395e
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, 0x1c1b6(%rip)     # 0x2f990
je 0x13802
movq 0x1c1a5(%rip), %rsi     # 0x2f988
leaq 0x8(%rsp), %rdi
callq 0x14cf8
movq $0x0, 0x1c198(%rip) # 0x2f990
movq 0x1c189(%rip), %rax     # 0x2f988
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x1203e
movl %eax, %ebx
cmpb $0x1, 0x1c1c6(%rip)     # 0x2f9e0
jne 0x1383b
leaq 0x1c1c1(%rip), %rdx     # 0x2f9e4
xorl %edi, %edi
movl $0x1, %esi
callq 0x7460
cmpl $-0x1, %eax
je 0x1383b
movb $0x0, 0x1c1a5(%rip)     # 0x2f9e0
movl $0xa, %edi
callq 0x74c0
cmpl $-0x1, %ebx
je 0x1395c
movslq 0x1c(%rsp), %rax
leaq 0x1(,%rax,4), %rbx
movq %rbx, %rdi
callq 0x7030
movq %rax, %r14
movq $0x0, 0x28(%rsp)
movq $-0x4, %r8
cmpl $0x0, 0x1074(%rsp,%r8)
leaq 0x4(%r8), %r8
jne 0x13876
sarq $0x2, %r8
leaq 0x28(%rsp), %rdx
leaq 0x1070(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x13dfb
movq %r14, %rdi
callq 0x7650
movq %rax, %rbx
movq %r14, %rdi
callq 0x7480
jmp 0x1395e
movl $0x1000, %edi           # imm = 0x1000
callq 0x7030
movq %rax, %r14
movq 0x1b6e3(%rip), %rax     # 0x2efb0
movq (%rax), %rdx
movq %r14, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x7560
testq %rax, %rax
je 0x1396a
movq %r14, %rdi
callq 0x7180
testl %eax, %eax
jle 0x13900
decl %eax
cmpb $0xa, (%r14,%rax)
jne 0x13900
movb $0x0, (%r14,%rax)
movq %r14, %rdi
callq 0x7650
movq %rax, %rbx
jmp 0x1396c
movq 0x38(%rsp), %rdi
movl 0x4c(%rsp), %esi
callq 0x10581
cmpl $-0x1, %eax
je 0x1395c
movq 0x1b659(%rip), %rax     # 0x2ef80
movq (%rax), %rdi
callq 0x73e0
cmpq $0x0, 0x1c059(%rip)     # 0x2f990
je 0x13984
movq 0x1c048(%rip), %r14     # 0x2f988
movq %r14, %rdi
callq 0x7650
movq %rax, %rbx
movq $0x0, 0x1c03a(%rip) # 0x2f990
movb $0x0, (%r14)
jmp 0x1395e
xorl %ebx, %ebx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
jne 0x1396f
jmp 0x13974
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x7480
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 0x1b618(%rip), %rax     # 0x2efb0
movq (%rax), %rdx
movq %r14, %rdi
movl $0x1000, %esi           # imm = 0x1000
callq 0x7560
testq %rax, %rax
je 0x139e2
movq %r14, %rdi
callq 0x7180
testq %rax, %rax
je 0x138a1
movzbl -0x1(%r14,%rax), %ecx
cmpl $0xd, %ecx
je 0x139d2
cmpl $0xa, %ecx
jne 0x138a1
movb $0x0, -0x1(%r14,%rax)
decq %rax
jne 0x139be
jmp 0x138a1
xorl %ebx, %ebx
jmp 0x138ac
jmp 0x139fe
movq %rax, %rbx
movq %r14, %rdi
callq 0x7480
jmp 0x13a01
jmp 0x139fe
jmp 0x139fe
jmp 0x139fe
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x13a10
callq 0x7480
movq %rbx, %rdi
callq 0x7620