// File: /workspace/github_cpp_makefile_star2_O1/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 0x12406
cmpl $0xc8, %esi
jne 0x1264d
movl $0x1, %edi
callq 0xa880
xorl %r14d, %r14d
cmpl $0x1, 0x1690(%rbx)
je 0x126ab
movl $0x1, 0x1690(%rbx)
movsd 0x24b6c(%rip), %xmm0    # 0x36ee0
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 0xb060
movsd 0x618(%rbx), %xmm0
movsd 0x24adf(%rip), %xmm1    # 0x36ee0
jmp 0x124bf
movl $0x2, %edi
callq 0xa880
xorl %r14d, %r14d
cmpl $0x2, 0x1690(%rbx)
je 0x126ab
movl $0x2, 0x1690(%rbx)
movsd 0x24a96(%rip), %xmm0    # 0x36ec8
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 0xb060
movsd 0x618(%rbx), %xmm0
movsd 0x24a09(%rip), %xmm1    # 0x36ec8
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 0xa070
movsd %xmm0, 0xd678(%rbx)
callq 0xb0b0
movsd %xmm0, 0xd680(%rbx)
callq 0xb420
movsd %xmm0, 0xd688(%rbx)
callq 0xb2c0
movsd %xmm0, 0xd690(%rbx)
callq 0xa080
movsd %xmm0, 0xd698(%rbx)
callq 0xa720
movsd %xmm0, 0xd6a0(%rbx)
callq 0xa0c0
movsd %xmm0, 0xd6a8(%rbx)
callq 0xa6c0
movsd %xmm0, 0xd6b0(%rbx)
callq 0xb1d0
movsd %xmm0, 0xd6b8(%rbx)
callq 0xacb0
movsd %xmm0, 0x678(%rbx)
jmp 0x126ab
movq %rdi, %r14
leaq 0x2642c(%rip), %rdi     # 0x38a83
callq 0xa1f0
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x318f0(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x24fc8(%rip), %rsi     # 0x37650
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r14d
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq
nop