// File: 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
subq $0x3090, %rsp           # imm = 0x3090
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x3068(%rbp)
movb $0x0, -0x2040(%rbp)
xorl %eax, %eax
movq 0x1b81e(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6b780
callq 0x11950
movq -0x3068(%rbp), %rdi
movl %eax, %ecx
leaq 0x1369e(%rip), %rsi     # 0x7edfd
xorl %edx, %edx
leaq 0x135ea(%rip), %r8      # 0x7ed52
movl $0xb2, %r9d
leaq 0x1cb4b(%rip), %rax     # 0x882c0
movq %rax, (%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6b782
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0xfb28(%rcx), %eax
jge 0x6bb20
movq -0x20(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x2d0(%rax), %rsi
callq 0x11820
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x6bb10
movq -0x20(%rbp), %rax
cmpq $0x0, 0x1680(%rax)
jne 0x6b8bb
jmp 0x6b7e5
leaq 0x134fa(%rip), %rdi     # 0x7ece6
callq 0x10380
movq -0x3068(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x1b757(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1b746(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1b738(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1368c(%rip), %rsi     # 0x7eec9
movl $0x50, %edx
callq 0x10840
movq 0x1b712(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1b704(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1b6ec(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1b6dc(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1b6cf(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1b6c1(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x6bf0c
movq -0x20(%rbp), %rdi
addq $0x680, %rdi            # imm = 0x680
movq -0x20(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rsi
callq 0x11820
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x6bab7
movq -0x20(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
leaq 0x123ef(%rip), %rsi     # 0x7dcff
callq 0x11490
movq %rax, -0x3058(%rbp)
movq -0x20(%rbp), %rax
movl $0x0, 0xc6b4(%rax)
movq -0x20(%rbp), %rdi
addq $0x680, %rdi            # imm = 0x680
movq -0x20(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rsi
callq 0x11080
cmpq $0x0, -0x3058(%rbp)
je 0x6b984
movq -0x20(%rbp), %rax
movq 0x1680(%rax), %rdi
callq 0x11160
movq -0x3058(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x1680(%rax)
jmp 0x6bab5
jmp 0x6b986
xorl %eax, %eax
movq 0x1b5d1(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6b9d0
callq 0x11950
movq -0x3068(%rbp), %rdi
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq $0x680, %rax            # imm = 0x680
leaq 0x1354d(%rip), %rsi     # 0x7ef03
xorl %edx, %edx
leaq 0x13393(%rip), %r8      # 0x7ed52
movl $0xd0, %r9d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6b9d2
jmp 0x6b9d4
leaq 0x13553(%rip), %rdi     # 0x7ef2e
callq 0x10380
movq -0x3068(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rdx
addq $0x680, %rdx            # imm = 0x680
movb $0x0, %al
callq 0x10df0
movq 0x1b55d(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1b54c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1b53e(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x13492(%rip), %rsi     # 0x7eec9
movl $0x50, %edx
callq 0x10840
movq 0x1b518(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1b50a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1b4f2(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1b4e2(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1b4d5(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1b4c7(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x6bf0c
jmp 0x6bab7
movq -0x20(%rbp), %rax
movq 0x1680(%rax), %rdi
movq -0x20(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x20(%rax), %rsi
xorl %edx, %edx
callq 0x11350
movq -0x20(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xc6b4(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6bf0c
jmp 0x6bb12
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x6b789
jmp 0x6bb22
xorl %eax, %eax
movq 0x1b435(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6bb6c
callq 0x11950
movq -0x3068(%rbp), %rdi
movl %eax, %ecx
movq -0x20(%rbp), %rax
addq $0x1c6b8, %rax          # imm = 0x1C6B8
leaq 0x133f5(%rip), %rsi     # 0x7ef47
xorl %edx, %edx
leaq 0x131f7(%rip), %r8      # 0x7ed52
movl $0xe1, %r9d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6bb6e
leaq -0x3050(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x2d0(%rax), %rdx
leaq 0x133f0(%rip), %rsi     # 0x7ef77
movb $0x0, %al
callq 0x10280
leaq -0x1030(%rbp), %rdi
movq -0x20(%rbp), %rdx
addq $0x1c6b8, %rdx          # imm = 0x1C6B8
leaq -0x3050(%rbp), %rcx
leaq 0x13132(%rip), %rsi     # 0x7ece0
movb $0x0, %al
callq 0x10280
leaq -0x1030(%rbp), %rdi
leaq 0x1213c(%rip), %rsi     # 0x7dcff
callq 0x11490
movq %rax, -0x3058(%rbp)
xorl %eax, %eax
movq 0x1b388(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6bc16
callq 0x11950
movq -0x3068(%rbp), %rdi
movl %eax, %ecx
leaq -0x1030(%rbp), %rax
leaq 0x13382(%rip), %rsi     # 0x7ef7e
xorl %edx, %edx
leaq 0x1314d(%rip), %r8      # 0x7ed52
movl $0xe9, %r9d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6bc18
cmpq $0x0, -0x3058(%rbp)
jne 0x6bc96
movq -0x3068(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x1d6c0, %rsi          # imm = 0x1D6C0
leaq -0x3050(%rbp), %rdx
leaq -0x2040(%rbp), %rcx
callq 0x11fa0
movl %eax, -0x305c(%rbp)
xorl %eax, %eax
cmpl -0x305c(%rbp), %eax
jne 0x6bc94
leaq -0x1030(%rbp), %rdi
leaq -0x2040(%rbp), %rdx
leaq -0x3050(%rbp), %rcx
leaq 0x1306d(%rip), %rsi     # 0x7ece0
movb $0x0, %al
callq 0x10280
leaq -0x1030(%rbp), %rdi
leaq 0x12077(%rip), %rsi     # 0x7dcff
callq 0x11490
movq %rax, -0x3058(%rbp)
jmp 0x6bc96
cmpq $0x0, -0x3058(%rbp)
je 0x6bd2d
jmp 0x6bca6
xorl %eax, %eax
movq 0x1b2b1(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6bced
callq 0x11950
movq -0x3068(%rbp), %rdi
movl %eax, %ecx
leaq -0x1030(%rbp), %rax
leaq 0x132ca(%rip), %rsi     # 0x7ef9d
xorl %edx, %edx
leaq 0x13076(%rip), %r8      # 0x7ed52
movl $0xfc, %r9d
movq %rax, (%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6bcef
movq -0x20(%rbp), %rax
movq 0x1680(%rax), %rdi
callq 0x11160
movq -0x3058(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x1680(%rax)
movq -0x20(%rbp), %rdi
addq $0x680, %rdi            # imm = 0x680
leaq -0x1030(%rbp), %rsi
callq 0x11080
jmp 0x6be79
jmp 0x6bd2f
xorl %eax, %eax
movq 0x1b228(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6bd98
callq 0x11950
movl %eax, -0x3074(%rbp)
leaq -0x1030(%rbp), %rax
movq %rax, -0x3070(%rbp)
callq 0x12180
movq -0x3068(%rbp), %rdi
movl -0x3074(%rbp), %ecx
movq -0x3070(%rbp), %r10
leaq 0x13246(%rip), %rsi     # 0x7efbf
xorl %edx, %edx
leaq 0x12fd0(%rip), %r8      # 0x7ed52
movl $0x107, %r9d            # imm = 0x107
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6bd9a
jmp 0x6bd9c
leaq 0x1318b(%rip), %rdi     # 0x7ef2e
callq 0x10380
movq -0x3068(%rbp), %rdi
movq %rax, %rsi
leaq -0x3050(%rbp), %rdx
movb $0x0, %al
callq 0x10df0
movq 0x1b199(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1b188(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1b17a(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x130ce(%rip), %rsi     # 0x7eec9
movl $0x50, %edx
callq 0x10840
movq 0x1b154(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1b146(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1b12e(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1b11e(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1b111(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1b103(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x6bf0c
movq -0x20(%rbp), %rax
cmpq $0x0, 0xef70(%rax)
je 0x6be97
movq -0x20(%rbp), %rax
movq 0xef70(%rax), %rdi
callq 0x114b0
movq -0x18(%rbp), %rax
movq 0x2d0(%rax), %rdi
callq 0x120d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xef70(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0xef78(%rax)
je 0x6bed3
movq -0x20(%rbp), %rax
movq 0xef78(%rax), %rdi
callq 0x114b0
movq -0x18(%rbp), %rax
movq 0x2d0(%rax), %rdi
callq 0x120d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xef78(%rax)
movq -0x20(%rbp), %rax
movl 0xc6b4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0xef80(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x3090, %rsp           # imm = 0x3090
popq %rbp
retq
nopl (%rax,%rax)