// File: /workspace/github_cpp_makefile_star2_O3/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_coordinate_system(int, setup_struct*)
int Interp::convert_coordinate_system(int g_code,        //!< g_code called (must be one listed above)     
                                     setup_pointer settings)    //!< pointer to machine settings                  
{
  int origin;
  double *parameters;

  CHKS((settings->cutter_comp_side != OFF),
       (_("Cannot change coordinate systems with cutter radius compensation on")));
  parameters = settings->parameters;
  switch (g_code) {
  case 540:
    origin = 1;
    break;
  case 550:
    origin = 2;
    break;
  case 560:
    origin = 3;
    break;
  case 570:
    origin = 4;
    break;
  case 580:
    origin = 5;
    break;
  case 590:
    origin = 6;
    break;
  case 591:
    origin = 7;
    break;
  case 592:
    origin = 8;
    break;
  case 593:
    origin = 9;
    break;
  default:
    ERS(NCE_BUG_CODE_NOT_IN_RANGE_G54_TO_G593);
  }

  if (origin == settings->origin_index) {       /* already using this origin */
#ifdef DEBUG_EMC
    enqueue_COMMENT("interpreter: continuing to use same coordinate system");
#endif
    return INTERP_OK;
  }

  // move the current point into the new system
  find_current_in_system(settings, origin,
                         &settings->current_x, &settings->current_y, &settings->current_z,
                         &settings->AA_current, &settings->BB_current, &settings->CC_current,
                         &settings->u_current, &settings->v_current, &settings->w_current);

  // remember that this is new system
  settings->origin_index = origin;
  parameters[5220] = (double) origin;

  // load the origin of the newly-selected system
  settings->origin_offset_x = USER_TO_PROGRAM_LEN(parameters[5201 + (origin * 20)]);
  settings->origin_offset_y = USER_TO_PROGRAM_LEN(parameters[5202 + (origin * 20)]);
  settings->origin_offset_z = USER_TO_PROGRAM_LEN(parameters[5203 + (origin * 20)]);
  settings->AA_origin_offset = USER_TO_PROGRAM_ANG(parameters[5204 + (origin * 20)]);
  settings->BB_origin_offset = USER_TO_PROGRAM_ANG(parameters[5205 + (origin * 20)]);
  settings->CC_origin_offset = USER_TO_PROGRAM_ANG(parameters[5206 + (origin * 20)]);
  settings->u_origin_offset = USER_TO_PROGRAM_LEN(parameters[5207 + (origin * 20)]);
  settings->v_origin_offset = USER_TO_PROGRAM_LEN(parameters[5208 + (origin * 20)]);
  settings->w_origin_offset = USER_TO_PROGRAM_LEN(parameters[5209 + (origin * 20)]);
  settings->rotation_xy = parameters[5210 + (origin * 20)];

  SET_ORIGIN_OFFSETS(settings->origin_offset_x + settings->axis_offset_x,
                     settings->origin_offset_y + settings->axis_offset_y,
                     settings->origin_offset_z + settings->axis_offset_z,
                     settings->AA_origin_offset + settings->AA_axis_offset,
                     settings->BB_origin_offset + settings->BB_axis_offset,
                     settings->CC_origin_offset + settings->CC_axis_offset,
                     settings->u_origin_offset + settings->u_axis_offset,
                     settings->v_origin_offset + settings->v_axis_offset,
                     settings->w_origin_offset + settings->w_axis_offset);
  SET_XY_ROTATION(settings->rotation_xy);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
cmpl $0x0, 0x624(%rdx)
je 0x1072e
leaq 0x24e88(%rip), %rdi     # 0x35568
callq 0xa1f0
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x30867(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x23c1f(%rip), %rsi     # 0x34326
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %eax
jmp 0x10b66
movq %rdx, %rbx
cmpl $0x239, %esi            # imm = 0x239
jg 0x10759
cmpl $0x21c, %esi            # imm = 0x21C
je 0x10794
cmpl $0x226, %esi            # imm = 0x226
je 0x1079c
cmpl $0x230, %esi            # imm = 0x230
jne 0x107a4
movl $0x3, %r15d
jmp 0x107ce
leal -0x24e(%rsi), %eax
cmpl $0x3, %eax
ja 0x1077c
leaq 0x23865(%rip), %rcx     # 0x33fd0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, %r15d
jmp 0x107ce
cmpl $0x23a, %esi            # imm = 0x23A
je 0x107b0
cmpl $0x244, %esi            # imm = 0x244
jne 0x107a4
movl $0x5, %r15d
jmp 0x107ce
movl $0x1, %r15d
jmp 0x107ce
movl $0x2, %r15d
jmp 0x107ce
leaq 0x24e01(%rip), %rdi     # 0x355ac
jmp 0x106e0
movl $0x4, %r15d
jmp 0x107ce
movl $0x8, %r15d
jmp 0x107ce
movl $0x9, %r15d
jmp 0x107ce
movl $0x7, %r15d
cmpl 0x179c(%rbx), %r15d
jne 0x107e8
leaq 0x24df0(%rip), %rdi     # 0x355ce
callq 0xb370
jmp 0x10b64
leaq 0x600(%rbx), %rcx
leaq 0x608(%rbx), %r8
leaq 0x610(%rbx), %r9
leaq 0x8(%rbx), %rax
movq %rax, -0x38(%rbp)
leaq 0x20(%rbx), %r10
leaq 0x38(%rbx), %r11
leaq 0x50(%rbx), %r12
leaq 0x68(%rbx), %r13
leaq 0x80(%rbx), %rax
movq %r14, %rdi
movq %rbx, %rsi
movl %r15d, %edx
pushq %rax
pushq %r13
pushq %r12
pushq %r11
pushq %r10
pushq -0x38(%rbp)
callq 0xb670
addq $0x30, %rsp
movl %r15d, 0x179c(%rbx)
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0xbae0(%rbx)
shll $0x5, %r15d
leal (%r15,%r15,4), %r14d
movsd 0xba48(%rbx,%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xa990
movq 0x306ef(%rip), %r15     # 0x40f60
movl 0x1690(%r15), %eax
movsd 0x23640(%rip), %xmm1    # 0x33ec0
movsd %xmm1, -0x40(%rbp)
cmpl $0x3, %eax
je 0x10892
movsd 0x2360e(%rip), %xmm1    # 0x33ea0
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x23625(%rip), %xmm0    # 0x33ec8
movsd %xmm0, -0x38(%rbp)
cmpl $0x1, %eax
je 0x108b1
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17a0(%rbx)
movsd 0xba50(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
movsd 0x235e0(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x108ed
movsd 0x235b3(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x235ca(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x10907
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17a8(%rbx)
movsd 0xba58(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
movsd 0x2358a(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x10943
movsd 0x2355d(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x23574(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x1095d
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17b0(%rbx)
movsd 0xba60(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xaf60
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rbx)
movsd 0xba68(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xaf60
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rbx)
movsd 0xba70(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xaf60
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rbx)
movsd 0xba78(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
movsd 0x234ce(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x109ff
movsd 0x234a1(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x234b8(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x10a19
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x58(%rbx)
movsd 0xba80(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
movsd 0x2347b(%rip), %xmm1    # 0x33ec0
cmpl $0x3, %eax
je 0x10a52
movsd 0x2344e(%rip), %xmm1    # 0x33ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x23465(%rip), %xmm0    # 0x33ec8
cmpl $0x1, %eax
je 0x10a6c
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x70(%rbx)
movsd 0xba88(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xa990
movl 0x1690(%r15), %eax
cmpl $0x3, %eax
je 0x10aa2
movsd 0x23403(%rip), %xmm1    # 0x33ea0
movsd %xmm1, -0x40(%rbp)
movsd -0x30(%rbp), %xmm8
divsd %xmm0, %xmm8
cmpl $0x1, %eax
je 0x10abc
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
divsd -0x38(%rbp), %xmm8
movsd %xmm8, 0x88(%rbx)
movsd 0xba90(%rbx,%r14), %xmm0
movsd %xmm0, 0x17b8(%rbx)
movsd 0x17a0(%rbx), %xmm0
addsd 0x118(%rbx), %xmm0
movsd 0x17a8(%rbx), %xmm1
addsd 0x120(%rbx), %xmm1
movsd 0x17b0(%rbx), %xmm2
addsd 0x128(%rbx), %xmm2
movsd 0x10(%rbx), %xmm3
movsd 0x28(%rbx), %xmm4
addsd (%rbx), %xmm3
addsd 0x18(%rbx), %xmm4
movsd 0x40(%rbx), %xmm5
addsd 0x30(%rbx), %xmm5
movsd 0x58(%rbx), %xmm6
addsd 0x48(%rbx), %xmm6
movsd 0x70(%rbx), %xmm7
addsd 0x60(%rbx), %xmm7
addsd 0x78(%rbx), %xmm8
subq $0x10, %rsp
movsd %xmm8, (%rsp)
callq 0xa510
addq $0x10, %rsp
movsd 0x17b8(%rbx), %xmm0
callq 0xae60
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop