// File: /workspace/github_cpp_makefile_star2_O3/sundale[P]gcode/rs274ngc/interp_internal.cc
// Function: Interp::enhance_block(block_struct*, setup_struct*)
int Interp::enhance_block(block_pointer block,   //!< pointer to a block to be checked 
                         setup_pointer settings)        //!< pointer to machine settings      
{
  int axis_flag;
  int ijk_flag;
  int polar_flag;
  int mode_zero_covets_axes;
  int mode0;
  int mode1;

  if(block->radius_flag || block->theta_flag) {
      // someday, tediously add polar support for other planes here:
      CHKS((!_readers[(int)'x'] || !_readers[(int)'y']), _("Cannot use polar coordinate on a machine lacking X or Y axes"));
      CHKS(((settings->plane != CANON_PLANE_XY)), _("Cannot use polar coordinate except in G17 plane"));
      CHKS(((block->x_flag)), _("Cannot specify both polar coordinate and X word"));
      CHKS(((block->y_flag)), _("Cannot specify both polar coordinate and Y word"));
  }

  axis_flag = ((block->x_flag == ON) || (block->y_flag == ON) ||
               (block->z_flag == ON) || (block->a_flag == ON) ||
               (block->b_flag == ON) || (block->c_flag == ON) ||
               (block->u_flag == ON) || (block->v_flag == ON) ||
               (block->w_flag == ON));
  polar_flag = (block->radius_flag == ON) || (block->theta_flag == ON);
  ijk_flag = ((block->i_flag == ON) || (block->j_flag == ON) ||
              (block->k_flag == ON));
  mode0 = block->g_modes[0];
  mode1 = block->g_modes[1];
  mode_zero_covets_axes =
    ((mode0 == G_10) || (mode0 == G_28) || (mode0 == G_30)
     || (mode0 == G_92));

  if (mode1 != -1) {
    if (mode1 == G_80) {
      CHKS(((polar_flag || axis_flag) && (!mode_zero_covets_axes)),
          NCE_CANNOT_USE_AXIS_VALUES_WITH_G80);
      CHKS((polar_flag && mode0 == G_92), _("Polar coordinates can only be used for motion"));
      CHKS(((!axis_flag) && (mode0 == G_92)), NCE_ALL_AXES_MISSING_WITH_G92);
    } else {
      CHKS(mode_zero_covets_axes,
          NCE_CANNOT_USE_TWO_G_CODES_THAT_BOTH_USE_AXIS_VALUES);
      CHKS(((!axis_flag && !polar_flag) && 
            mode1 != G_0 && mode1 != G_1 && 
            mode1 != G_2 && mode1 != G_3 && mode1 != G_5_2),
          NCE_ALL_AXES_MISSING_WITH_MOTION_CODE);
    }
    block->motion_to_be = mode1;
  } else if (mode_zero_covets_axes) {   /* other 3 can get by without axes but not G92 */
    CHKS((polar_flag && mode0 == G_92), _("Polar coordinates can only be used for motion"));
    CHKS(((!axis_flag) && (block->g_modes[0] == G_92)), NCE_ALL_AXES_MISSING_WITH_G92);
  } else if (axis_flag || polar_flag) {
    CHKS(((settings->motion_mode == -1)
         || (settings->motion_mode == G_80)) && (block->g_modes[8] != G_43_1),
        NCE_CANNOT_USE_AXIS_VALUES_WITHOUT_A_G_CODE_THAT_USES_THEM);
    if (block->g_modes[8] != G_43_1) {
       block->motion_to_be = settings->motion_mode;
    }
  } else if (!axis_flag && !polar_flag && ijk_flag && (settings->motion_mode == G_2 || settings->motion_mode == G_3)) {
    // this is a block like simply "i1" which should be accepted if we're in arc mode
      block->motion_to_be = settings->motion_mode;
  }
  CHKS((polar_flag && block->motion_to_be == -1), _("Polar coordinates can only be used for motion"));
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x2a0(%rsi), %edi
testl %edi, %edi
jne 0x25aa4
cmpl $0x0, 0x2b0(%rsi)
je 0x25b3c
cmpq $0x0, 0x788(%rbx)
je 0x25ad7
cmpq $0x0, 0x798(%rbx)
je 0x25ad7
cmpl $0x1, 0xc67c(%rdx)
jne 0x25ae0
movb 0x270(%rsi), %r8b
cmpb $0x1, %r8b
jne 0x25b45
leaq 0x1212f(%rip), %rdi     # 0x37c04
jmp 0x25ae7
leaq 0x120b9(%rip), %rdi     # 0x37b97
jmp 0x25ae7
leaq 0x120ed(%rip), %rdi     # 0x37bd4
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movl $0xc6d0, %edi           # imm = 0xC6D0
addq 0x1b45b(%rip), %rdi     # 0x40f60
leaq 0x1229d(%rip), %rsi     # 0x37da9
movl $0x50, %edx
callq 0xa8a0
movq 0x1b443(%rip), %rax     # 0x40f60
movw $0x0, 0xc71f(%rax)
movl $0x1, 0xd670(%rax)
movl $0x5, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movb 0x270(%rsi), %r8b
jmp 0x25b57
cmpb $0x1, 0x280(%rsi)
jne 0x25b57
leaq 0x120df(%rip), %rdi     # 0x37c34
jmp 0x25ae7
movb $0x1, %cl
movb $0x1, %al
testb $0x1, %r8b
jne 0x25b9c
cmpb $0x0, 0x280(%rsi)
jne 0x25b9c
cmpb $0x0, 0x290(%rsi)
jne 0x25b9c
cmpb $0x0, (%rsi)
jne 0x25b9c
cmpb $0x0, 0x10(%rsi)
jne 0x25b9c
cmpb $0x0, 0x20(%rsi)
jne 0x25b9c
cmpb $0x0, 0x244(%rsi)
jne 0x25b9c
cmpb $0x0, 0x250(%rsi)
jne 0x25b9c
movb 0x260(%rsi), %al
cmpl $0x1, %edi
je 0x25bab
cmpl $0x1, 0x2b0(%rsi)
sete %cl
movb $0x1, %r9b
cmpb $0x0, 0x198(%rsi)
jne 0x25bc7
cmpb $0x0, 0x1a8(%rsi)
jne 0x25bc7
movb 0x1b8(%rsi), %r9b
movl 0x150(%rsi), %r8d
movl 0x154(%rsi), %edi
xorl %r10d, %r10d
cmpl $0x12b, %r8d            # imm = 0x12B
jg 0x25bf1
cmpl $0x64, %r8d
je 0x25c06
cmpl $0x118, %r8d            # imm = 0x118
je 0x25c06
jmp 0x25c03
cmpl $0x12c, %r8d            # imm = 0x12C
je 0x25c06
cmpl $0x398, %r8d            # imm = 0x398
je 0x25c06
movb $0x1, %r10b
cmpl $-0x1, %edi
je 0x25c2f
cmpl $0x320, %edi            # imm = 0x320
jne 0x25c75
movl %ecx, %edx
orb %al, %dl
andb %r10b, %dl
cmpb $0x1, %dl
jne 0x25cc0
leaq 0x1203a(%rip), %rdi     # 0x37c64
jmp 0x25ae7
testb %r10b, %r10b
je 0x25ce6
orb %cl, %al
testb $0x1, %al
je 0x25d21
movl 0x1798(%rdx), %edi
cmpl $0x320, %edi            # imm = 0x320
je 0x25c59
cmpl $-0x1, %edi
jne 0x25d5f
cmpl $0x1af, 0x170(%rsi)     # imm = 0x1AF
je 0x25d3c
leaq 0x120af(%rip), %rdi     # 0x37d1f
jmp 0x25ae7
testb %r10b, %r10b
je 0x25d15
orb %cl, %al
testb $0x1, %al
jne 0x25d36
cmpl $0x1e, %edi
je 0x25d36
cmpl $0x34, %edi
je 0x25d36
cmpl $0x14, %edi
je 0x25d36
testl %edi, %edi
je 0x25d36
cmpl $0xa, %edi
je 0x25d36
leaq 0x12042(%rip), %rdi     # 0x37cfd
jmp 0x25ae7
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
movl %ecx, %r9d
xorb $0x1, %r9b
orb %dl, %r9b
je 0x25d53
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
orb %al, %dl
je 0x25d09
jmp 0x25d36
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
movl %ecx, %edi
xorb $0x1, %dil
orb %dl, %dil
je 0x25d53
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
orb %dl, %al
jne 0x25d3c
leaq 0x11fa2(%rip), %rdi     # 0x37cb2
jmp 0x25ae7
leaq 0x11fb0(%rip), %rdi     # 0x37ccc
jmp 0x25ae7
testb %r9b, %r9b
je 0x25d3c
movl 0x1798(%rdx), %edi
cmpl $0x1e, %edi
je 0x25d36
cmpl $0x14, %edi
jne 0x25d3c
movl %edi, 0x1d8(%rsi)
xorl %eax, %eax
testb %cl, %cl
je 0x25b35
cmpl $-0x1, 0x1d8(%rsi)
jne 0x25b35
leaq 0x11f2a(%rip), %rdi     # 0x37c84
jmp 0x25ae7
cmpl $0x1af, 0x170(%rsi)     # imm = 0x1AF
jne 0x25d36
jmp 0x25d3c
nop