// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_write.cc
// Function: Interp::write_g_codes(block_struct*, setup_struct*)
int Interp::write_g_codes(block_pointer block,   //!< pointer to a block of RS274/NGC instructions
                         setup_pointer settings)        //!< pointer to machine settings                 
{
  int *gez;

  gez = settings->active_g_codes;
  gez[0] = settings->sequence_number;
  gez[1] = settings->motion_mode;
  gez[2] = ((block == NULL) ? -1 : block->g_modes[0]);
  switch(settings->plane) {
  case CANON_PLANE_XY:
      gez[3] = G_17;
      break;
  case CANON_PLANE_XZ:
      gez[3] = G_18;
      break;
  case CANON_PLANE_YZ:
      gez[3] = G_19;
      break;
  case CANON_PLANE_UV:
      gez[3] = G_17_1;
      break;
  case CANON_PLANE_UW:
      gez[3] = G_18_1;
      break;
  case CANON_PLANE_VW:
      gez[3] = G_19_1;
      break;
  }
  gez[4] =
    (settings->cutter_comp_side == RIGHT) ? G_42 :
    (settings->cutter_comp_side == LEFT) ? G_41 : G_40;
  gez[5] = (settings->length_units == CANON_UNITS_INCHES) ? G_20 : G_21;
  gez[6] = (settings->distance_mode == MODE_ABSOLUTE) ? G_90 : G_91;
  gez[7] = (settings->feed_mode == INVERSE_TIME) ? G_93 :
	    (settings->feed_mode == UNITS_PER_MINUTE) ? G_94 : G_95;
  gez[8] =
    (settings->origin_index <
     7) ? (530 + (10 * settings->origin_index)) : (584 +
                                                   settings->origin_index);
  gez[9] = (settings->tool_offset.tran.x || settings->tool_offset.tran.y || settings->tool_offset.tran.z ||
            settings->tool_offset.a || settings->tool_offset.b || settings->tool_offset.c ||
            settings->tool_offset.u || settings->tool_offset.v || settings->tool_offset.w) ? G_43 : G_49;
  gez[10] = (settings->retract_mode == OLD_Z) ? G_98 : G_99;
  gez[11] =
    (settings->control_mode == CANON_CONTINUOUS) ? G_64 :
    (settings->control_mode == CANON_EXACT_PATH) ? G_61 : G_61_1;
  gez[12] = -1;
  gez[13] =
    (settings->spindle_mode == CONSTANT_RPM) ? G_97 : G_96;
  gez[14] = (settings->ijk_distance_mode == MODE_ABSOLUTE) ? G_90_1 : G_91_1;
  gez[15] = (settings->lathe_diameter_mode == ON) ? G_7 : G_8;
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl 0xc6b4(%rdx), %eax
movl %eax, 0x90(%rdx)
movl 0x1798(%rdx), %eax
movl %eax, 0x94(%rdx)
testq %rsi, %rsi
je 0x2870d
movl 0x150(%rsi), %eax
jmp 0x28712
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x98(%rdx)
movl 0xc67c(%rdx), %eax
decl %eax
cmpl $0x5, %eax
ja 0x28737
movl %eax, %eax
leaq 0xd66a(%rip), %rcx      # 0x35d98
movl (%rcx,%rax,4), %eax
movl %eax, 0x9c(%rdx)
movl 0x624(%rdx), %eax
cmpl $0x2, %eax
movl $0x19a, %ecx            # imm = 0x19A
movl $0x190, %esi            # imm = 0x190
cmovel %ecx, %esi
cmpl $0x1, %eax
movl $0x1a4, %eax            # imm = 0x1A4
cmovnel %esi, %eax
movl 0x670(%rdx), %ecx
movl %eax, 0xa0(%rdx)
cmpl $0x1, 0x1690(%rdx)
movl $0xc8, %eax
movl $0xd2, %esi
cmovel %eax, %esi
movl %esi, 0xa4(%rdx)
cmpl $0x0, 0x668(%rdx)
movl $0x384, %eax            # imm = 0x384
movl $0x38e, %esi            # imm = 0x38E
cmovel %eax, %esi
movl %esi, 0xa8(%rdx)
testl %ecx, %ecx
movl $0x3ac, %eax            # imm = 0x3AC
movl $0x3b6, %esi            # imm = 0x3B6
cmovel %eax, %esi
cmpl $0x1, %ecx
movl $0x3a2, %eax            # imm = 0x3A2
cmovnel %esi, %eax
movl %eax, 0xac(%rdx)
movl 0x179c(%rdx), %eax
imull $0xa, %eax, %ecx
addl $0x212, %ecx            # imm = 0x212
leal 0x248(%rax), %esi
cmpl $0x7, %eax
cmovll %ecx, %esi
movl %esi, 0xb0(%rdx)
movsd 0xd678(%rdx), %xmm1
movl $0x1ae, %eax            # imm = 0x1AE
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd680(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd688(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd690(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd698(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd6a0(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd6a8(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
movsd 0xd6b0(%rdx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x28887
jp 0x28887
ucomisd 0xd6b8(%rdx), %xmm0
setp %al
setne %cl
orb %al, %cl
movl $0x1ae, %ecx            # imm = 0x1AE
movl $0x1ea, %eax            # imm = 0x1EA
cmovnel %ecx, %eax
movl %eax, 0xb4(%rdx)
cmpl $0x1, 0xc6a8(%rdx)
movl $0x3d4, %eax            # imm = 0x3D4
movl $0x3de, %ecx            # imm = 0x3DE
cmovel %eax, %ecx
movl %ecx, 0xb8(%rdx)
movl 0x5f8(%rdx), %eax
xorl %ecx, %ecx
cmpl $0x2, %eax
sete %cl
xorl $0x263, %ecx            # imm = 0x263
cmpl $0x3, %eax
movl $0x280, %eax            # imm = 0x280
cmovnel %ecx, %eax
movl %eax, 0xbc(%rdx)
orl $-0x1, 0xc0(%rdx)
cmpl $0x0, 0xc6c0(%rdx)
movl $0x3ca, %eax            # imm = 0x3CA
movl $0x3c0, %ecx            # imm = 0x3C0
cmovel %eax, %ecx
movl %ecx, 0xc4(%rdx)
cmpl $0x0, 0x66c(%rdx)
movl $0x385, %eax            # imm = 0x385
movl $0x38f, %ecx            # imm = 0x38F
cmovel %eax, %ecx
movl %ecx, 0xc8(%rdx)
cmpb $0x0, 0x1e6d8(%rdx)
movl $0x46, %eax
movl $0x50, %ecx
cmovnel %eax, %ecx
movl %ecx, 0xcc(%rdx)
xorl %eax, %eax
popq %rbp
retq
nop