// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
pushq %rax
movl %edx, %ebp
movl %esi, %ebx
movl (%rdi), %r14d
leaq 0x1e17b(%rip), %rcx     # 0x256e0
movl (%rcx), %edx
cmpl %esi, %edx
sete %al
movl %ebp, %esi
shrl $0x1e, %esi
leal -0xb(%r14), %r8d
cmpl $0x2, %r8d
setb %r8b
andb %sil, %r8b
andb %al, %r8b
cmpb $0x1, %r8b
jne 0x75b6
movl %ebp, %esi
andl $0xbfffffff, %esi       # imm = 0xBFFFFFFF
xorl %eax, %eax
cmpl %esi, %edx
je 0x76aa
cmpl %esi, 0x8(%rcx)
je 0x76aa
cmpl %esi, 0x4(%rcx)
je 0x76aa
cmpl %esi, 0xc(%rcx)
je 0x76aa
movl 0x14(%rcx), %eax
cmpl %ebx, %eax
setne %dl
cmpl %ebp, %eax
setne %al
xorl %r15d, %r15d
testb %al, %dl
jne 0x75f7
movl %r14d, %eax
decl %eax
movl $0x1, %r15d
cmpl $0x13, %eax
ja 0x75f4
movl $0xfcf03, %edx          # imm = 0xFCF03
btl %eax, %edx
jae 0x75f4
movl %eax, %eax
leaq 0x13333(%rip), %rdx     # 0x1a920
movl (%rdx,%rax,4), %r14d
xorl %r15d, %r15d
movl %r14d, (%rdi)
movl %ebx, %esi
andl $0x9fffffff, %esi       # imm = 0x9FFFFFFF
movl 0x10(%rcx), %edx
movl 0x20(%rcx), %eax
cmpl %edx, %esi
setne %cl
cmpl %eax, %esi
setne %sil
testb %sil, %cl
jne 0x763f
movl %ebp, %ecx
andl $0x9fffffff, %ecx       # imm = 0x9FFFFFFF
cmpl %edx, %ecx
setne %dl
cmpl %eax, %ecx
setne %al
testb %al, %dl
jne 0x763f
cmpl $0x10, %r14d
je 0x76a2
cmpl $0xf, %r14d
jne 0x763f
movl $0x41, (%rdi)
jmp 0x76a8
btl $0x1e, %ebx
jb 0x7650
movl %ebx, %edi
callq 0x74d6
testl %eax, %eax
je 0x7656
movl $0x1, %r15d
testl %ebp, %ebp
je 0x7688
btl $0x1e, %ebp
jb 0x766b
movl %ebp, %edi
callq 0x74d6
testl %eax, %eax
je 0x7671
movl $0x1, %r15d
addl $-0xf, %r14d
cmpl $0x1, %r14d
ja 0x7688
movl %ebx, %edi
callq 0x74d6
testl %eax, %eax
cmovel %eax, %r15d
testl %r15d, %r15d
je 0x76a8
leaq 0x13982(%rip), %rdi     # 0x1b016
xorl %eax, %eax
callq 0x10418
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x76aa
movl $0x42, (%rdi)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq