// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_length_units(int, setup_struct*)
int Interp::convert_length_units(int g_code,     //!< g_code being executed (must be G_20 or G_21)
                                setup_pointer settings) //!< pointer to machine settings                 
{
  if (g_code == G_20) {
    USE_LENGTH_UNITS(CANON_UNITS_INCHES);
    if (settings->length_units != CANON_UNITS_INCHES) {
      settings->length_units = CANON_UNITS_INCHES;
      settings->current_x = (settings->current_x * INCH_PER_MM);
      settings->current_y = (settings->current_y * INCH_PER_MM);
      settings->current_z = (settings->current_z * INCH_PER_MM);
      settings->program_x = (settings->program_x * INCH_PER_MM);
      settings->program_y = (settings->program_y * INCH_PER_MM);
      settings->program_z = (settings->program_z * INCH_PER_MM);
      qc_scale(INCH_PER_MM);
      settings->cutter_comp_radius *= INCH_PER_MM;
      settings->axis_offset_x = (settings->axis_offset_x * INCH_PER_MM);
      settings->axis_offset_y = (settings->axis_offset_y * INCH_PER_MM);
      settings->axis_offset_z = (settings->axis_offset_z * INCH_PER_MM);
      settings->origin_offset_x = (settings->origin_offset_x * INCH_PER_MM);
      settings->origin_offset_y = (settings->origin_offset_y * INCH_PER_MM);
      settings->origin_offset_z = (settings->origin_offset_z * INCH_PER_MM);

      settings->u_current = (settings->u_current * INCH_PER_MM);
      settings->v_current = (settings->v_current * INCH_PER_MM);
      settings->w_current = (settings->w_current * INCH_PER_MM);
      settings->u_axis_offset = (settings->u_axis_offset * INCH_PER_MM);
      settings->v_axis_offset = (settings->v_axis_offset * INCH_PER_MM);
      settings->w_axis_offset = (settings->w_axis_offset * INCH_PER_MM);
      settings->u_origin_offset = (settings->u_origin_offset * INCH_PER_MM);
      settings->v_origin_offset = (settings->v_origin_offset * INCH_PER_MM);
      settings->w_origin_offset = (settings->w_origin_offset * INCH_PER_MM);

      settings->tool_offset.tran.x = GET_EXTERNAL_TOOL_LENGTH_XOFFSET();
      settings->tool_offset.tran.y = GET_EXTERNAL_TOOL_LENGTH_YOFFSET();
      settings->tool_offset.tran.z = GET_EXTERNAL_TOOL_LENGTH_ZOFFSET();
      settings->tool_offset.a = GET_EXTERNAL_TOOL_LENGTH_AOFFSET();
      settings->tool_offset.b = GET_EXTERNAL_TOOL_LENGTH_BOFFSET();
      settings->tool_offset.c = GET_EXTERNAL_TOOL_LENGTH_COFFSET();
      settings->tool_offset.u = GET_EXTERNAL_TOOL_LENGTH_UOFFSET();
      settings->tool_offset.v = GET_EXTERNAL_TOOL_LENGTH_VOFFSET();
      settings->tool_offset.w = GET_EXTERNAL_TOOL_LENGTH_WOFFSET();
      settings->feed_rate = GET_EXTERNAL_FEED_RATE();
    }
  } else if (g_code == G_21) {
    USE_LENGTH_UNITS(CANON_UNITS_MM);
    if (settings->length_units != CANON_UNITS_MM) {
      settings->length_units = CANON_UNITS_MM;
      settings->current_x = (settings->current_x * MM_PER_INCH);
      settings->current_y = (settings->current_y * MM_PER_INCH);
      settings->current_z = (settings->current_z * MM_PER_INCH);
      settings->program_x = (settings->program_x * MM_PER_INCH);
      settings->program_y = (settings->program_y * MM_PER_INCH);
      settings->program_z = (settings->program_z * MM_PER_INCH);
      qc_scale(MM_PER_INCH);
      settings->cutter_comp_radius *= MM_PER_INCH;
      settings->axis_offset_x = (settings->axis_offset_x * MM_PER_INCH);
      settings->axis_offset_y = (settings->axis_offset_y * MM_PER_INCH);
      settings->axis_offset_z = (settings->axis_offset_z * MM_PER_INCH);
      settings->origin_offset_x = (settings->origin_offset_x * MM_PER_INCH);
      settings->origin_offset_y = (settings->origin_offset_y * MM_PER_INCH);
      settings->origin_offset_z = (settings->origin_offset_z * MM_PER_INCH);

      settings->u_current = (settings->u_current * MM_PER_INCH);
      settings->v_current = (settings->v_current * MM_PER_INCH);
      settings->w_current = (settings->w_current * MM_PER_INCH);
      settings->u_axis_offset = (settings->u_axis_offset * MM_PER_INCH);
      settings->v_axis_offset = (settings->v_axis_offset * MM_PER_INCH);
      settings->w_axis_offset = (settings->w_axis_offset * MM_PER_INCH);
      settings->u_origin_offset = (settings->u_origin_offset * MM_PER_INCH);
      settings->v_origin_offset = (settings->v_origin_offset * MM_PER_INCH);
      settings->w_origin_offset = (settings->w_origin_offset * MM_PER_INCH);

      settings->tool_offset.tran.x = GET_EXTERNAL_TOOL_LENGTH_XOFFSET();
      settings->tool_offset.tran.y = GET_EXTERNAL_TOOL_LENGTH_YOFFSET();
      settings->tool_offset.tran.z = GET_EXTERNAL_TOOL_LENGTH_ZOFFSET();
      settings->tool_offset.a = GET_EXTERNAL_TOOL_LENGTH_AOFFSET();
      settings->tool_offset.b = GET_EXTERNAL_TOOL_LENGTH_BOFFSET();
      settings->tool_offset.c = GET_EXTERNAL_TOOL_LENGTH_COFFSET();
      settings->tool_offset.u = GET_EXTERNAL_TOOL_LENGTH_UOFFSET();
      settings->tool_offset.v = GET_EXTERNAL_TOOL_LENGTH_VOFFSET();
      settings->tool_offset.w = GET_EXTERNAL_TOOL_LENGTH_WOFFSET();
      settings->feed_rate = GET_EXTERNAL_FEED_RATE();
    }
  } else
    ERS(NCE_BUG_CODE_NOT_G20_OR_G21);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rdx, %rbx
cmpl $0xd2, %esi
je 0x1266a
cmpl $0xc8, %esi
jne 0x128af
pushq $0x1
popq %rdi
callq 0xb910
xorl %r14d, %r14d
cmpl $0x1, 0x1690(%rbx)
je 0x128fe
movl $0x1, 0x1690(%rbx)
movsd 0x1d910(%rip), %xmm0    # 0x2fee8
movsd 0x600(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x600(%rbx)
movsd 0x608(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x608(%rbx)
movsd 0x610(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x610(%rbx)
movsd 0xc690(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0xc690(%rbx)
movsd 0xc698(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0xc698(%rbx)
movsd 0xc6a0(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0xc6a0(%rbx)
callq 0xc1a0
movsd 0x618(%rbx), %xmm0
movsd 0x1d883(%rip), %xmm1    # 0x2fee8
jmp 0x12721
pushq $0x2
popq %rdi
callq 0xb910
xorl %r14d, %r14d
cmpl $0x2, 0x1690(%rbx)
je 0x128fe
movl $0x2, 0x1690(%rbx)
movsd 0x1d834(%rip), %xmm0    # 0x2fec8
movsd 0x600(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x600(%rbx)
movsd 0x608(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x608(%rbx)
movsd 0x610(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x610(%rbx)
movsd 0xc690(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0xc690(%rbx)
movsd 0xc698(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0xc698(%rbx)
movsd 0xc6a0(%rbx), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0xc6a0(%rbx)
callq 0xc1a0
movsd 0x618(%rbx), %xmm0
movsd 0x1d7a7(%rip), %xmm1    # 0x2fec8
mulsd %xmm1, %xmm0
movsd %xmm0, 0x618(%rbx)
movsd 0x118(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rbx)
movsd 0x120(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x120(%rbx)
movsd 0x128(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rbx)
movsd 0x17a0(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x17a0(%rbx)
movsd 0x17a8(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x17a8(%rbx)
movsd 0x17b0(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x17b0(%rbx)
movsd 0x50(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rbx)
movsd 0x68(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x68(%rbx)
movsd 0x80(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rbx)
movsd 0x48(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x48(%rbx)
movsd 0x60(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rbx)
movsd 0x78(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rbx)
movsd 0x58(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rbx)
movsd 0x70(%rbx), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rbx)
mulsd 0x88(%rbx), %xmm1
movsd %xmm1, 0x88(%rbx)
callq 0xb080
movsd %xmm0, 0xd678(%rbx)
callq 0xc1f0
movsd %xmm0, 0xd680(%rbx)
callq 0xc590
movsd %xmm0, 0xd688(%rbx)
callq 0xc420
movsd %xmm0, 0xd690(%rbx)
callq 0xb090
movsd %xmm0, 0xd698(%rbx)
callq 0xb770
movsd %xmm0, 0xd6a0(%rbx)
callq 0xb0d0
movsd %xmm0, 0xd6a8(%rbx)
callq 0xb710
movsd %xmm0, 0xd6b0(%rbx)
callq 0xc330
movsd %xmm0, 0xd6b8(%rbx)
callq 0xbda0
movsd %xmm0, 0x678(%rbx)
jmp 0x128fe
movq %rdi, %r14
leaq 0x1f1d4(%rip), %rdi     # 0x31a8d
callq 0xb220
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2a68e(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1dd70(%rip), %rsi     # 0x30650
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r14
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq