private Constant simulateMath(SsaInsn insn, int resultType) {
    Insn ropInsn = insn.getOriginalRopInsn();
    int opcode = insn.getOpcode().getOpcode();
    RegisterSpecList sources = insn.getSources();
    int regA = sources.get(0).getReg();
    Constant cA;
    Constant cB;

    if (latticeValues[regA] != CONSTANT) {
      cA = null;
    } else {
      cA = latticeConstants[regA];
    }

    if (sources.size() == 1) {
      CstInsn cstInsn = (CstInsn) ropInsn;
      cB = cstInsn.getConstant();
    } else {
        /* sources.size() == 2 */
      int regB = sources.get(1).getReg();
      if (latticeValues[regB] != CONSTANT) {
        cB = null;
      } else {
        cB = latticeConstants[regB];
      }
    }

    if (cA == null || cB == null) {
      // TODO handle a constant of 0 with MUL or AND
      return null;
    }

    switch (resultType) {
      case Type.BT_INT:
        int vR;
        boolean skip = false;

        int vA = ((CstInteger) cA).getValue();
        int vB = ((CstInteger) cB).getValue();

        switch (opcode) {
          case RegOps.ADD:
            vR = vA + vB;
            break;
          case RegOps.SUB:
            // 1 source for reverse sub, 2 sources for regular sub
            if (sources.size() == 1) {
              vR = vB - vA;
            } else {
              vR = vA - vB;
            }
            break;
          case RegOps.MUL:
            vR = vA * vB;
            break;
          case RegOps.DIV:
            if (vB == 0) {
              skip = true;
              vR = 0; // just to hide a warning
            } else {
              vR = vA / vB;
            }
            break;
          case RegOps.AND:
            vR = vA & vB;
            break;
          case RegOps.OR:
            vR = vA | vB;
            break;
          case RegOps.XOR:
            vR = vA ^ vB;
            break;
          case RegOps.SHL:
            vR = vA << vB;
            break;
          case RegOps.SHR:
            vR = vA >> vB;
            break;
          case RegOps.USHR:
            vR = vA >>> vB;
            break;
          case RegOps.REM:
            if (vB == 0) {
              skip = true;
              vR = 0; // just to hide a warning
            } else {
              vR = vA % vB;
            }
            break;
          default:
            throw new RuntimeException("Unexpected op");
        }

        return skip ? null : CstInteger.make(vR);

      default:
        // not yet supported
        return null;
    }
  }
Simulates math insns, if possible.

@param insn non-null insn to simulate
@param resultType basic type of the result
@return constant result or null if not simulatable.
android/android_framework/dex-maker/src/main/java/com/android/dx/ssa/SCCP.java