// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq 0x10481(%rip), %r13     # 0x40f60
cmpl $0x0, 0x1d6b8(%r13)
je 0x30b0e
cmpl $0x0, 0x1d6bc(%r13)
je 0x30b0e
movl $0x0, 0x1d6b8(%r13)
callq 0xa940
movq $0x1, 0x1d6b8(%r13)
cmpq $0x0, 0x1680(%r13)
je 0x30b21
leaq 0xa310(%rip), %rdi      # 0x3ae2f
jmp 0x30b38
movq %rbx, %rdi
callq 0xa4a0
cmpq $0xff, %rax
jb 0x30b8a
leaq 0xa30e(%rip), %rdi      # 0x3ae46
callq 0xa1f0
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
leaq 0xc6d0(%r13), %rdi
leaq 0xa6cd(%rip), %rsi      # 0x3b222
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%r13)
movl $0x1, 0xd670(%r13)
movl $0x5, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x888e(%rip), %rsi      # 0x3941f
movq %rbx, %rdi
callq 0xace0
movq %rax, 0x1680(%r13)
testq %rax, %rax
je 0x30c7d
leaq 0x1698(%r13), %r14
movl $0x1698, %r15d          # imm = 0x1698
addq 0x103a3(%rip), %r15     # 0x40f60
movq %r14, -0x38(%rbp)
movq %r15, -0x30(%rbp)
movq 0x1680(%r13), %rdx
movq %r14, %rdi
movl $0xff, %esi
callq 0xb0f0
testq %rax, %rax
je 0x30d1d
movq %r15, %rdi
callq 0xa4a0
movq %rax, %r12
cmpl $0xfe, %r12d
je 0x30c60
movl %r12d, %r15d
decq %r15
movl %r12d, %r14d
testl %r14d, %r14d
jle 0x30c21
movl %r15d, %eax
movsbl 0x1698(%r13,%rax), %edi
callq 0xa0b0
decl %r14d
decq %r15
testl %eax, %eax
jne 0x30bff
jmp 0x30c33
testl %r12d, %r12d
movq -0x38(%rbp), %r14
movq -0x30(%rbp), %r15
jns 0x30bc5
leal -0x1(%r12), %r14d
movslq %r14d, %rax
cmpb $0x25, 0x1698(%r13,%rax)
jne 0x30ca0
movl %r14d, %r14d
testl %r14d, %r14d
jle 0x30c9b
movsbl 0x1697(%r13,%r14), %edi
decq %r14
callq 0xa0b0
testl %eax, %eax
jne 0x30c44
jmp 0x30ca0
movq 0x1680(%r13), %rdi
callq 0xb0d0
cmpl $0xa, %eax
jne 0x30c60
leaq 0x902e(%rip), %rdi      # 0x39ca6
jmp 0x30b38
leaq 0x946a(%rip), %rdi      # 0x3a0ee
callq 0xa1f0
movq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa850
jmp 0x30b47
testq %r14, %r14
je 0x30d13
movq 0x1680(%r13), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
xorl %edx, %edx
callq 0xabe0
xorl %eax, %eax
movb %r14b, 0xc678(%r13)
movl %eax, 0xc6b4(%r13)
leaq 0x680(%r13), %rdi
movq %rbx, %rsi
callq 0xa9d0
xorl %ebx, %ebx
movb %bl, 0x1698(%r13)
movb %bl, 0x4f8(%r13)
movl %ebx, 0x1694(%r13)
movl %ebx, 0xef90(%r13)
movl %ebx, 0xef50(%r13)
movq $0x0, 0xef70(%r13)
movl %ebx, 0xfb28(%r13)
callq 0xa090
jmp 0x30b79
movl $0x1, %eax
movb $0x1, %r14b
jmp 0x30cb5
leaq 0x8f33(%rip), %rdi      # 0x39c57
jmp 0x30b38
nop