// File: /workspace/github_cpp_makefile_star2_O1/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 0x111b4
cmpl $0x0, 0x624(%r14)
je 0x11221
leaq 0x274e1(%rip), %rdi     # 0x38693
jmp 0x111bb
leaq 0x2749f(%rip), %rdi     # 0x3865a
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x32d8c(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x2622d(%rip), %rsi     # 0x37419
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 0x1123d
cmpl $0x19b, %ecx            # imm = 0x19B
jne 0x1127d
cmpb $0x0, 0x138(%r12)
je 0x11306
movsd 0x130(%r12), %xmm1
movl 0x1c8(%r12), %r13d
cmpl $-0x1, %r13d
je 0x11340
cmpl $0x3, %eax
je 0x1155d
leaq 0x2745a(%rip), %rdi     # 0x386d2
jmp 0x1130d
cmpb $0x0, 0x138(%r12)
je 0x11348
movsd 0x130(%r12), %xmm1
movsd 0x23d6a(%rip), %xmm0    # 0x35008
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm1, %xmm2
andpd 0x23d6a(%rip), %xmm2    # 0x35020
movsd 0x255a2(%rip), %xmm1    # 0x36860
ucomisd %xmm2, %xmm1
ja 0x11354
movl %r15d, -0x40(%rbp)
leaq 0x27427(%rip), %rdi     # 0x386fa
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 0x11408
leaq 0x273b0(%rip), %rdi     # 0x386bd
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 0x111cd
xorl %r13d, %r13d
jmp 0x1155d
movl $0x0, -0x2c(%rbp)
jmp 0x11464
cvttsd2si %xmm0, %edx
testl %edx, %edx
js 0x113eb
leaq -0x2c(%rbp), %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa930
movl %eax, %r13d
testl %eax, %eax
sete %al
je 0x1145c
movq 0x32bdc(%rip), %rcx     # 0x43f60
movslq 0xd670(%rcx), %rax
cmpq $0x30, %rax
jg 0x115cb
movl %r15d, -0x40(%rbp)
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rcx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x26066(%rip), %rsi     # 0x37419
movl $0x50, %edx
movq %rcx, %r15
callq 0xa8a0
movq %r15, %rdx
movslq 0xd670(%r15), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
addq %rcx, %r15
addq $0xc720, %r15           # imm = 0xC720
movb $0x0, -0x1(%r15)
incl %eax
movl %eax, 0xd670(%rdx)
jmp 0x11452
movl %r15d, -0x40(%rbp)
leaq 0x2732d(%rip), %rdi     # 0x38723
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x32b51(%rip), %r15     # 0x43f60
movl $0x0, 0xd670(%r15)
leaq 0xc6d0(%r15), %rdi
leaq 0x25ff1(%rip), %rsi     # 0x37419
movl $0x50, %edx
callq 0xa8a0
movb $0x0, 0xc71f(%r15)
movl $0x1, 0xd670(%r15)
addq $0xc720, %r15           # imm = 0xC720
movl $0x5, %r13d
movb $0x0, (%r15)
xorl %eax, %eax
movl -0x40(%rbp), %r15d
testb %al, %al
je 0x1120f
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd 0xd718(%r14,%rax), %xmm0
movapd %xmm0, -0x40(%rbp)
callq 0xa990
movapd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
movq 0x32ad0(%rip), %rsi     # 0x43f60
movl 0x1690(%rsi), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x114b3
movb %cl, %al
leaq 0x25ae4(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x114bb
movsd 0x25a0d(%rip), %xmm0    # 0x36ec8
divsd %xmm0, %xmm1
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movl 0xd730(%r14,%rax), %r13d
cmpl $0x3, 0xc67c(%r14)
je 0x1155d
testl %r13d, %r13d
je 0x1155d
cmpl $0x9, %r13d
je 0x1155d
leaq 0x2725b(%rip), %rdi     # 0x3874a
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
movl $0x0, 0xd670(%r14)
leaq 0xc6d0(%r14), %rdi
leaq 0x25ee0(%rip), %rsi     # 0x37419
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%r14)
movl $0x1, 0xd670(%r14)
jmp 0x11209
mulsd 0x23aa3(%rip), %xmm1    # 0x35008
movapd 0x259a3(%rip), %xmm0    # 0x36f10
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 0x271dd(%rip), %rax     # 0x38774
leaq 0x27207(%rip), %rdi     # 0x387a5
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 0x1120f
xorl %eax, %eax
jmp 0x1145c