public static Exprent getLastExprentWhen(Exprent base, boolean ifTrue, boolean onlyIfTrue) {
    switch (base.type){
      case FUNCTION: {
        FunctionExprent func = (FunctionExprent) base;
        switch (func.getFuncType()) {
          case BOOLEAN_AND: {
            if (ifTrue) {
              // when `&&` returns true, the second exprent had to run and return true
              return getLastExprentWhen(func.getLstOperands().get(1), true, onlyIfTrue);
            }
            // when `&&` returns false, either could have returned false, so we go to
            // the default case of returning ourselves
            break;
          }
          case BOOLEAN_OR: {
            if (!ifTrue) {
              // when `||` returns false, the second exprent had to run and return false
              return getLastExprentWhen(func.getLstOperands().get(1), false, onlyIfTrue);
            }
            // when `||` returns true, either could have returned true, so we go to
            // the default case of returning ourselves
            break;
          }
          case BOOL_NOT: {
            // when `!` returns true, the exprent had to return false
            // when `!` returns false, the exprent had to return true
            return getLastExprentWhen(func.getLstOperands().get(0), !ifTrue, onlyIfTrue);
          }

          // TEMPORARY
          // This is here because things like `a instanceof B` are initially decompiled as
          // `(a instanceof B) != false`, and this is only cleaned up at the end by
          // secondaryFunctionsHelper
          case EQ: {
            Exprent rhs = func.getLstOperands().get(1);
            if (rhs.type == Exprent.Type.CONST) {
              ConstExprent constExprent = (ConstExprent) rhs;
              if (constExprent.getConstType() == VarType.VARTYPE_BOOLEAN) {
                if (constExprent.getIntValue() == 0) {
                  // `x == false` is the same as `!x`
                  return getLastExprentWhen(func.getLstOperands().get(0), !ifTrue, onlyIfTrue);
                } else {
                  // `x == true` is the same as `x`
                  return getLastExprentWhen(func.getLstOperands().get(0), ifTrue, onlyIfTrue);
                }
              }
            }
            break;
          }
          case NE: {
            Exprent rhs = func.getLstOperands().get(1);
            if (rhs.type == Exprent.Type.CONST) {
              ConstExprent constExprent = (ConstExprent) rhs;
              if (constExprent.getConstType() == VarType.VARTYPE_BOOLEAN) {
                if (constExprent.getIntValue() == 0) {
                  // `x != false` is the same as `x`
                  return getLastExprentWhen(func.getLstOperands().get(0), ifTrue, onlyIfTrue);
                } else {
                  // `x != true` is the same as `!x`
                  return getLastExprentWhen(func.getLstOperands().get(0), !ifTrue, onlyIfTrue);
                }
              }
            }
            break;
          }
        }
      }
    }

    // if we're only looking for exprents that had to return true, and this exprent didn't, return null
    if (onlyIfTrue && !ifTrue) {
      return null;
    }

    // otherwise, return ourselves
    return base;
  }
Gets the last guaranteed executed exprent in an expression.
@param ifTrue if true, gets the last executed exprent when the condition is true.
              if false, gets the last executed exprent when the condition is false.
@param onlyIfTrue if true, only returns the last executed exprent if the exprent had to return true for
                 the requested outcome to be selected.
@return the last executed exprent
src/org/jetbrains/java/decompiler/modules/decompiler/IfPatternMatchProcessor.java