// File: /workspace/github_cpp_makefile_star2_O2/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 0x113fb
leaq 0x201c0(%rip), %rdi     # 0x31572
callq 0xb220
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2bb95(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1ef4d(%rip), %rsi     # 0x30326
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %rax
jmp 0x117fe
movq %rdx, %rbx
leal -0x24e(%rsi), %eax
cmpl $0x3, %eax
jbe 0x11439
cmpl $0x21c, %esi            # imm = 0x21C
je 0x11455
cmpl $0x244, %esi            # imm = 0x244
je 0x11465
cmpl $0x230, %esi            # imm = 0x230
je 0x11461
cmpl $0x23a, %esi            # imm = 0x23A
je 0x1144d
cmpl $0x226, %esi            # imm = 0x226
jne 0x1180d
pushq $0x2
jmp 0x11467
leaq 0x1eb90(%rip), %rcx     # 0x2ffd0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x6
jmp 0x11467
pushq $0x4
jmp 0x11467
pushq $0x8
jmp 0x11467
pushq $0x1
jmp 0x11467
pushq $0x9
jmp 0x11467
pushq $0x7
jmp 0x11467
pushq $0x3
jmp 0x11467
pushq $0x5
popq %r15
cmpl 0x179c(%rbx), %r15d
jne 0x11483
leaq 0x2015f(%rip), %rdi     # 0x315d8
callq 0xc4d0
jmp 0x117fc
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 0xc7e0
addq $0x30, %rsp
cvtsi2sd %r15d, %xmm0
movl %r15d, 0x179c(%rbx)
movsd %xmm0, 0xbae0(%rbx)
imull $0xa0, %r15d, %r14d
movsd 0xba48(%rbx,%r14), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xba40
movq 0x2ba55(%rip), %r15     # 0x3cf60
movl 0x1690(%r15), %eax
movsd 0x1e9a6(%rip), %xmm1    # 0x2fec0
movsd %xmm1, -0x40(%rbp)
cmpl $0x3, %eax
je 0x1152c
movsd 0x1e974(%rip), %xmm1    # 0x2fea0
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1e98b(%rip), %xmm0    # 0x2fec8
movsd %xmm0, -0x38(%rbp)
cmpl $0x1, %eax
je 0x1154b
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17a0(%rbx)
movsd 0xba50(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movl 0x1690(%r15), %eax
movsd 0x1e946(%rip), %xmm1    # 0x2fec0
cmpl $0x3, %eax
je 0x11587
movsd 0x1e919(%rip), %xmm1    # 0x2fea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1e930(%rip), %xmm0    # 0x2fec8
cmpl $0x1, %eax
je 0x115a1
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17a8(%rbx)
movsd 0xba58(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movl 0x1690(%r15), %eax
movsd 0x1e8f0(%rip), %xmm1    # 0x2fec0
cmpl $0x3, %eax
je 0x115dd
movsd 0x1e8c3(%rip), %xmm1    # 0x2fea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1e8da(%rip), %xmm0    # 0x2fec8
cmpl $0x1, %eax
je 0x115f7
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x17b0(%rbx)
movsd 0xba60(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xc090
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rbx)
movsd 0xba68(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xc090
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rbx)
movsd 0xba70(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xc090
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rbx)
movsd 0xba78(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movl 0x1690(%r15), %eax
movsd 0x1e834(%rip), %xmm1    # 0x2fec0
cmpl $0x3, %eax
je 0x11699
movsd 0x1e807(%rip), %xmm1    # 0x2fea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1e81e(%rip), %xmm0    # 0x2fec8
cmpl $0x1, %eax
je 0x116b3
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x58(%rbx)
movsd 0xba80(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movl 0x1690(%r15), %eax
movsd 0x1e7e1(%rip), %xmm1    # 0x2fec0
cmpl $0x3, %eax
je 0x116ec
movsd 0x1e7b4(%rip), %xmm1    # 0x2fea0
movsd -0x30(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd 0x1e7cb(%rip), %xmm0    # 0x2fec8
cmpl $0x1, %eax
je 0x11706
movapd %xmm1, %xmm0
divsd %xmm0, %xmm2
movsd %xmm2, 0x70(%rbx)
movsd 0xba88(%rbx,%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movl 0x1690(%r15), %eax
cmpl $0x3, %eax
je 0x1173c
movsd 0x1e769(%rip), %xmm1    # 0x2fea0
movsd %xmm1, -0x40(%rbp)
movsd -0x30(%rbp), %xmm8
divsd %xmm0, %xmm8
cmpl $0x1, %eax
je 0x11756
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 0xb550
popq %rax
popq %rcx
movsd 0x17b8(%rbx), %xmm0
callq 0xbf80
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1fda2(%rip), %rdi     # 0x315b6
jmp 0x113b2
nop