// File: /workspace/github_cpp_makefile_star2_O1/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 0xfa6b(%rip), %r13      # 0x43f60
cmpl $0x0, 0x1d6b8(%r13)
je 0x34524
cmpl $0x0, 0x1d6bc(%r13)
je 0x34524
movl $0x0, 0x1d6b8(%r13)
callq 0xa940
movq $0x1, 0x1d6b8(%r13)
cmpq $0x0, 0x1680(%r13)
je 0x34537
leaq 0x994a(%rip), %rdi      # 0x3de7f
jmp 0x3454e
movq %rbx, %rdi
callq 0xa4a0
cmpq $0xff, %rax
jb 0x345ab
leaq 0x9948(%rip), %rdi      # 0x3de96
callq 0xa1f0
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movl $0x0, 0xd670(%r13)
leaq 0xc6d0(%r13), %rdi
leaq 0x9cfc(%rip), %rsi      # 0x3e272
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 0x7e75(%rip), %rsi      # 0x3c427
movq %rbx, %rdi
callq 0xace0
movq %rax, 0x1680(%r13)
testq %rax, %rax
je 0x346b5
movq %rbx, -0x30(%rbp)
leaq 0x1698(%r13), %rax
movq %rax, -0x40(%rbp)
movl $0x1698, %eax           # imm = 0x1698
addq 0xf97b(%rip), %rax      # 0x43f60
movq %rax, -0x38(%rbp)
movq 0x1680(%r13), %rdx
movq -0x40(%rbp), %rdi
movl $0xff, %esi
callq 0xb0f0
testq %rax, %rax
je 0x346d3
movq -0x38(%rbp), %rdi
callq 0xa4a0
movq %rax, %r14
cmpl $0xfe, %r14d
je 0x34698
movl %r14d, %r15d
movl %r14d, %ebx
sarl $0x1f, %ebx
andl %r14d, %ebx
leal -0x1(%rbx), %r12d
decq %r15
testl %r14d, %r14d
jle 0x34655
movl %r15d, %eax
movsbl 0x1698(%r13,%rax), %edi
callq 0xa0b0
decl %r14d
decq %r15
testl %eax, %eax
jne 0x3462f
leal 0x1(%r14), %ebx
jmp 0x34658
movl %r12d, %r14d
testl %ebx, %ebx
je 0x345e9
movslq %r14d, %rax
cmpb $0x25, 0x1698(%r13,%rax)
jne 0x346e7
movl %r14d, %ebx
movl %r14d, %r15d
sarl $0x1f, %r15d
andl %r14d, %r15d
incl %r14d
testl %ebx, %ebx
jle 0x346df
movsbl 0x1697(%r13,%rbx), %edi
decq %rbx
callq 0xa0b0
decl %r14d
testl %eax, %eax
jne 0x3467a
jmp 0x346e2
movq 0x1680(%r13), %rdi
callq 0xb0d0
cmpl $0xa, %eax
jne 0x34698
leaq 0x8601(%rip), %rdi      # 0x3ccb1
jmp 0x3454e
leaq 0x8a3d(%rip), %rdi      # 0x3d0f9
callq 0xa1f0
movq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xa850
jmp 0x3455d
leaq 0x8588(%rip), %rdi      # 0x3cc62
jmp 0x3454e
movl %r15d, %r14d
testl %r14d, %r14d
je 0x3475a
movq 0x1680(%r13), %rdi
xorl %ebx, %ebx
xorl %esi, %esi
xorl %edx, %edx
callq 0xabe0
xorl %eax, %eax
movb %bl, 0xc678(%r13)
movl %eax, 0xc6b4(%r13)
leaq 0x680(%r13), %rdi
movq -0x30(%rbp), %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 0x3459a
movl $0x1, %eax
movb $0x1, %bl
jmp 0x346fb
nop