// File: sundale[P]gcode/rs274ngc/rs274ngc_pre.cc
// Function: Interp::restore_parameters(char const*)
int Interp::restore_parameters(const char *filename)   //!< name of parameter file to read  
{
  FILE *infile;
  char line[256];
  int variable;
  double value;
  int required;                 // number of next required parameter
  int index;                    // index into _required_parameters
  double *pars;                 // short name for _setup.parameters
  int k;

  // it's OK if the parameter file doesn't exist yet
  // it'll be created in due course with some default values
  if(access(filename, F_OK) == -1)
      return INTERP_OK;
  // open original for reading
  infile = fopen(filename, "r");
  sprintf(line,"Unable to open parameter file: '%s'", filename);
  CHKS((infile == NULL), line);

  pars = _setup.parameters;
  k = 0;
  index = 0;
  required = _required_parameters[index++];
  while (feof(infile) == 0) {
    if (fgets(line, 256, infile) == NULL) {
      break;
    }
    // try for a variable-value match in the file
    if (sscanf(line, "%d %lf", &variable, &value) == 2) {
      CHKS(((variable <= 0)
           || (variable >= RS274NGC_MAX_PARAMETERS)),
          NCE_PARAMETER_NUMBER_OUT_OF_RANGE);
      for (; k < RS274NGC_MAX_PARAMETERS; k++) {
        if (k > variable)
          ERS(NCE_PARAMETER_FILE_OUT_OF_ORDER);
        else if (k == variable) {
          pars[k] = value;
          if (k == required)
            required = _required_parameters[index++];
          k++;
          break;
        } else                  // if (k < variable)
        {
          if (k == required)
            required = _required_parameters[index++];
          pars[k] = 0;
        }
      }
    }
  }
  fclose(infile);
  for (; k < RS274NGC_MAX_PARAMETERS; k++) {
    pars[k] = 0;
  }
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x11dc0
cmpl $-0x1, %eax
jne 0x74f4a
movl $0x0, -0x4(%rbp)
jmp 0x75405
movq -0x18(%rbp), %rdi
leaq 0x8daa(%rip), %rsi      # 0x7dcff
callq 0x11490
movq %rax, -0x20(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0xaeff(%rip), %rsi      # 0x7fe6f
movb $0x0, %al
callq 0x10280
cmpq $0x0, -0x20(%rbp)
jne 0x75052
jmp 0x74f84
movq -0x150(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movb $0x0, %al
callq 0x10df0
movq 0x11fc0(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x11faf(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x11fa1(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0xaebf(%rip), %rsi      # 0x7fe93
movl $0x50, %edx
callq 0x10840
movq 0x11f7b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x11f6d(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x11f55(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x11f45(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x11f38(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x11f2a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x75405
jmp 0x75054
movq 0x11f05(%rip), %rax     # 0x86f60
addq $0x17c0, %rax           # imm = 0x17C0
movq %rax, -0x140(%rbp)
movl $0x0, -0x144(%rbp)
movl $0x0, -0x138(%rbp)
movl -0x138(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x138(%rbp)
movslq %eax, %rcx
movq 0x11f09(%rip), %rax     # 0x86fa0
movl (%rax,%rcx,4), %eax
movl %eax, -0x134(%rbp)
movq -0x20(%rbp), %rdi
callq 0x11ac0
cmpl $0x0, %eax
jne 0x753c2
leaq -0x120(%rbp), %rdi
movq -0x20(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x11b60
cmpq $0x0, %rax
jne 0x750d2
jmp 0x753c2
leaq -0x120(%rbp), %rdi
leaq 0xade0(%rip), %rsi      # 0x7fec0
leaq -0x124(%rbp), %rdx
leaq -0x130(%rbp), %rcx
movb $0x0, %al
callq 0x11130
cmpl $0x2, %eax
jne 0x753bd
jmp 0x75100
cmpl $0x0, -0x124(%rbp)
jle 0x75119
cmpl $0x1526, -0x124(%rbp)   # imm = 0x1526
jl 0x751f1
jmp 0x7511b
leaq 0x92b3(%rip), %rdi      # 0x7e3d5
callq 0x10380
movq -0x150(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x11e21(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x11e10(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x11e02(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0xad20(%rip), %rsi      # 0x7fe93
movl $0x50, %edx
callq 0x10840
movq 0x11ddc(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x11dce(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x11db6(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x11da6(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x11d99(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x11d8b(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x75405
jmp 0x751f3
jmp 0x751f5
cmpl $0x1526, -0x144(%rbp)   # imm = 0x1526
jge 0x753bb
movl -0x144(%rbp), %eax
cmpl -0x124(%rbp), %eax
jle 0x752ef
jmp 0x75219
leaq 0xaca7(%rip), %rdi      # 0x7fec7
callq 0x10380
movq -0x150(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x11d23(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x11d12(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x11d04(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0xac22(%rip), %rsi      # 0x7fe93
movl $0x50, %edx
callq 0x10840
movq 0x11cde(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x11cd0(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x11cb8(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x11ca8(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x11c9b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x11c8d(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x75405
movl -0x144(%rbp), %eax
cmpl -0x124(%rbp), %eax
jne 0x7535b
movsd -0x130(%rbp), %xmm0
movq -0x140(%rbp), %rax
movslq -0x144(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x144(%rbp), %eax
cmpl -0x134(%rbp), %eax
jne 0x7534a
movl -0x138(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x138(%rbp)
movslq %eax, %rcx
movq 0x11c5f(%rip), %rax     # 0x86fa0
movl (%rax,%rcx,4), %eax
movl %eax, -0x134(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x753bb
movl -0x144(%rbp), %eax
cmpl -0x134(%rbp), %eax
jne 0x7538d
movl -0x138(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x138(%rbp)
movslq %eax, %rcx
movq 0x11c1c(%rip), %rax     # 0x86fa0
movl (%rax,%rcx,4), %eax
movl %eax, -0x134(%rbp)
movq -0x140(%rbp), %rax
movslq -0x144(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x753a5
jmp 0x753a7
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x751f5
jmp 0x753bd
jmp 0x750a0
movq -0x20(%rbp), %rdi
callq 0x11160
cmpl $0x1526, -0x144(%rbp)   # imm = 0x1526
jge 0x753fe
movq -0x140(%rbp), %rax
movslq -0x144(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x753cb
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)