// File: /workspace/github_cpp_makefile_star2_O1/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 0x10ad4
leaq 0x27aec(%rip), %rdi     # 0x38568
callq 0xa1f0
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x334cb(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x26879(%rip), %rsi     # 0x37326
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %eax
jmp 0x10f0c
movq %rdx, %rbx
cmpl $0x239, %esi            # imm = 0x239
jg 0x10aff
cmpl $0x21c, %esi            # imm = 0x21C
je 0x10b3a
cmpl $0x226, %esi            # imm = 0x226
je 0x10b42
cmpl $0x230, %esi            # imm = 0x230
jne 0x10b4a
movl $0x3, %r15d
jmp 0x10b74
leal -0x24e(%rsi), %eax
cmpl $0x3, %eax
ja 0x10b22
leaq 0x264bf(%rip), %rcx     # 0x36fd0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x6, %r15d
jmp 0x10b74
cmpl $0x23a, %esi            # imm = 0x23A
je 0x10b56
cmpl $0x244, %esi            # imm = 0x244
jne 0x10b4a
movl $0x5, %r15d
jmp 0x10b74
movl $0x1, %r15d
jmp 0x10b74
movl $0x2, %r15d
jmp 0x10b74
leaq 0x27a5b(%rip), %rdi     # 0x385ac
jmp 0x10a7c
movl $0x4, %r15d
jmp 0x10b74
movl $0x8, %r15d
jmp 0x10b74
movl $0x9, %r15d
jmp 0x10b74
movl $0x7, %r15d
cmpl 0x179c(%rbx), %r15d
jne 0x10b8e
leaq 0x27a4a(%rip), %rdi     # 0x385ce
callq 0xb370
jmp 0x10f0a
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 0x33349(%rip), %r15     # 0x43f60
movl 0x1690(%r15), %eax
movsd 0x2629a(%rip), %xmm1    # 0x36ec0
movsd %xmm1, -0x40(%rbp)
cmpl $0x3, %eax
je 0x10c38
movsd 0x26268(%rip), %xmm1    # 0x36ea0
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x2627f(%rip), %xmm0    # 0x36ec8
movsd %xmm0, -0x38(%rbp)
cmpl $0x1, %eax
je 0x10c57
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 0x2623a(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x10c93
movsd 0x2620d(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x26224(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x10cad
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 0x261e4(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x10ce9
movsd 0x261b7(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x261ce(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x10d03
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 0x26128(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x10da5
movsd 0x260fb(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x26112(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x10dbf
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 0x260d5(%rip), %xmm1    # 0x36ec0
cmpl $0x3, %eax
je 0x10df8
movsd 0x260a8(%rip), %xmm1    # 0x36ea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x260bf(%rip), %xmm0    # 0x36ec8
cmpl $0x1, %eax
je 0x10e12
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 0x10e48
movsd 0x2605d(%rip), %xmm1    # 0x36ea0
movsd %xmm1, -0x40(%rbp)
movsd -0x30(%rbp), %xmm8
divsd %xmm0, %xmm8
cmpl $0x1, %eax
je 0x10e62
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