// File: /workspace/github_cpp_makefile_star2_O2/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 0x232fa
cmpl $0x0, 0x2b0(%rsi)
je 0x2338d
cmpq $0x0, 0x788(%rbx)
je 0x2332d
cmpq $0x0, 0x798(%rbx)
je 0x2332d
cmpl $0x1, 0xc67c(%rdx)
jne 0x23336
movb 0x270(%rsi), %r8b
cmpb $0x1, %r8b
jne 0x23396
leaq 0x108d9(%rip), %rdi     # 0x33c04
jmp 0x2333d
leaq 0x10863(%rip), %rdi     # 0x33b97
jmp 0x2333d
leaq 0x10897(%rip), %rdi     # 0x33bd4
callq 0xb220
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movl $0xc6d0, %edi           # imm = 0xC6D0
addq 0x19c05(%rip), %rdi     # 0x3cf60
leaq 0x10a47(%rip), %rsi     # 0x33da9
pushq $0x50
popq %rdx
callq 0xb940
movq 0x19bef(%rip), %rax     # 0x3cf60
andw $0x0, 0xc71f(%rax)
movl $0x1, 0xd670(%rax)
pushq $0x5
popq %rax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movb 0x270(%rsi), %r8b
jmp 0x233a8
cmpb $0x1, 0x280(%rsi)
jne 0x233a8
leaq 0x1088e(%rip), %rdi     # 0x33c34
jmp 0x2333d
movb $0x1, %cl
movb $0x1, %al
testb $0x1, %r8b
jne 0x233ed
cmpb $0x0, 0x280(%rsi)
jne 0x233ed
cmpb $0x0, 0x290(%rsi)
jne 0x233ed
cmpb $0x0, (%rsi)
jne 0x233ed
cmpb $0x0, 0x10(%rsi)
jne 0x233ed
cmpb $0x0, 0x20(%rsi)
jne 0x233ed
cmpb $0x0, 0x244(%rsi)
jne 0x233ed
cmpb $0x0, 0x250(%rsi)
jne 0x233ed
movb 0x260(%rsi), %al
cmpl $0x1, %edi
je 0x233fc
cmpl $0x1, 0x2b0(%rsi)
sete %cl
movb $0x1, %r9b
cmpb $0x0, 0x198(%rsi)
jne 0x23418
cmpb $0x0, 0x1a8(%rsi)
jne 0x23418
movb 0x1b8(%rsi), %r9b
movl 0x150(%rsi), %r8d
movl 0x154(%rsi), %edi
xorl %r10d, %r10d
cmpl $0x64, %r8d
je 0x2344c
cmpl $0x118, %r8d            # imm = 0x118
je 0x2344c
cmpl $0x12c, %r8d            # imm = 0x12C
je 0x2344c
cmpl $0x398, %r8d            # imm = 0x398
je 0x2344c
movb $0x1, %r10b
cmpl $-0x1, %edi
je 0x23475
cmpl $0x320, %edi            # imm = 0x320
jne 0x234bb
movl %ecx, %edx
orb %al, %dl
andb %r10b, %dl
cmpb $0x1, %dl
jne 0x23506
leaq 0x107f4(%rip), %rdi     # 0x33c64
jmp 0x2333d
testb %r10b, %r10b
je 0x2352c
orb %cl, %al
testb $0x1, %al
je 0x23567
movl 0x1798(%rdx), %edi
cmpl $0x320, %edi            # imm = 0x320
je 0x2349f
cmpl $-0x1, %edi
jne 0x235a5
cmpl $0x1af, 0x170(%rsi)     # imm = 0x1AF
je 0x23582
leaq 0x10869(%rip), %rdi     # 0x33d1f
jmp 0x2333d
testb %r10b, %r10b
je 0x2355b
orb %cl, %al
testb $0x1, %al
jne 0x2357c
cmpl $0x1e, %edi
je 0x2357c
cmpl $0x34, %edi
je 0x2357c
cmpl $0x14, %edi
je 0x2357c
testl %edi, %edi
je 0x2357c
cmpl $0xa, %edi
je 0x2357c
leaq 0x107fc(%rip), %rdi     # 0x33cfd
jmp 0x2333d
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
movl %ecx, %r9d
xorb $0x1, %r9b
orb %dl, %r9b
je 0x23599
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
orb %al, %dl
je 0x2354f
jmp 0x2357c
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
movl %ecx, %edi
xorb $0x1, %dil
orb %dl, %dil
je 0x23599
cmpl $0x398, %r8d            # imm = 0x398
setne %dl
orb %dl, %al
jne 0x23582
leaq 0x1075c(%rip), %rdi     # 0x33cb2
jmp 0x2333d
leaq 0x1076a(%rip), %rdi     # 0x33ccc
jmp 0x2333d
testb %r9b, %r9b
je 0x23582
movl 0x1798(%rdx), %edi
cmpl $0x1e, %edi
je 0x2357c
cmpl $0x14, %edi
jne 0x23582
movl %edi, 0x1d8(%rsi)
xorl %eax, %eax
testb %cl, %cl
je 0x23386
cmpl $-0x1, 0x1d8(%rsi)
jne 0x23386
leaq 0x106e4(%rip), %rdi     # 0x33c84
jmp 0x2333d
cmpl $0x1af, 0x170(%rsi)     # imm = 0x1AF
jne 0x2357c
jmp 0x23582
nop