// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/rs274ngc_pre.cc
// Function: Interp::open(char const*)
int Interp::open(const char *filename) //!< string: the name of the input NC-program file
{
  char *line;
  int index;
  int length;

  if(_setup.use_lazy_close && _setup.lazy_closing)
    {
      _setup.use_lazy_close = 0; // so that close will work
      close();
      _setup.use_lazy_close = 1;
      _setup.lazy_closing = 0;
    }

  CHKS((_setup.file_pointer != NULL), NCE_A_FILE_IS_ALREADY_OPEN);
  CHKS((strlen(filename) > (LINELEN - 1)), NCE_FILE_NAME_TOO_LONG);
  _setup.file_pointer = fopen(filename, "r");
  CHKS((_setup.file_pointer == NULL), NCE_UNABLE_TO_OPEN_FILE, filename);
  line = _setup.linetext;
  for (index = -1; index == -1;) {      /* skip blank lines */
    CHKS((fgets(line, LINELEN, _setup.file_pointer) ==
         NULL), NCE_FILE_ENDED_WITH_NO_PERCENT_SIGN);
    length = strlen(line);
    if (length == (LINELEN - 1)) {   // line is too long. need to finish reading the line to recover
      for (; fgetc(_setup.file_pointer) != '\n';);      // could look for EOF
      ERS(NCE_COMMAND_TOO_LONG);
    }
    for (index = (length - 1);  // index set on last char
         (index >= 0) && (isspace(line[index])); index--);
  }
  if (line[index] == '%') {
    for (index--; (index >= 0) && (isspace(line[index])); index--);
    if (index == -1) {
      _setup.percent_flag = ON;
      _setup.sequence_number = 1;       // We have already read the first line
      // and we are not going back to it.
    } else {
      fseek(_setup.file_pointer, 0, SEEK_SET);
      _setup.percent_flag = OFF;
      _setup.sequence_number = 0;       // Going back to line 0
    }
  } else {
    fseek(_setup.file_pointer, 0, SEEK_SET);
    _setup.percent_flag = OFF;
    _setup.sequence_number = 0; // Going back to line 0
  }
  strcpy(_setup.filename, filename);
  reset();
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq 0xf555(%rip), %rbx      # 0x3cf60
cmpl $0x0, 0x1d6b8(%rbx)
je 0x2da34
cmpl $0x0, 0x1d6bc(%rbx)
je 0x2da34
andl $0x0, 0x1d6b8(%rbx)
callq 0xb9e0
movq $0x1, 0x1d6b8(%rbx)
cmpq $0x0, 0x1680(%rbx)
je 0x2da47
leaq 0x93ea(%rip), %rdi      # 0x36e2f
jmp 0x2da5e
movq %r14, %rdi
callq 0xb4e0
cmpq $0xff, %rax
jb 0x2daa7
leaq 0x93e8(%rip), %rdi      # 0x36e46
callq 0xb220
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
leaq 0xc6d0(%rbx), %rdi
leaq 0x97a7(%rip), %rsi      # 0x37222
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7971(%rip), %rsi      # 0x3541f
movq %r14, %rdi
callq 0xbdd0
movq %rax, 0x1680(%rbx)
testq %rax, %rax
je 0x2db78
movq %r14, -0x30(%rbp)
pushq $-0x1
popq %r13
leaq 0x1698(%rbx), %rax
movq %rax, -0x38(%rbp)
movl $0x1698, %r12d          # imm = 0x1698
addq 0xf47a(%rip), %r12      # 0x3cf60
cmpl $-0x1, %r13d
jne 0x2db96
movq 0x1680(%rbx), %rdx
movq -0x38(%rbp), %rdi
movl $0xff, %esi
callq 0xc230
testq %rax, %rax
je 0x2dbc2
movq %r12, %rdi
callq 0xb4e0
movq %rax, %r13
cmpl $0xfe, %r13d
je 0x2db5b
movl %r13d, %r14d
movl %r13d, %r15d
sarl $0x1f, %r15d
andl %r13d, %r15d
decl %r15d
decq %r14
testl %r13d, %r13d
jle 0x2db56
movl %r14d, %eax
movsbl 0x1698(%rbx,%rax), %edi
callq 0xb0c0
decl %r13d
decq %r14
testl %eax, %eax
jne 0x2db35
jmp 0x2dae6
movl %r15d, %r13d
jmp 0x2dae6
movq 0x1680(%rbx), %rdi
callq 0xc210
cmpl $0xa, %eax
jne 0x2db5b
leaq 0x8133(%rip), %rdi      # 0x35ca6
jmp 0x2da5e
leaq 0x856f(%rip), %rdi      # 0x360ee
callq 0xb220
movq %rax, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb8e0
jmp 0x2da6d
movslq %r13d, %rax
cmpb $0x25, 0x1698(%rbx,%rax)
jne 0x2dbd3
movl %r13d, %r14d
testl %r14d, %r14d
jle 0x2dbce
movsbl 0x1697(%rbx,%r14), %edi
decq %r14
callq 0xb0c0
testl %eax, %eax
jne 0x2dba6
jmp 0x2dbd3
leaq 0x808e(%rip), %rdi      # 0x35c57
jmp 0x2da5e
testq %r14, %r14
je 0x2dc14
movq 0x1680(%rbx), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0xbcd0
xorl %eax, %eax
movb %r14b, 0xc678(%rbx)
movl %eax, 0xc6b4(%rbx)
addq $0x680, %rbx            # imm = 0x680
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
callq 0xba80
callq 0xb6a0
xorl %eax, %eax
jmp 0x2da98
pushq $0x1
popq %rax
movb $0x1, %r14b
jmp 0x2dbe8