// File: 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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x11061(%rip), %rax     # 0x86f60
cmpl $0x0, 0x1d6b8(%rax)
je 0x75f54
movq 0x11051(%rip), %rax     # 0x86f60
cmpl $0x0, 0x1d6bc(%rax)
je 0x75f54
movq -0x30(%rbp), %rdi
movq 0x1103d(%rip), %rax     # 0x86f60
movl $0x0, 0x1d6b8(%rax)
callq 0x10f90
movq 0x11027(%rip), %rax     # 0x86f60
movl $0x1, 0x1d6b8(%rax)
movq 0x11016(%rip), %rax     # 0x86f60
movl $0x0, 0x1d6bc(%rax)
jmp 0x75f56
movq 0x11003(%rip), %rax     # 0x86f60
cmpq $0x0, 0x1680(%rax)
je 0x76040
jmp 0x75f6d
leaq 0x9de9(%rip), %rdi      # 0x7fd5d
callq 0x10380
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x10fd2(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x10fc1(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x10fb3(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x9db2(%rip), %rsi      # 0x7fd74
movl $0x50, %edx
callq 0x10840
movq 0x10f8d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10f7f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x10f67(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x10f57(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x10f4a(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10f3c(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x765ce
jmp 0x76042
jmp 0x76044
movq -0x18(%rbp), %rdi
callq 0x10740
cmpq $0xfe, %rax
jbe 0x7612e
jmp 0x7605b
leaq 0x9d31(%rip), %rdi      # 0x7fd93
callq 0x10380
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x10ee4(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x10ed3(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x10ec5(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x9cc4(%rip), %rsi      # 0x7fd74
movl $0x50, %edx
callq 0x10840
movq 0x10e9f(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10e91(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x10e79(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x10e69(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x10e5c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10e4e(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x765ce
jmp 0x76130
movq -0x18(%rbp), %rdi
leaq 0x7bc4(%rip), %rsi      # 0x7dcff
callq 0x11490
movq %rax, %rcx
movq 0x10e16(%rip), %rax     # 0x86f60
movq %rcx, 0x1680(%rax)
movq 0x10e08(%rip), %rax     # 0x86f60
cmpq $0x0, 0x1680(%rax)
jne 0x7623f
jmp 0x76168
leaq 0x8dbf(%rip), %rdi      # 0x7ef2e
callq 0x10380
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movb $0x0, %al
callq 0x10df0
movq 0x10dd3(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x10dc2(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x10db4(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x9bb3(%rip), %rsi      # 0x7fd74
movl $0x50, %edx
callq 0x10840
movq 0x10d8e(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10d80(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x10d68(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x10d58(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x10d4b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10d3d(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x765ce
jmp 0x76241
movq 0x10d18(%rip), %rax     # 0x86f60
addq $0x1698, %rax           # imm = 0x1698
movq %rax, -0x20(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
cmpl $-0x1, -0x24(%rbp)
jne 0x764b5
jmp 0x76265
movq -0x20(%rbp), %rdi
movq 0x10cf0(%rip), %rax     # 0x86f60
movq 0x1680(%rax), %rdx
movl $0xff, %esi
callq 0x11b60
cmpq $0x0, %rax
jne 0x76360
jmp 0x7628d
leaq 0x869b(%rip), %rdi      # 0x7e92f
callq 0x10380
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x10cb2(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x10ca1(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x10c93(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x9a92(%rip), %rsi      # 0x7fd74
movl $0x50, %edx
callq 0x10840
movq 0x10c6d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10c5f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x10c47(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x10c37(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x10c2a(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10c1c(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x765ce
jmp 0x76362
movq -0x20(%rbp), %rdi
callq 0x10740
movl %eax, -0x28(%rbp)
cmpl $0xfe, -0x28(%rbp)
jne 0x7646c
jmp 0x7637d
movq 0x10bdc(%rip), %rax     # 0x86f60
movq 0x1680(%rax), %rdi
callq 0x11b40
cmpl $0xa, %eax
je 0x76397
jmp 0x7637d
jmp 0x76399
leaq 0x85de(%rip), %rdi      # 0x7e97e
callq 0x10380
movq -0x30(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x10ba6(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x10b95(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x10b87(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x9986(%rip), %rsi      # 0x7fd74
movl $0x50, %edx
callq 0x10840
movq 0x10b61(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10b53(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x10b3b(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x10b2b(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x10b1e(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x10b10(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x765ce
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x31(%rbp)
jl 0x7649a
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x10120
cmpl $0x0, %eax
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x764a3
jmp 0x764b0
jmp 0x764a5
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x76475
jmp 0x76259
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
jne 0x7656f
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x32(%rbp)
jl 0x764f8
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x10120
cmpl $0x0, %eax
setne %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
testb $0x1, %al
jne 0x76501
jmp 0x7650e
jmp 0x76503
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x764d3
cmpl $-0x1, -0x24(%rbp)
jne 0x76535
movq 0x10a45(%rip), %rax     # 0x86f60
movb $0x1, 0xc678(%rax)
movq 0x10a37(%rip), %rax     # 0x86f60
movl $0x1, 0xc6b4(%rax)
jmp 0x7656d
movq 0x10a24(%rip), %rax     # 0x86f60
movq 0x1680(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x11350
movq 0x10a0b(%rip), %rax     # 0x86f60
movb $0x0, 0xc678(%rax)
movq 0x109fd(%rip), %rax     # 0x86f60
movl $0x0, 0xc6b4(%rax)
jmp 0x765a7
movq 0x109ea(%rip), %rax     # 0x86f60
movq 0x1680(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x11350
movq 0x109d1(%rip), %rax     # 0x86f60
movb $0x0, 0xc678(%rax)
movq 0x109c3(%rip), %rax     # 0x86f60
movl $0x0, 0xc6b4(%rax)
movq -0x18(%rbp), %rsi
movq 0x109ae(%rip), %rdi     # 0x86f60
addq $0x680, %rdi            # imm = 0x680
callq 0x11080
movq -0x30(%rbp), %rdi
callq 0x10a10
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)