// File: /workspace/github_cpp_makefile_star2_O2/rofl0r[P]ascc/cs_parser.cpp
// Function: check_operator_valid_for_type(int*, int, int)
int check_operator_valid_for_type(int *vcpuOpPtr, int type1, int type2) {
  int NULL_TYPE = STYPE_POINTER | sym.nullSym;
  int vcpuOp = *vcpuOpPtr;

  int isError = 0;
  // it's allowed to add or subtract from a pointer to an integral type.
  if (is_int(type1) && (type2 & STYPE_POINTER)
     && (vcpuOp == SCMD_ADDREG || vcpuOp == SCMD_SUBREG)
     && is_integral_type(type2 & ~STYPE_POINTER))
      return 0;
  if ((type1 == sym.normalFloatSym) || (type2 == sym.normalFloatSym)) {
    // some operators not valid on floats
    int changeOpTo = vcpuOp;
    switch (vcpuOp) {
    case SCMD_ISEQUAL: // == and != same as integer versions
    case SCMD_NOTEQUAL:
      break;
    case SCMD_ADD:
      changeOpTo = SCMD_FADD;
      break;
    case SCMD_SUB:
      changeOpTo = SCMD_FSUB;
      break;
    case SCMD_ADDREG:
      changeOpTo = SCMD_FADDREG;
      break;
    case SCMD_SUBREG:
      changeOpTo = SCMD_FSUBREG;
      break;
    case SCMD_MULREG:
      changeOpTo = SCMD_FMULREG;
      break;
    case SCMD_DIVREG:
      changeOpTo = SCMD_FDIVREG;
      break;
    case SCMD_GREATER:
      changeOpTo = SCMD_FGREATER;
      break;
    case SCMD_LESSTHAN:
      changeOpTo = SCMD_FLESSTHAN;
      break;
    case SCMD_GTE:
      changeOpTo = SCMD_FGTE;
      break;
    case SCMD_LTE:
      changeOpTo = SCMD_FLTE;
      break;
    default:
      isError = 1;
    }
    vcpuOp = changeOpTo;
    *vcpuOpPtr = changeOpTo;
  }

  if (is_any_type_of_string(type1) && is_any_type_of_string(type2)) {
    if (vcpuOp == SCMD_ISEQUAL) {
      *vcpuOpPtr = SCMD_STRINGSEQUAL;
      return 0;
    }
    else if (vcpuOp == SCMD_NOTEQUAL) {
      *vcpuOpPtr = SCMD_STRINGSNOTEQ;
      return 0;
    }
  }

  if ((type1 & STYPE_POINTER) || (is_string(type1))) {
    isError = 1;
  }
  if (type2) {
    if ((type2 & STYPE_POINTER) || (is_string(type2))) {
      isError = 1;
    }
    if ((vcpuOp == SCMD_ISEQUAL) || (vcpuOp == SCMD_NOTEQUAL)) {
      // pointers can be compared to each other
      // (except strings)
      if (!is_string(type1))
        isError = 0;
    }
  }

  if (isError) {
    cc_error("Operator cannot be applied to this type");
    return -1;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
movl (%rdi), %r15d
leaq 0x1e89b(%rip), %r13     # 0x256f0
cmpl %esi, (%r13)
sete %al
movl %edx, %ecx
shrl $0x1e, %ecx
leal -0xb(%r15), %edx
cmpl $0x2, %edx
setb %dl
andb %cl, %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x6e89
movl %ebp, %edi
andl $0xbfffffff, %edi       # imm = 0xBFFFFFFF
callq 0x6f87
testl %eax, %eax
jne 0x6f76
movl 0x14(%r13), %eax
cmpl %ebx, %eax
setne %cl
cmpl %ebp, %eax
setne %al
xorl %r12d, %r12d
testb %al, %cl
jne 0x6ec9
movl %r15d, %eax
decl %eax
pushq $0x1
popq %r12
cmpl $0x13, %eax
ja 0x6ec6
movl $0xfcf03, %ecx          # imm = 0xFCF03
btl %eax, %ecx
jae 0x6ec6
movl %eax, %eax
leaq 0x11a1d(%rip), %rcx     # 0x188dc
movl (%rcx,%rax,4), %r15d
xorl %r12d, %r12d
movl %r15d, (%r14)
movl %ebx, %edx
andl $0x9fffffff, %edx       # imm = 0x9FFFFFFF
movl 0x10(%r13), %ecx
movl 0x20(%r13), %eax
cmpl %ecx, %edx
setne %sil
cmpl %eax, %edx
setne %dl
testb %dl, %sil
jne 0x6f14
movl %ebp, %edx
andl $0x9fffffff, %edx       # imm = 0x9FFFFFFF
cmpl %ecx, %edx
setne %cl
cmpl %eax, %edx
setne %al
testb %al, %cl
jne 0x6f14
cmpl $0x10, %r15d
je 0x6f6f
cmpl $0xf, %r15d
jne 0x6f14
movl $0x41, (%r14)
jmp 0x6f76
btl $0x1e, %ebx
jb 0x6f25
movl %ebx, %edi
callq 0x6dc1
testl %eax, %eax
je 0x6f29
pushq $0x1
popq %r12
testl %ebp, %ebp
je 0x6f57
btl $0x1e, %ebp
jb 0x6f3e
movl %ebp, %edi
callq 0x6dc1
testl %eax, %eax
je 0x6f42
pushq $0x1
popq %r12
addl $-0xf, %r15d
cmpl $0x1, %r15d
ja 0x6f57
movl %ebx, %edi
callq 0x6dc1
testl %eax, %eax
je 0x6f76
testl %r12d, %r12d
je 0x6f76
leaq 0x12093(%rip), %rdi     # 0x18ff6
xorl %eax, %eax
callq 0xf258
pushq $-0x1
popq %rax
jmp 0x6f78
movl $0x42, (%r14)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq