// File: /workspace/github_cpp_makefile_star2_O2/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 0x27c26
movq %rsi, %rbx
movq %rsi, %rdi
callq 0xb4e0
cmpq $0xff, %rax
jb 0x27c8b
leaq 0xe09e(%rip), %rdi      # 0x35ca6
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x1533f(%rip), %rbx     # 0x3cf60
jmp 0x27d52
movq %rdx, %r13
movq %r12, %rdi
movl $0xff, %esi
callq 0xc230
movq 0x15323(%rip), %rbx     # 0x3cf60
testq %rax, %rax
je 0x27d23
incl 0xc6b4(%rbx)
movq %r12, %rdi
callq 0xb4e0
cmpq $0xfe, %rax
jne 0x27d90
movq %r13, %rdi
callq 0xc210
cmpl $0xa, %eax
jne 0x27c60
leaq 0xe032(%rip), %rdi      # 0x35ca6
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
jmp 0x27d52
movq %r12, %rdi
movq %rbx, %rsi
callq 0xba80
movq %r14, %rdi
movq %rbx, %rsi
callq 0xba80
movq %r15, %rdi
movq %r14, %rsi
callq 0xb7a0
testl %eax, %eax
jne 0x27dd2
movq 0x152a5(%rip), %rbx     # 0x3cf60
andl $0x0, 0xc0f0(%rbx)
movl 0xc350(%rbx), %eax
testl %eax, %eax
je 0x27cee
xorl %r15d, %r15d
cltq
cmpq %rax, %r15
jge 0x27cee
movq 0xc358(%rbx,%r15,8), %rdi
callq 0xbde0
incq %r15
movl 0xc350(%rbx), %eax
jmp 0x27ccf
andl $0x0, 0xc350(%rbx)
movzbl (%r14), %ebx
testl %ebx, %ebx
je 0x27d18
cmpl $0x2f, %ebx
jne 0x27d0d
xorl %ebx, %ebx
callq 0xb260
testb %al, %al
jne 0x27d18
movq %r14, %rdi
callq 0xb4e0
movq %rax, %rbx
movq -0x30(%rbp), %rax
movl %ebx, (%rax)
xorl %r15d, %r15d
jmp 0x27d7e
movq 0xef78(%rbx), %rcx
testq %rcx, %rcx
je 0x27e2f
movl 0xef80(%rbx), %r8d
leaq 0x680(%rbx), %rdx
leaq 0xdedc(%rip), %rsi      # 0x35c24
movq %r15, %rdi
xorl %eax, %eax
callq 0xb8e0
leaq 0xc6d0(%rbx), %rdi
leaq 0xced8(%rip), %rsi      # 0x34c38
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r15
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ebx
decq %rbx
testl %ebx, %ebx
js 0x27db8
movl %ebx, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movsbl (%r12,%r13), %edi
callq 0xb0c0
testl %eax, %eax
je 0x27db8
movb $0x0, (%r12,%r13)
jmp 0x27d92
movq %r14, %rdi
movq %r12, %rsi
callq 0xba80
movq %r15, %rdi
movq %r14, %rsi
callq 0xb7a0
testl %eax, %eax
je 0x27e44
movl %eax, %r15d
movq 0x15184(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x27d7e
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0xce39(%rip), %rsi      # 0x34c38
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%rbx), %rax
imulq $0x50, %rax, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x27d7e
cmpb $0x1, 0xc678(%rbx)
jne 0x27e79
leaq 0xde18(%rip), %rdi      # 0x35c57
jmp 0x27c74
cmpb $0x25, (%r14)
movq 0x15111(%rip), %rax     # 0x3cf60
jne 0x27cb4
cmpb $0x0, 0x1(%r14)
jne 0x27cb4
cmpb $0x1, 0xc678(%rax)
jne 0x27cb4
callq 0xbd40
pushq $0x3
jmp 0x27d7c
leaq 0xddf7(%rip), %rdi      # 0x35c77
jmp 0x27c74
nop