// File: /workspace/github_cpp_makefile_star2_O3/sundale[P]gcode/rs274ngc/interp_o_word.cc
// Function: Interp::control_back_to(block_struct*, setup_struct*)
int Interp::control_back_to( /* ARGUMENTS                       */
 block_pointer block, // pointer to block
 setup_pointer settings)   /* pointer to machine settings      */
{
  static char name[] = "control_back_to";
  int i;
  char newFileName[PATH_MAX+1];
  char foundPlace[PATH_MAX+1];
  char tmpFileName[PATH_MAX+1];
  FILE *newFP;

  foundPlace[0] = 0;
  logDebug("Entered:%s", name);
  for(i=0; i<settings->oword_labels; i++)
    {
      // if(settings->oword_offset[i].o_word == line)
      if(0 == strcmp(settings->oword_offset[i].o_word_name, block->o_name))
	{
          if(settings->file_pointer == NULL)
          {
            ERS(NCE_FILE_NOT_OPEN);
          }
          if(0 != strcmp(settings->filename,
                         settings->oword_offset[i].filename))
          {
              // open the new file...

              newFP = fopen(settings->oword_offset[i].filename, "r");

              // set the line number
              settings->sequence_number = 0;

              strcpy(settings->filename, settings->oword_offset[i].filename);

              if(newFP)
              {
                  // close the old file...
                  fclose(settings->file_pointer);
                  settings->file_pointer = newFP;
              }
              else
              {
                  logDebug("Unable to open file: %s", settings->filename);
                  ERS(NCE_UNABLE_TO_OPEN_FILE,settings->filename);
              }
          }
	  fseek(settings->file_pointer,
		settings->oword_offset[i].offset, SEEK_SET);

	  settings->sequence_number =
	    settings->oword_offset[i].sequence_number;

	  return INTERP_OK;
	}
    }

  // NO o_word found

  // look for a new file
  logDebug("settings->program_prefix:%s:", settings->program_prefix);
  sprintf(tmpFileName, "%s.ngc", block->o_name);

  // first look in the prefix place

  sprintf(newFileName, "%s/%s", settings->program_prefix, tmpFileName);

  newFP = fopen(newFileName, "r");
  logDebug("fopen: |%s|", newFileName);

  // if not found, search the wizard tree
  if(!newFP)
  {
      int ret;
      ret = findFile(settings->wizard_root, tmpFileName, foundPlace);

      if(INTERP_OK == ret)
      {
	  // create the long name
          sprintf(newFileName, "%s/%s",
		  foundPlace, tmpFileName);
          newFP = fopen(newFileName, "r");
      }
  }

  if(newFP)
  {
      logDebug("fopen: |%s| OK", newFileName);

      // close the old file...
      fclose(settings->file_pointer);
      settings->file_pointer = newFP;

      strcpy(settings->filename, newFileName);
  }
  else
  {
     logDebug("fopen: |%s| failed CWD:|%s|", newFileName,
              get_current_dir_name());
     ERS(NCE_UNABLE_TO_OPEN_FILE,tmpFileName);
  }

  if(settings->skipping_o)free(settings->skipping_o);
  settings->skipping_o = strdup(block->o_name); // start skipping

  if(settings->skipping_to_sub)free(settings->skipping_to_sub);
  settings->skipping_to_sub = strdup(block->o_name); // start skipping

  settings->skipping_start = settings->sequence_number;
  //ERS(NCE_UNKNOWN_OWORD_NUMBER);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3048, %rsp           # imm = 0x3048
movq %rdx, %r14
movq %rsi, -0x38(%rbp)
movq %rdi, %rbx
movb $0x0, -0x2050(%rbp)
movq 0x1545a(%rip), %rax     # 0x40f60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x2bb41
callq 0xaf80
leaq 0x16125(%rip), %rcx     # 0x41c40
movq %rcx, (%rsp)
leaq 0xe515(%rip), %rsi      # 0x3a03b
leaq 0xe4a6(%rip), %r8       # 0x39fd3
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xb2, %r9d
xorl %eax, %eax
callq 0xb470
movq %rbx, -0x30(%rbp)
movslq 0xfb28(%r14), %rax
testq %rax, %rax
jle 0x2bb88
movq -0x38(%rbp), %rcx
movq 0x2d0(%rcx), %r12
shlq $0x4, %rax
leaq (%rax,%rax,2), %r13
xorl %r15d, %r15d
movq 0xfb38(%r14,%r15), %rdi
movq %r12, %rsi
callq 0xaeb0
testl %eax, %eax
je 0x2bd25
addq $0x30, %r15
cmpq %r15, %r13
jne 0x2bb67
movq 0x153d1(%rip), %r15     # 0x40f60
cmpl $0x0, 0x1b6b4(%r15)
jle 0x2bbcc
callq 0xaf80
leaq 0x1c6b8(%r14), %rcx
movq %rcx, (%rsp)
leaq 0xe557(%rip), %rsi      # 0x3a107
leaq 0xe41c(%rip), %r8       # 0x39fd3
movq -0x30(%rbp), %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xe1, %r9d
xorl %eax, %eax
callq 0xb470
movq -0x38(%rbp), %rax
movq 0x2d0(%rax), %rdx
leaq 0xe559(%rip), %rsi      # 0x3a137
leaq -0x1040(%rbp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0xa170
leaq 0x1c6b8(%r14), %rdx
leaq 0xe394(%rip), %rsi      # 0x39f91
leaq -0x3060(%rbp), %r12
movq %r12, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xa170
leaq 0xd807(%rip), %rsi      # 0x3941f
movq %r12, %rdi
callq 0xace0
movq %rax, %r13
cmpl $0x0, 0x1b6b4(%r15)
jle 0x2bc59
callq 0xaf80
movq %r12, (%rsp)
leaq 0xe501(%rip), %rsi      # 0x3a13e
leaq 0xe38f(%rip), %r8       # 0x39fd3
movq -0x30(%rbp), %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xe9, %r9d
xorl %eax, %eax
callq 0xb470
testq %r13, %r13
je 0x2bdc4
cmpl $0x0, 0x1b6b4(%r15)
jle 0x2bc98
callq 0xaf80
movq %r12, (%rsp)
leaq 0xe4e1(%rip), %rsi      # 0x3a15d
leaq 0xe350(%rip), %r8       # 0x39fd3
movq -0x30(%rbp), %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xfc, %r9d
xorl %eax, %eax
callq 0xb470
movq 0x1680(%r14), %rdi
callq 0xaa80
movq %r13, 0x1680(%r14)
leaq 0x680(%r14), %rdi
leaq -0x3060(%rbp), %rsi
callq 0xa9d0
movq 0xef70(%r14), %rdi
testq %rdi, %rdi
movq -0x38(%rbp), %r15
je 0x2bcd3
callq 0xacf0
movq 0x2d0(%r15), %rbx
movq %rbx, %rdi
callq 0xb4e0
movq %rax, 0xef70(%r14)
movq 0xef78(%r14), %rdi
testq %rdi, %rdi
je 0x2bd01
callq 0xacf0
movq 0x2d0(%r15), %rbx
movq %rbx, %rdi
callq 0xb4e0
movq %rax, 0xef78(%r14)
movl 0xc6b4(%r14), %eax
movl %eax, 0xef80(%r14)
xorl %ebx, %ebx
jmp 0x2bfab
movq 0x1680(%r14), %r12
testq %r12, %r12
je 0x2be83
leaq 0x680(%r14), %rbx
movq 0xfb48(%r14,%r15), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0xaeb0
testl %eax, %eax
je 0x2bd9c
leaq 0xd6c5(%rip), %rsi      # 0x3941f
movq %r13, %rdi
callq 0xace0
movq %rax, %r12
movl $0x0, 0xc6b4(%r14)
movq 0xfb48(%r14,%r15), %rsi
movq %rbx, %rdi
callq 0xa9d0
testq %r12, %r12
je 0x2bf1a
movq 0x1680(%r14), %rdi
callq 0xaa80
movq %r12, 0x1680(%r14)
movq 0xfb50(%r14,%r15), %rsi
xorl %ebx, %ebx
movq %r12, %rdi
xorl %edx, %edx
callq 0xabe0
movl 0xfb58(%r14,%r15), %eax
movl %eax, 0xc6b4(%r14)
jmp 0x2bfab
leaq 0x1d6c0(%r14), %rsi
leaq -0x1040(%rbp), %rdx
leaq -0x2050(%rbp), %rcx
movq -0x30(%rbp), %rdi
callq 0xb3f0
testl %eax, %eax
je 0x2bed4
cmpl $0x0, 0x1b6b4(%r15)
movq -0x30(%rbp), %rbx
jle 0x2be31
callq 0xaf80
movl %eax, %r14d
callq 0xb570
movq %rax, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0xe36a(%rip), %rsi      # 0x3a17f
leaq 0xe1b7(%rip), %r8       # 0x39fd3
movq %rbx, %rdi
xorl %edx, %edx
movl %r14d, %ecx
movl $0x107, %r9d            # imm = 0x107
xorl %eax, %eax
callq 0xb470
leaq 0xe2b6(%rip), %rdi      # 0x3a0ee
callq 0xa1f0
leaq -0x1040(%rbp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
leaq 0xc6d0(%r15), %rdi
leaq 0xe090(%rip), %rsi      # 0x39eef
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%r15)
movl $0x1, 0xd670(%r15)
jmp 0x2bfa6
leaq 0xe10d(%rip), %rdi      # 0x39f97
callq 0xa1f0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x150bc(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0xe03d(%rip), %rsi      # 0x39eef
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
jmp 0x2bfa6
leaq 0xe0b6(%rip), %rsi      # 0x39f91
leaq -0x3060(%rbp), %r13
leaq -0x2050(%rbp), %rdx
leaq -0x1040(%rbp), %rcx
movq %r13, %rdi
xorl %eax, %eax
callq 0xa170
leaq 0xd51e(%rip), %rsi      # 0x3941f
movq %r13, %rdi
callq 0xace0
testq %rax, %rax
je 0x2bdea
movq %rax, %r13
jmp 0x2bc62
movq %rbx, %r13
movq 0x1503c(%rip), %r14     # 0x40f60
cmpl $0x0, 0x1b6b4(%r14)
movq -0x30(%rbp), %rbx
jle 0x2bf5d
callq 0xaf80
movq %r13, (%rsp)
leaq 0xe181(%rip), %rsi      # 0x3a0c3
leaq 0xe08a(%rip), %r8       # 0x39fd3
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xd0, %r9d
xorl %eax, %eax
callq 0xb470
leaq 0xe18a(%rip), %rdi      # 0x3a0ee
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xa850
leaq 0xc6d0(%r14), %rdi
leaq 0xdf68(%rip), %rsi      # 0x39eef
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%r14)
movl $0x1, 0xd670(%r14)
movl $0x5, %ebx
movl %ebx, %eax
addq $0x3048, %rsp           # imm = 0x3048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop