// File: sundale[P]gcode/rs274ngc/interp_o_word.cc
// Function: Interp::control_save_offset(int, block_struct*, setup_struct*)
int Interp::control_save_offset( /* ARGUMENTS                   */
 int line,                   /* (o-word) line number        */
 block_pointer block,        /* pointer to a block of RS274/NGC instructions */
 setup_pointer settings)     /* pointer to machine settings */
{
  static char name[] = "control_save_offset";
  int index;

  logDebug("Entered:%s for o_name:|%s|", name, block->o_name);

  if(control_find_oword(block, settings, &index) == INTERP_OK)
  {
      // already exists
      ERS("File:%s line:%d redefining sub: o|%s| already defined in file:%s",
               settings->filename, settings->sequence_number,
	       block->o_name,
               settings->oword_offset[index].filename);
      //return INTERP_OK;
  }

  CHKS((settings->oword_labels >= INTERP_OWORD_LABELS),
      NCE_TOO_MANY_OWORD_LABELS);


  index = settings->oword_labels++;
  //logDebug("index: %d offset: %ld", index, block->offset);

  //  settings->oword_offset[index].o_word = line;
  settings->oword_offset[index].o_word_name = strdup(block->o_name);
  settings->oword_offset[index].type = block->o_type;
  settings->oword_offset[index].offset = block->offset;
  settings->oword_offset[index].filename = strdup(settings->filename);
  settings->oword_offset[index].repeat_count = -1;

  // the sequence number has already been bumped, so save
  // the proper value
  settings->oword_offset[index].sequence_number =
    settings->sequence_number - 1;

  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
movq 0x1be08(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6b1a3
callq 0x11950
movq -0x38(%rbp), %rdi
movl %eax, %ecx
movq -0x20(%rbp), %rax
movq 0x2d0(%rax), %rax
leaq 0x13ba7(%rip), %rsi     # 0x7ed24
xorl %edx, %edx
leaq 0x13bcc(%rip), %r8      # 0x7ed52
movl $0x63, %r9d
leaq 0x1d0ed(%rip), %r10     # 0x88280
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6b1a5
movq -0x38(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
callq 0x11840
cmpl $0x0, %eax
jne 0x6b2c9
jmp 0x6b1c5
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rdx
addq $0x680, %rdx            # imm = 0x680
movq -0x28(%rbp), %rax
movl 0xc6b4(%rax), %ecx
movq -0x20(%rbp), %rax
movq 0x2d0(%rax), %r8
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rsi
imulq $0x30, %rsi, %rsi
addq %rsi, %rax
movq 0x18(%rax), %r9
leaq 0x13b5a(%rip), %rsi     # 0x7ed63
movb $0x0, %al
callq 0x10df0
movq 0x1bd49(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1bd38(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1bd2a(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x13b59(%rip), %rsi     # 0x7eda4
movl $0x50, %edx
callq 0x10840
movq 0x1bd04(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1bcf6(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1bcde(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1bcce(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1bcc1(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1bcb3(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x6b4b4
jmp 0x6b2cb
movq -0x28(%rbp), %rax
cmpl $0x3e8, 0xfb28(%rax)    # imm = 0x3E8
jl 0x6b3b4
jmp 0x6b2e1
leaq 0x13aff(%rip), %rdi     # 0x7ede7
callq 0x10380
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x1bc5e(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x1bc4d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x1bc3f(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x13a6e(%rip), %rsi     # 0x7eda4
movl $0x50, %edx
callq 0x10840
movq 0x1bc19(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1bc0b(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x1bbf3(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x1bbe3(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x1bbd6(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x1bbc8(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x6b4b4
jmp 0x6b3b6
movq -0x28(%rbp), %rcx
movl 0xfb28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0xfb28(%rcx)
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq 0x2d0(%rax), %rdi
callq 0x120d0
movq %rax, %rcx
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x2c8(%rax), %ecx
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x2c0(%rax), %rcx
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rdi
addq $0x680, %rdi            # imm = 0x680
callq 0x120d0
movq %rax, %rcx
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x2c(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl 0xc6b4(%rax), %ecx
subl $0x1, %ecx
movq -0x28(%rbp), %rax
addq $0xfb30, %rax           # imm = 0xFB30
movslq -0x2c(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x28(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)