// File: /workspace/github_cpp_makefile_star2_O1/sundale[P]gcode/rs274ngc/interp_read.cc
// Function: Interp::read_text(char const*, _IO_FILE*, char*, char*, int*)
int Interp::read_text(
    const char *command,       //!< a string which may have input text, or null
    FILE * inport,     //!< a file pointer for an input file, or null
    char *raw_line,    //!< array to write raw input line into
    char *line,        //!< array for input line to be processed in
    int *length)       //!< a pointer to an integer to be set
{
  int index;
  int n;

  if (command == NULL) {
    if (fgets(raw_line, LINELEN, inport) == NULL) {
      if(_setup.skipping_to_sub)
      {
        ERS("EOF in file:%s seeking o-word: o<%s> from line: %d",
                 _setup.filename,
                 _setup.skipping_to_sub,
                 _setup.skipping_start);
      }
      if (_setup.percent_flag == ON)
      {
        ERS(NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN);
      }
      else
      {
        ERS(NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN_OR_PROGRAM_END);
      }
    }
    _setup.sequence_number++;   /* moved from version1, was outside if */
    if (strlen(raw_line) == (LINELEN - 1)) { // line is too long. need to finish reading the line to recover
      for (; fgetc(inport) != '\n';) {
      }                         // could also look for EOF
      ERS(NCE_COMMAND_TOO_LONG);
    }
    for (index = (strlen(raw_line) - 1);        // index set on last char
         (index >= 0) && (isspace(raw_line[index]));
         index--) { // remove space at end of raw_line, especially CR & LF
      raw_line[index] = 0;
    }
    strcpy(line, raw_line);
    CHP(close_and_downcase(line));
    if ((line[0] == '%') && (line[1] == 0) && (_setup.percent_flag == ON)) {
        FINISH();
        return INTERP_ENDFILE;
    }
  } else {
    CHKS((strlen(command) >= LINELEN), NCE_COMMAND_TOO_LONG);
    strcpy(raw_line, command);
    strcpy(line, command);
    CHP(close_and_downcase(line));
  }

  _setup.parameter_occurrence = 0;      /* initialize parameter buffer */

  // just in case free the strings
  if(_setup.named_parameter_occurrence != 0)
  {
      for (n = 0; n < _setup.named_parameter_occurrence; n++)
      {
          // free the string
          free(_setup.named_parameters[n]);
      }
  }
  _setup.named_parameter_occurrence = 0;      /* initialize parameter buffer */

  if ((line[0] == 0) || ((line[0] == '/') && (GET_BLOCK_DELETE() == ON)))
    *length = 0;
  else
    *length = strlen(line);

  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, -0x30(%rbp)
movq %r8, %r14
movq %rcx, %r12
movq %rdi, %r15
testq %rsi, %rsi
je 0x2dfb6
movq %rsi, %rbx
movq %rsi, %rdi
callq 0xa4a0
cmpq $0xff, %rax
jb 0x2e014
leaq 0xed19(%rip), %rdi      # 0x3ccb1
callq 0xa1f0
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x15faf(%rip), %rbx     # 0x43f60
jmp 0x2e07b
movq %rdx, %r13
movq %r12, %rdi
movl $0xff, %esi
callq 0xb0f0
movq 0x15f93(%rip), %rbx     # 0x43f60
testq %rax, %rax
je 0x2e04c
incl 0xc6b4(%rbx)
movq %r12, %rdi
callq 0xa4a0
cmpq $0xfe, %rax
jne 0x2e0bb
movq %r13, %rdi
callq 0xb0d0
cmpl $0xa, %eax
jne 0x2dfec
leaq 0xecb1(%rip), %rdi      # 0x3ccb1
callq 0xa1f0
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
jmp 0x2e07b
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa9d0
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa9d0
movq %r15, %rdi
movq %r14, %rsi
callq 0xa750
testl %eax, %eax
je 0x2e199
movl %eax, %r15d
movq 0x15f19(%rip), %rbx     # 0x43f60
jmp 0x2e0fc
movq 0xef78(%rbx), %rcx
testq %rcx, %rcx
je 0x2e15d
movl 0xef80(%rbx), %r8d
leaq 0x680(%rbx), %rdx
leaq 0xebbe(%rip), %rsi      # 0x3cc2f
movq %r15, %rdi
xorl %eax, %eax
callq 0xa850
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0xdba5(%rip), %rsi      # 0x3bc38
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r15d
jmp 0x2e208
decl %eax
js 0x2e0df
movl %eax, %r13d
incq %r13
movsbl -0x1(%r12,%r13), %edi
callq 0xa0b0
testl %eax, %eax
je 0x2e0df
movb $0x0, -0x1(%r12,%r13)
decq %r13
jg 0x2e0c5
movq %r14, %rdi
movq %r12, %rsi
callq 0xa9d0
movq %r15, %rdi
movq %r14, %rsi
callq 0xa750
testl %eax, %eax
je 0x2e176
movl %eax, %r15d
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x2e208
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0xdb11(%rip), %rsi      # 0x3bc38
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%rbx), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x2e208
cmpb $0x1, 0xc678(%rbx)
jne 0x2e21a
leaq 0xeaf1(%rip), %rdi      # 0x3cc62
jmp 0x2e000
cmpb $0x25, (%r14)
jne 0x2e199
cmpb $0x0, 0x1(%r14)
jne 0x2e199
cmpb $0x1, 0xc678(%rbx)
jne 0x2e199
callq 0xac50
movl $0x3, %r15d
jmp 0x2e208
movq 0x15dc0(%rip), %rbx     # 0x43f60
movl $0x0, 0xc0f0(%rbx)
cmpl $0x0, 0xc350(%rbx)
jle 0x2e1d2
xorl %r15d, %r15d
movq 0xc358(%rbx,%r15,8), %rdi
callq 0xacf0
incq %r15
movslq 0xc350(%rbx), %rax
cmpq %rax, %r15
jl 0x2e1b6
movl $0x0, 0xc350(%rbx)
movzbl (%r14), %ebx
testl %ebx, %ebx
je 0x2e1ff
cmpl $0x2f, %ebx
jne 0x2e1f4
xorl %ebx, %ebx
callq 0xa230
testb %al, %al
jne 0x2e1ff
movq %r14, %rdi
callq 0xa4a0
movq %rax, %rbx
movq -0x30(%rbp), %rax
movl %ebx, (%rax)
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xea61(%rip), %rdi      # 0x3cc82
jmp 0x2e000