// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rdi, %r12
movb $0x0, -0x2050(%rbp)
movq 0x14051(%rip), %rax     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x28f4a
callq 0xc0b0
leaq 0x14ddc(%rip), %rcx     # 0x3dd00
movq %rcx, (%rsp)
leaq 0xd10c(%rip), %rsi      # 0x3603b
leaq 0xd09d(%rip), %r8       # 0x35fd3
movq %r12, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xb2, %r9d
xorl %eax, %eax
callq 0xc5e0
movl 0xfb28(%r14), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
imulq $0x30, %rax, %rbx
addq $0x30, %rbx
leaq 0x30(%rcx), %r13
cmpq %r13, %rbx
je 0x29028
movq 0xfb38(%r14,%rcx), %rdi
movq 0x2d0(%r15), %rsi
callq 0xbfd0
movq %r13, %rcx
testl %eax, %eax
jne 0x28f60
movq %r12, -0x30(%rbp)
movq 0x1680(%r14), %r12
testq %r12, %r12
je 0x29248
leaq 0x680(%r14), %r15
movq 0xfb18(%r14,%r13), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0xbfd0
testl %eax, %eax
je 0x29000
leaq 0xc45e(%rip), %rsi      # 0x3541f
movq %rbx, %rdi
callq 0xbdd0
movq %rax, %r12
andl $0x0, 0xc6b4(%r14)
movq 0xfb18(%r14,%r13), %rsi
movq %r15, %rdi
callq 0xba80
testq %r12, %r12
je 0x292a8
movq 0x1680(%r14), %rdi
callq 0xbb40
movq %r12, 0x1680(%r14)
movq 0xfb20(%r14,%r13), %rsi
xorl %ebx, %ebx
movq %r12, %rdi
xorl %edx, %edx
callq 0xbcd0
movl 0xfb28(%r14,%r13), %eax
movl %eax, 0xc6b4(%r14)
jmp 0x29294
movq 0x13f31(%rip), %rbx     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rbx)
jle 0x2906a
callq 0xc0b0
leaq 0x1c6b8(%r14), %rcx
movq %rcx, (%rsp)
leaq 0xd0b8(%rip), %rsi      # 0x36107
leaq 0xcf7d(%rip), %r8       # 0x35fd3
movq %r12, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xe1, %r9d
xorl %eax, %eax
callq 0xc5e0
movq %r12, %rbx
movq 0x2d0(%r15), %rdx
leaq 0xd0bc(%rip), %rsi      # 0x36137
leaq -0x1040(%rbp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0xb190
leaq 0x1c6b8(%r14), %rdx
leaq 0xcef7(%rip), %rsi      # 0x35f91
leaq -0x3060(%rbp), %r12
movq %r12, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xb190
leaq 0xc36a(%rip), %rsi      # 0x3541f
movq %r12, %rdi
callq 0xbdd0
movq %rax, %r13
movq 0x13e99(%rip), %rax     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x290fb
callq 0xc0b0
movq %r12, (%rsp)
leaq 0xd05e(%rip), %rsi      # 0x3613e
leaq 0xceec(%rip), %r8       # 0x35fd3
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xe9, %r9d
xorl %eax, %eax
callq 0xc5e0
testq %r13, %r13
je 0x291b8
movq 0x13e55(%rip), %rax     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x2913f
callq 0xc0b0
movq %r12, (%rsp)
leaq 0xd039(%rip), %rsi      # 0x3615d
leaq 0xcea8(%rip), %r8       # 0x35fd3
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xfc, %r9d
xorl %eax, %eax
callq 0xc5e0
movq 0x1680(%r14), %rdi
callq 0xbb40
movq %r13, 0x1680(%r14)
leaq 0x680(%r14), %rdi
leaq -0x3060(%rbp), %rsi
callq 0xba80
movq 0xef70(%r14), %rdi
callq 0xbde0
movq 0x2d0(%r15), %rdi
callq 0xc650
movq %rax, 0xef70(%r14)
movq 0xef78(%r14), %rdi
callq 0xbde0
movq 0x2d0(%r15), %rdi
callq 0xc650
movq %rax, 0xef78(%r14)
movl 0xc6b4(%r14), %eax
movl %eax, 0xef80(%r14)
xorl %ebx, %ebx
jmp 0x29294
leaq 0x1d6c0(%r14), %rsi
leaq -0x1040(%rbp), %rdx
leaq -0x2050(%rbp), %rcx
movq %rbx, %rdi
callq 0xc560
testl %eax, %eax
je 0x2930b
movq 0x13d7c(%rip), %rax     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x29226
callq 0xc0b0
movl %eax, %r14d
callq 0xc6e0
movq %rax, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0xcf75(%rip), %rsi      # 0x3617f
leaq 0xcdc2(%rip), %r8       # 0x35fd3
movq %rbx, %rdi
xorl %edx, %edx
movl %r14d, %ecx
movl $0x107, %r9d            # imm = 0x107
xorl %eax, %eax
callq 0xc5e0
leaq 0xcec1(%rip), %rdi      # 0x360ee
callq 0xb220
leaq -0x1040(%rbp), %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
jmp 0x29262
leaq 0xcd48(%rip), %rdi      # 0x35f97
callq 0xb220
movq -0x30(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x13cf7(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0xcc78(%rip), %rsi      # 0x35eef
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %rbx
movl %ebx, %eax
addq $0x3048, %rsp           # imm = 0x3048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %r14
movq 0x13cae(%rip), %rbx     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rbx)
movq -0x30(%rbp), %r15
jle 0x292ea
callq 0xc0b0
movq %r14, (%rsp)
leaq 0xcdf4(%rip), %rsi      # 0x360c3
leaq 0xccfd(%rip), %r8       # 0x35fd3
movq %r15, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xd0, %r9d
xorl %eax, %eax
callq 0xc5e0
leaq 0xcdfd(%rip), %rdi      # 0x360ee
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb8e0
jmp 0x29269
leaq 0xcc7f(%rip), %rsi      # 0x35f91
leaq -0x3060(%rbp), %r13
leaq -0x2050(%rbp), %rdx
leaq -0x1040(%rbp), %rcx
movq %r13, %rdi
xorl %eax, %eax
callq 0xb190
leaq 0xc0e7(%rip), %rsi      # 0x3541f
movq %r13, %rdi
callq 0xbdd0
testq %rax, %rax
je 0x291dd
movq %rax, %r13
jmp 0x29104
nop