// File: /workspace/github_cpp_makefile_star2_O2/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 0x11a86
cmpl $0x0, 0x624(%r14)
je 0x11ae4
leaq 0x1fc19(%rip), %rdi     # 0x3169d
jmp 0x11a8d
leaq 0x1fbd7(%rip), %rdi     # 0x31664
callq 0xb220
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2b4ba(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1e965(%rip), %rsi     # 0x30419
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r13
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 0x11b00
cmpl $0x19b, %ecx            # imm = 0x19B
jne 0x11b3d
cmpb $0x0, 0x138(%r12)
je 0x11b91
movsd 0x130(%r12), %xmm1
movl 0x1c8(%r12), %r13d
cmpl $-0x1, %r13d
je 0x11bbf
cmpl $0x3, %eax
je 0x11bc2
leaq 0x1fba1(%rip), %rdi     # 0x316dc
jmp 0x11b98
cmpb $0x0, 0x138(%r12)
je 0x11c30
movsd 0x130(%r12), %xmm1
movsd 0x1c4aa(%rip), %xmm0    # 0x2e008
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm1, %xmm2
andpd 0x1c4aa(%rip), %xmm2    # 0x2e020
movsd 0x1dce2(%rip), %xmm1    # 0x2f860
ucomisd %xmm2, %xmm1
ja 0x11c88
leaq 0x1fb75(%rip), %rdi     # 0x31704
jmp 0x11b98
leaq 0x1fb2f(%rip), %rdi     # 0x316c7
callq 0xb220
movq %rax, %rsi
movl 0x16c(%r12), %eax
pushq $0xa
popq %rcx
cltd
idivl %ecx
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xb8e0
jmp 0x11a9f
xorl %r13d, %r13d
mulsd 0x1c43e(%rip), %xmm1    # 0x2e008
movapd 0x1e33e(%rip), %xmm0    # 0x2ff10
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 0x1fb82(%rip), %rax     # 0x3177e
leaq 0x1fbac(%rip), %rdi     # 0x317af
cmoveq %rax, %rdi
callq 0xc4d0
movapd -0x40(%rbp), %xmm0
movsd %xmm0, 0x618(%r14)
movl %r13d, 0x620(%r14)
movl %ebx, 0x624(%r14)
xorl %r13d, %r13d
jmp 0x11ad2
andl $0x0, -0x2c(%rbp)
xorl %eax, %eax
imulq $0x70, %rax, %rax
movsd 0xd718(%r14,%rax), %xmm0
movapd %xmm0, -0x40(%rbp)
callq 0xba40
movapd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
movq 0x2b302(%rip), %rsi     # 0x3cf60
movl 0x1690(%rsi), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x11d0c
movb %cl, %al
leaq 0x1e312(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x11d14
cvttsd2si %xmm0, %edx
testl %edx, %edx
js 0x11da4
leaq -0x2c(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb9d0
testl %eax, %eax
je 0x11db0
movl %eax, %r13d
movq 0x2b2ab(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x11ad2
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x1e73d(%rip), %rsi     # 0x30419
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%rbx), %rax
imulq $0x50, %rax, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x11ad2
movsd 0x1e1b4(%rip), %xmm0    # 0x2fec8
divsd %xmm0, %xmm1
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movl 0xd730(%r14,%rax), %r13d
cmpl $0x3, 0xc67c(%r14)
je 0x11bc2
testl %r13d, %r13d
je 0x11bc2
cmpl $0x9, %r13d
je 0x11bc2
leaq 0x1fa04(%rip), %rdi     # 0x31754
movq %rsi, %r14
callq 0xb220
movq %rax, %rsi
movl 0x16c(%r12), %eax
pushq $0xa
popq %rcx
cltd
idivl %ecx
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xb8e0
leaq 0xc6d0(%r14), %rdi
leaq 0x1e696(%rip), %rsi     # 0x30419
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%r14)
movl $0x1, 0xd670(%r14)
jmp 0x11ace
leaq 0x1f982(%rip), %rdi     # 0x3172d
jmp 0x11a8d
movslq -0x2c(%rbp), %rax
jmp 0x11c36
nop