// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movb $0x0, -0x2050(%rbp)
movq 0x14b27(%rip), %rax     # 0x43f60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x2f474
callq 0xaf80
leaq 0x157f2(%rip), %rcx     # 0x44c40
movq %rcx, (%rsp)
leaq 0xdbed(%rip), %rsi      # 0x3d046
leaq 0xdb7e(%rip), %r8       # 0x3cfde
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 0x2f4b7
movq 0x2d0(%r15), %r12
shlq $0x4, %rax
leaq (%rax,%rax,2), %rbx
xorl %r13d, %r13d
movq 0xfb38(%r14,%r13), %rdi
movq %r12, %rsi
callq 0xaeb0
testl %eax, %eax
je 0x2f5b9
addq $0x30, %r13
cmpq %r13, %rbx
jne 0x2f496
movq 0x14aa2(%rip), %rbx     # 0x43f60
cmpl $0x0, 0x1b6b4(%rbx)
jle 0x2f4fa
callq 0xaf80
leaq 0x1c6b8(%r14), %rcx
movq %rcx, (%rsp)
leaq 0xdc34(%rip), %rsi      # 0x3d112
leaq 0xdaf9(%rip), %r8       # 0x3cfde
movq -0x30(%rbp), %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xe1, %r9d
xorl %eax, %eax
callq 0xb470
movq 0x2d0(%r15), %rdx
leaq 0xdc3a(%rip), %rsi      # 0x3d142
leaq -0x1040(%rbp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0xa170
leaq 0x1c6b8(%r14), %rdx
leaq 0xda72(%rip), %rsi      # 0x3cf99
leaq -0x3060(%rbp), %r12
movq %r12, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xa170
leaq 0xcee5(%rip), %rsi      # 0x3c427
movq %r12, %rdi
callq 0xace0
movq %rax, %r13
cmpl $0x0, 0x1b6b4(%rbx)
jle 0x2f582
callq 0xaf80
movq %r12, (%rsp)
leaq 0xdbe3(%rip), %rsi      # 0x3d149
leaq 0xda71(%rip), %r8       # 0x3cfde
movq -0x30(%rbp), %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xe9, %r9d
xorl %eax, %eax
callq 0xb470
testq %r13, %r13
jne 0x2f6bf
leaq 0x1d6c0(%r14), %rsi
leaq -0x1040(%rbp), %rdx
leaq -0x2050(%rbp), %rcx
movq -0x30(%rbp), %rdi
callq 0xb3f0
testl %eax, %eax
je 0x2f687
xorl %r13d, %r13d
jmp 0x2f6bf
cmpq $0x0, 0x1680(%r14)
je 0x2f661
leaq 0x680(%r14), %r15
movq 0xfb48(%r14,%r13), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0xaeb0
testl %eax, %eax
movq 0x14976(%rip), %rbx     # 0x43f60
je 0x2f635
leaq 0xce34(%rip), %rsi      # 0x3c427
movq %r12, %rdi
callq 0xace0
movq %rax, %r12
movl $0x0, 0xc6b4(%r14)
movq 0xfb48(%r14,%r13), %rsi
movq %r15, %rdi
callq 0xa9d0
testq %r12, %r12
je 0x2f830
movq 0x1680(%r14), %rdi
callq 0xaa80
movq %r12, 0x1680(%r14)
movq 0x1680(%r14), %rdi
movq 0xfb50(%r14,%r13), %rsi
xorl %ebx, %ebx
xorl %edx, %edx
callq 0xabe0
movl 0xfb58(%r14,%r13), %eax
movl %eax, 0xc6b4(%r14)
jmp 0x2f81c
leaq 0xd937(%rip), %rdi      # 0x3cf9f
callq 0xa1f0
movq -0x30(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x148de(%rip), %rbx     # 0x43f60
jmp 0x2f7e2
leaq 0xd90b(%rip), %rsi      # 0x3cf99
leaq -0x3060(%rbp), %r13
leaq -0x2050(%rbp), %rdx
leaq -0x1040(%rbp), %rcx
movq %r13, %rdi
xorl %eax, %eax
callq 0xa170
leaq 0xcd73(%rip), %rsi      # 0x3c427
movq %r13, %rdi
callq 0xace0
movq %rax, %r13
movl 0x1b6b4(%rbx), %eax
testq %r13, %r13
je 0x2f781
testl %eax, %eax
jle 0x2f6fe
callq 0xaf80
movq %r12, (%rsp)
leaq 0xda86(%rip), %rsi      # 0x3d168
leaq 0xd8f5(%rip), %r8       # 0x3cfde
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
je 0x2f735
callq 0xacf0
movq 0x2d0(%r15), %rdi
callq 0xb4e0
movq %rax, 0xef70(%r14)
movq 0xef78(%r14), %rdi
testq %rdi, %rdi
je 0x2f759
callq 0xacf0
movq 0x2d0(%r15), %rdi
callq 0xb4e0
movq %rax, 0xef78(%r14)
movl 0xc6b4(%r14), %eax
movl %eax, 0xef80(%r14)
xorl %ebx, %ebx
jmp 0x2f81c
testl %eax, %eax
movq -0x30(%rbp), %r15
jle 0x2f7c2
callq 0xaf80
movl %eax, %r14d
callq 0xb570
movq %rax, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0xd9e4(%rip), %rsi      # 0x3d18a
leaq 0xd831(%rip), %r8       # 0x3cfde
movq %r15, %rdi
xorl %edx, %edx
movl %r14d, %ecx
movl $0x107, %r9d            # imm = 0x107
xorl %eax, %eax
callq 0xb470
leaq 0xd930(%rip), %rdi      # 0x3d0f9
callq 0xa1f0
leaq -0x1040(%rbp), %rdx
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0xd6fd(%rip), %rsi      # 0x3cef7
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %ebx
movl %ebx, %eax
addq $0x3048, %rsp           # imm = 0x3048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, 0x1b6b4(%rbx)
movq -0x30(%rbp), %r14
jle 0x2f868
callq 0xaf80
movq %r15, (%rsp)
leaq 0xd881(%rip), %rsi      # 0x3d0ce
leaq 0xd78a(%rip), %r8       # 0x3cfde
movq %r14, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0xd0, %r9d
xorl %eax, %eax
callq 0xb470
leaq 0xd88a(%rip), %rdi      # 0x3d0f9
callq 0xa1f0
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
jmp 0x2f7db