// File: 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
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x90, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0xc6b4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl 0x1798(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpq $0x0, -0x10(%rbp)
jne 0x6a810
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x24(%rbp)
jmp 0x6a81d
movq -0x10(%rbp), %rax
movl 0x150(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x18(%rbp), %rax
movl 0xc67c(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x5, %eax
ja 0x6a89e
movq -0x30(%rbp), %rax
leaq 0x1443f(%rip), %rcx     # 0x7ec88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
movl $0xaa, 0xc(%rax)
jmp 0x6a89e
movq -0x20(%rbp), %rax
movl $0xb4, 0xc(%rax)
jmp 0x6a89e
movq -0x20(%rbp), %rax
movl $0xbe, 0xc(%rax)
jmp 0x6a89e
movq -0x20(%rbp), %rax
movl $0xab, 0xc(%rax)
jmp 0x6a89e
movq -0x20(%rbp), %rax
movl $0xb5, 0xc(%rax)
jmp 0x6a89e
movq -0x20(%rbp), %rax
movl $0xbf, 0xc(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x624(%rax)
jne 0x6a8b5
movl $0x1a4, %eax            # imm = 0x1A4
movl %eax, -0x34(%rbp)
jmp 0x6a8d2
movq -0x18(%rbp), %rax
movl 0x624(%rax), %edx
movl $0x190, %eax            # imm = 0x190
movl $0x19a, %ecx            # imm = 0x19A
cmpl $0x2, %edx
cmovel %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl 0x1690(%rax), %edx
movl $0xd2, %ecx
movl $0xc8, %eax
cmpl $0x1, %edx
cmovel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x668(%rax), %edx
movl $0x38e, %ecx            # imm = 0x38E
movl $0x384, %eax            # imm = 0x384
cmpl $0x0, %edx
cmovel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x670(%rax)
jne 0x6a935
movl $0x3a2, %eax            # imm = 0x3A2
movl %eax, -0x38(%rbp)
jmp 0x6a952
movq -0x18(%rbp), %rax
movl 0x670(%rax), %edx
movl $0x3b6, %eax            # imm = 0x3B6
movl $0x3ac, %ecx            # imm = 0x3AC
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x18(%rbp), %rax
cmpl $0x7, 0x179c(%rax)
jge 0x6a97e
movq -0x18(%rbp), %rax
imull $0xa, 0x179c(%rax), %eax
addl $0x212, %eax            # imm = 0x212
movl %eax, -0x3c(%rbp)
jmp 0x6a990
movq -0x18(%rbp), %rax
movl 0x179c(%rax), %eax
addl $0x248, %eax            # imm = 0x248
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x18(%rbp), %rax
movsd 0xd678(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd680(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd688(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd690(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd698(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd6a0(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd6a8(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd6b0(%rax), %xmm0
movb $0x1, %al
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x3d(%rbp)
jne 0x6aab8
jp 0x6aab8
movq -0x18(%rbp), %rax
movsd 0xd6b8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
setne %al
setp %cl
orb %cl, %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %dl
movl $0x1ea, %ecx            # imm = 0x1EA
movl $0x1ae, %eax            # imm = 0x1AE
testb $0x1, %dl
cmovnel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rax
movl 0xc6a8(%rax), %edx
movl $0x3de, %ecx            # imm = 0x3DE
movl $0x3d4, %eax            # imm = 0x3D4
cmpl $0x1, %edx
cmovel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x18(%rbp), %rax
cmpl $0x3, 0x5f8(%rax)
jne 0x6ab0a
movl $0x280, %eax            # imm = 0x280
movl %eax, -0x44(%rbp)
jmp 0x6ab27
movq -0x18(%rbp), %rax
movl 0x5f8(%rax), %edx
movl $0x263, %eax            # imm = 0x263
movl $0x262, %ecx            # imm = 0x262
cmpl $0x2, %edx
cmovel %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x30(%rax) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movl 0xc6c0(%rax), %edx
movl $0x3c0, %ecx            # imm = 0x3C0
movl $0x3ca, %eax            # imm = 0x3CA
cmpl $0x0, %edx
cmovel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x18(%rbp), %rax
movl 0x66c(%rax), %edx
movl $0x38f, %ecx            # imm = 0x38F
movl $0x385, %eax            # imm = 0x385
cmpl $0x0, %edx
cmovel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
movb 0x1e6d8(%rax), %al
andb $0x1, %al
movzbl %al, %edx
movl $0x50, %ecx
movl $0x46, %eax
cmpl $0x1, %edx
cmovel %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x3c(%rax)
xorl %eax, %eax
popq %rbp
retq
nopl (%rax,%rax)