// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_cutter_compensation_on(int, block_struct*, setup_struct*)
int Interp::convert_cutter_compensation_on(int side,     //!< side of path cutter is on (LEFT or RIGHT)
                                          block_pointer block,  //!< pointer to a block of RS274 instructions 
                                          setup_pointer settings)       //!< pointer to machine settings              
{
  double radius;
  int index, orientation;

  CHKS((settings->plane != CANON_PLANE_XY && settings->plane != CANON_PLANE_XZ),
      NCE_RADIUS_COMP_ONLY_IN_XY_OR_XZ);
  CHKS((settings->cutter_comp_side != OFF),
      NCE_CANNOT_TURN_CUTTER_RADIUS_COMP_ON_WHEN_ON);
  if(block->g_modes[7] == G_41_1 || block->g_modes[7] == G_42_1) {
      CHKS((block->d_flag != ON),
              _("G%d.1 with no D word"), block->g_modes[7]/10 );
      radius = block->d_number_float / 2;
      if(block->l_number != -1) {
          CHKS((settings->plane != CANON_PLANE_XZ), _("G%d.1 with L word, but plane is not G18"), block->g_modes[7]/10);
          orientation = block->l_number;
      } else {
          orientation = 0;
      }
  } else {
      if(block->d_flag == OFF) {
          index = 0;
      } else {
          int tool;
          CHKS(!is_near_int(&tool, block->d_number_float),
                  _("G%d requires D word to be a whole number"),
                   block->g_modes[7]/10);
          CHKS((tool < 0), NCE_NEGATIVE_D_WORD_TOOL_RADIUS_INDEX_USED);
          CHP((find_tool_pocket(settings, tool, &index)));
      }
      radius = USER_TO_PROGRAM_LEN(settings->tool_table[index].diameter) / 2.0;
      orientation = settings->tool_table[index].orientation;
      CHKS((settings->plane != CANON_PLANE_XZ && orientation != 0 && orientation != 9), _("G%d with lathe tool, but plane is not G18"), block->g_modes[7]/10);
  }
  if (radius < 0.0) { /* switch side & make radius positive if radius negative */
    radius = -radius;
    if (side == RIGHT)
      side = LEFT;
    else
      side = RIGHT;
  }
#ifdef DEBUG_EMC
  if (side == RIGHT)
    enqueue_COMMENT("interpreter: cutter radius compensation on right");
  else
    enqueue_COMMENT("interpreter: cutter radius compensation on left");
#endif

  settings->cutter_comp_radius = radius;
  settings->cutter_comp_orientation = orientation;
  settings->cutter_comp_side = side;
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, 0xc67c(%rax)
je 0x20746
movq -0x28(%rbp), %rax
cmpl $0x3, 0xc67c(%rax)
je 0x20746
jmp 0x20673
leaq 0x5982e(%rip), %rdi     # 0x79ea8
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x668cc(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x668bb(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x668ad(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x59819(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x66887(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x66879(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x66861(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x66851(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x66844(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x66836(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x20748
jmp 0x2074a
movq -0x28(%rbp), %rax
cmpl $0x0, 0x624(%rax)
je 0x20830
jmp 0x2075d
leaq 0x597cb(%rip), %rdi     # 0x79f2f
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x667e2(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x667d1(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x667c3(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x5972f(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x6679d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6678f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x66777(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x66767(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x6675a(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6674c(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x20832
movq -0x20(%rbp), %rax
cmpl $0x19b, 0x16c(%rax)     # imm = 0x19B
je 0x20856
movq -0x20(%rbp), %rax
cmpl $0x1a5, 0x16c(%rax)     # imm = 0x1A5
jne 0x20aa2
jmp 0x20858
movq -0x20(%rbp), %rax
movb 0x138(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x20959
jmp 0x20872
leaq 0x596e0(%rip), %rdi     # 0x79f59
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rax
movl 0x16c(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %edx
movb $0x0, %al
callq 0x10df0
movq 0x666b9(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x666a8(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x6669a(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x59606(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x66674(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x66666(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x6664e(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x6663e(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x66631(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x66623(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x2095b
movq -0x20(%rbp), %rax
movsd 0x130(%rax), %xmm0
movsd 0x56699(%rip), %xmm1    # 0x77008
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $-0x1, 0x1c8(%rax)
je 0x20a96
jmp 0x2098b
movq -0x28(%rbp), %rax
cmpl $0x3, 0xc67c(%rax)
je 0x20a85
jmp 0x2099e
leaq 0x595c9(%rip), %rdi     # 0x79f6e
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rax
movl 0x16c(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %edx
movb $0x0, %al
callq 0x10df0
movq 0x6658d(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x6657c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x6656e(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x594da(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x66548(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6653a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x66522(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x66512(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x66505(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x664f7(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x20a87
movq -0x20(%rbp), %rax
movl 0x1c8(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x20a9d
movl $0x0, -0x38(%rbp)
jmp 0x20f74
movq -0x20(%rbp), %rax
movb 0x138(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x20ac2
movl $0x0, -0x34(%rbp)
jmp 0x20d94
jmp 0x20ac4
movq -0x20(%rbp), %rax
movsd 0x130(%rax), %xmm0
leaq -0x3c(%rbp), %rdi
callq 0x21020
cmpl $0x0, %eax
jne 0x20bcb
jmp 0x20ae4
leaq 0x594ab(%rip), %rdi     # 0x79f96
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rax
movl 0x16c(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %edx
movb $0x0, %al
callq 0x10df0
movq 0x66447(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x66436(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x66428(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x59394(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x66402(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x663f4(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x663dc(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x663cc(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x663bf(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x663b1(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x20bcd
jmp 0x20bcf
cmpl $0x0, -0x3c(%rbp)
jge 0x20cae
jmp 0x20bdb
leaq 0x593dd(%rip), %rdi     # 0x79fbf
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x66364(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x66353(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x66345(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x592b1(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x6631f(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x66311(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x662f9(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x662e9(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x662dc(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x662ce(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x20cb0
jmp 0x20cb2
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x3c(%rbp), %edx
leaq -0x34(%rbp), %rcx
callq 0x10f70
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x20d90
jmp 0x20cd5
movq 0x66284(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x20d85
movq 0x66270(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x66262(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x591ce(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x6623c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6622e(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x66216(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x66206(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x661f9(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x661eb(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x21009
jmp 0x20d92
jmp 0x20d94
movq -0x28(%rbp), %rax
addq $0xd6c8, %rax           # imm = 0xD6C8
movslq -0x34(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd 0x50(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movq 0x66190(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x20de8
movsd 0x58067(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0x60(%rbp)
jmp 0x20e28
movq 0x66171(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x58043(%rip), %xmm0    # 0x78e40
movsd 0x5800b(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0x70(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0x68(%rbp)
je 0x20e1e
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x561ca(%rip), %xmm1    # 0x77008
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x28(%rbp), %rax
addq $0xd6c8, %rax           # imm = 0xD6C8
movslq -0x34(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl 0x68(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, 0xc67c(%rax)
je 0x20f70
cmpl $0x0, -0x38(%rbp)
je 0x20f70
cmpl $0x9, -0x38(%rbp)
je 0x20f70
jmp 0x20e89
leaq 0x59156(%rip), %rdi     # 0x79fe6
callq 0x10380
movq -0x48(%rbp), %rdi
movq %rax, %rsi
movq -0x20(%rbp), %rax
movl 0x16c(%rax), %eax
movl $0xa, %ecx
cltd
idivl %ecx
movl %eax, %edx
movb $0x0, %al
callq 0x10df0
movq 0x660a2(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x66091(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x66083(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x58fef(%rip), %rsi     # 0x79ee1
movl $0x50, %edx
callq 0x10840
movq 0x6605d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6604f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x66037(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x66027(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x6601a(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6600c(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x21009
jmp 0x20f72
jmp 0x20f74
xorps %xmm0, %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x20fb7
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x20fae
movl $0x2, -0x14(%rbp)
jmp 0x20fb5
movl $0x1, -0x14(%rbp)
jmp 0x20fb7
cmpl $0x1, -0x14(%rbp)
jne 0x20fcb
leaq 0x5904c(%rip), %rdi     # 0x7a010
callq 0x11f00
jmp 0x20fd7
leaq 0x5906f(%rip), %rdi     # 0x7a041
callq 0x11f00
movsd -0x30(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x618(%rax)
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x620(%rax)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x624(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)