// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdi, %rbx
movl 0xc67c(%rcx), %eax
movl %eax, %ecx
orl $0x2, %ecx
cmpl $0x3, %ecx
jne 0x10e14
cmpl $0x0, 0x624(%r14)
je 0x10e77
leaq 0x24881(%rip), %rdi     # 0x35693
jmp 0x10e1b
leaq 0x2483f(%rip), %rdi     # 0x3565a
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x3012c(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x235d7(%rip), %rsi     # 0x34419
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r12
movl %esi, %r15d
movl 0x16c(%rdx), %ecx
cmpl $0x1a5, %ecx            # imm = 0x1A5
je 0x10e93
cmpl $0x19b, %ecx            # imm = 0x19B
jne 0x10ed0
cmpb $0x0, 0x138(%r12)
je 0x10f24
movsd 0x130(%r12), %xmm1
movl 0x1c8(%r12), %r13d
cmpl $-0x1, %r13d
je 0x10f5e
cmpl $0x3, %eax
je 0x10f61
leaq 0x24804(%rip), %rdi     # 0x356d2
jmp 0x10f2b
cmpb $0x0, 0x138(%r12)
je 0x10fcf
movsd 0x130(%r12), %xmm1
movsd 0x21117(%rip), %xmm0    # 0x32008
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm1, %xmm2
andpd 0x21117(%rip), %xmm2    # 0x32020
movsd 0x2294f(%rip), %xmm1    # 0x33860
ucomisd %xmm2, %xmm1
ja 0x1102a
leaq 0x247d8(%rip), %rdi     # 0x356fa
jmp 0x10f2b
leaq 0x24792(%rip), %rdi     # 0x356bd
callq 0xa1f0
movslq 0x16c(%r12), %rcx
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rdx
addl %ecx, %edx
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
jmp 0x10e2d
xorl %r13d, %r13d
mulsd 0x2109f(%rip), %xmm1    # 0x32008
movapd 0x22f9f(%rip), %xmm0    # 0x33f10
xorpd %xmm1, %xmm0
xorl %ebx, %ebx
cmpl $0x1, %r15d
sete %bl
incl %ebx
ucomisd %xmm1, %xmm0
cmovbel %r15d, %ebx
maxsd %xmm1, %xmm0
movapd %xmm0, -0x40(%rbp)
cmpl $0x1, %ebx
leaq 0x247d9(%rip), %rax     # 0x35774
leaq 0x24803(%rip), %rdi     # 0x357a5
cmoveq %rax, %rdi
callq 0xb370
movapd -0x40(%rbp), %xmm0
movsd %xmm0, 0x618(%r14)
movl %r13d, 0x620(%r14)
movl %ebx, 0x624(%r14)
xorl %r13d, %r13d
jmp 0x10e65
movl $0x0, -0x2c(%rbp)
xorl %eax, %eax
imulq $0x70, %rax, %rax
movsd 0xd718(%r14,%rax), %xmm0
movapd %xmm0, -0x40(%rbp)
callq 0xa990
movapd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
movq 0x2ff60(%rip), %rsi     # 0x40f60
movl 0x1690(%rsi), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x110b8
movb %cl, %al
leaq 0x22f70(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x110c0
cvttsd2si %xmm0, %edx
testl %edx, %edx
js 0x1115f
leaq -0x2c(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa930
testl %eax, %eax
je 0x1116b
movl %eax, %r13d
movq 0x2ff09(%rip), %rbx     # 0x40f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x10e65
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x23397(%rip), %rsi     # 0x34419
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%rbx), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x10e65
movsd 0x22e08(%rip), %xmm0    # 0x33ec8
divsd %xmm0, %xmm1
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movl 0xd730(%r14,%rax), %r13d
cmpl $0x3, 0xc67c(%r14)
je 0x10f61
testl %r13d, %r13d
je 0x10f61
cmpl $0x9, %r13d
je 0x10f61
leaq 0x2464e(%rip), %rdi     # 0x3574a
movq %rsi, %r14
callq 0xa1f0
movslq 0x16c(%r12), %rcx
imulq $0x66666667, %rcx, %rdx # imm = 0x66666667
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rdx
addl %ecx, %edx
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
leaq 0xc6d0(%r14), %rdi
leaq 0x232de(%rip), %rsi     # 0x34419
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%r14)
movl $0x1, 0xd670(%r14)
jmp 0x10e5f
leaq 0x245bd(%rip), %rdi     # 0x35723
jmp 0x10e1b
movslq -0x2c(%rbp), %rax
jmp 0x10fd8