Try to remove duplicate statements from IF blocks. For example:

if (a) {
x = 1;
return true;
} else {
x = 2;
return true;
}

becomes:

if (a) {
x = 1;
} else {
x = 2;
}
return true;

@param n The IF node to examine.
175030
private void tryRemoveRepeatedStatements(Node n) {
    // Only run this if variable names are guaranteed to be unique. Otherwise bad things can happen:
    // see PeepholeMinimizeConditionsTest#testDontRemoveDuplicateStatementsWithoutNormalization
    if (!isASTNormalized()) {
      return;
    }
    checkState(n.isIf(), n);

    Node parent = n.getParent();
    if (!NodeUtil.isStatementBlock(parent)) {
      // If the immediate parent is something like a label, we
      // can't move the statement, so bail.
      return;
    }

    Node cond = n.getFirstChild();
    Node trueBranch = cond.getNext();
    Node falseBranch = trueBranch.getNext();
    checkNotNull(trueBranch);
    checkNotNull(falseBranch);

    while (true) {
      Node lastTrue = trueBranch.getLastChild();
      Node lastFalse = falseBranch.getLastChild();
      if (lastTrue == null || lastFalse == null
          || !areNodesEqualForInlining(lastTrue, lastFalse)) {
        break;
      }
      lastTrue.detach();
      lastFalse.detach();
      parent.addChildAfter(lastTrue, n);
      reportChangeToEnclosingScope(parent);
    }
  }
180103
@Override
  public int compare(String s1, String s2) {
    if (s1 == s2) { // NOSONAR false-positive: Compare Objects With Equals
      return 0;
    }
    int h1 = s1.hashCode();
    int h2 = s2.hashCode();
    if (h1 < h2) {
      return -1;
    } else if (h1 > h2) {
      return 1;
    } else {
      return s1.compareTo(s2);
    }
  }
467302
@Override
    public int compare(final Issue i1, final Issue i2) {

        if (null == i1 && null == i2) {
            return 0;
        } else if (null == i1) {
            return 1;
        } else if (null == i2) {
            return -1;
        } else {
            return i1.getCreatedOn().compareTo(i2.getCreatedOn());
        }
    }
396394
public static <T> T detectIfNone(Iterable<T> iterable, Predicate<? super T> predicate, T ifNone)
    {
        T result = Iterate.detect(iterable, predicate);
        return result == null ? ifNone : result;
    }
547131
private function _if() {
    $node = new IfNode();
    $this->mustMatch(T_IF, $node);
    $this->condition($node, 'condition');
    if ($this->tryMatch(':', $node, 'openColon', FALSE, TRUE)) {
      $node->addChild($this->innerIfInnerStatementList(), 'then');
      while ($this->currentType === T_ELSEIF) {
        $this->matchHidden($node);
        $elseIf = new ElseIfNode();
        $this->mustMatch(T_ELSEIF, $elseIf);
        $this->condition($elseIf, 'condition');
        $this->mustMatch(':', $elseIf, 'openColon', FALSE, TRUE);
        $elseIf->addChild($this->innerIfInnerStatementList(), 'then');
        $node->addChild($elseIf);
      }
      if ($this->tryMatch(T_ELSE, $node, 'elseKeyword')) {
        $this->mustMatch(':', $node, 'elseColon', FALSE, TRUE);
        $node->addChild($this->innerStatementListNode(T_ENDIF), 'else');
      }
      $this->mustMatch(T_ENDIF, $node, 'endKeyword');
      $this->endStatement($node);
      return $node;
    }
    else {
      $this->matchHidden($node);
      $node->addChild($this->statement(), 'then');
      while ($this->currentType === T_ELSEIF) {
        $this->matchHidden($node);
        $elseIf = new ElseIfNode();
        $this->mustMatch(T_ELSEIF, $elseIf);
        $this->condition($elseIf, 'condition');
        $this->matchHidden($elseIf);
        $elseIf->addChild($this->statement(), 'then');
        $node->addChild($elseIf);
      }
      if ($this->tryMatch(T_ELSE, $node, 'elseKeyword', FALSE, TRUE)) {
        $node->addChild($this->statement(), 'else');
      }
      return $node;
    }
  }
367882
def _check_for_duplicates(xs, attr, check_fn=None):
    
    dups = []
    for key, vals in itertools.groupby(x[attr] for x in xs):
        if len(list(vals)) > 1:
            dups.append(key)
    if len(dups) > 0:
        psamples = []
        for x in xs:
            if x[attr] in dups:
                psamples.append(x)
        # option to skip problem based on custom input function.
        if check_fn and check_fn(psamples):
            return
        descrs = [x["description"] for x in psamples]
        raise ValueError("Duplicate '%s' found in input sample configuration.\n"
                         "Required to be unique for a project: %s\n"
                         "Problem found in these samples: %s" % (attr, dups, descrs))
558136
private final boolean elseifStatement(Data data, Condition cont) throws TemplateException {
	int pos = data.srcCode.getPos();
	if (!data.srcCode.forwardIfCurrent("else")) return false;

	comments(data);
	if (!data.srcCode.forwardIfCurrent("if", '(')) {
	    data.srcCode.setPos(pos);
	    return false;
	}

	Position line = data.srcCode.getPosition();
	Body body = new BodyBase(data.factory);
	Pair pair = cont.addElseIf(condition(data), body, line, null);

	if (!data.srcCode.forwardIfCurrent(')')) throw new TemplateException(data.srcCode, "else if statement must end with a [)]");
	// ex block
	Body prior = data.setParent(body);
	statement(data, body, CTX_ELSE_IF);
	data.setParent(prior);

	pair.end = data.srcCode.getPosition();
	return true;
    }
924411
def p_statement_if_then_endif(p):
    
    cond_ = p[1]
    stat_ = p[2]
    endif_ = p[3]
    p[0] = make_sentence('IF', cond_, make_block(stat_, endif_), lineno=p.lineno(1))
610065
public static boolean tryMergeBlock(Node block, boolean alwaysMerge) {
    checkState(block.isBlock());
    Node parent = block.getParent();
    boolean canMerge = alwaysMerge || canMergeBlock(block);
    // Try to remove the block if its parent is a block/script or if its
    // parent is label and it has exactly one child.
    if (isStatementBlock(parent) && canMerge) {
      Node previous = block;
      while (block.hasChildren()) {
        Node child = block.removeFirstChild();
        parent.addChildAfter(child, previous);
        previous = child;
      }
      parent.removeChild(block);
      return true;
    } else {
      return false;
    }
  }
162140
public final void containsNoDuplicates() {
    List<Entry<?>> duplicates = newArrayList();
    for (Multiset.Entry<?> entry : LinkedHashMultiset.create(actual()).entrySet()) {
      if (entry.getCount() > 1) {
        duplicates.add(entry);
      }
    }
    if (!duplicates.isEmpty()) {
      failWithoutActual(
          simpleFact("expected not to contain duplicates"),
          fact("but contained", duplicates),
          fullContents());
    }
  }
324981
protected boolean areNodesEqualForInlining(Node n1, Node n2) {
    /* Our implementation delegates to the compiler. We provide this
     * method because we don't want to expose Compiler to PeepholeOptimizations.
     */
    checkNotNull(compiler);
    return compiler.areNodesEqualForInlining(n1, n2);
  }
808374
private void normalizeNodeTypes(Node n) {
    normalizeBlocks(n);

    for (Node child = n.getFirstChild();
         child != null; child = child.getNext()) {
      // This pass is run during the CompilerTestCase validation, so this
      // parent pointer check serves as a more general check.
      checkState(child.getParent() == n);

      normalizeNodeTypes(child);
    }
  }
532181
def visit_If(self, node):
        """"""
        # do not optimize ifs that have a block inside so that it doesn't
        # break super().
        if node.find(nodes.Block) is not None:
            return self.generic_visit(node)
        try:
            val = self.visit(node.test).as_const()
        except nodes.Impossible:
            return self.generic_visit(node)
        if val:
            body = node.body
        else:
            body = node.else_
        result = []
        for node in body:
            result.extend(self.visit_list(node))
        return result
371233
public static boolean and(final INDArray n, final Condition cond) {
        if (cond instanceof BaseCondition) {
            long val = (long) Nd4j.getExecutioner().exec(new MatchCondition(n, cond)).getDouble(0);

            if (val == n.length())
                return true;
            else
                return false;

        } else {
            throw new RuntimeException("Can only execute BaseCondition conditions using this method");
        }
    }
634187
private static int compareNodes(String node1, String node2) {
        assert node1 != null;
        assert node2 != null;
        
        if (node1.equals(node2)) {
            return 0;
        }
        if (node1.length() > 0 && node1.charAt(0) == '{') {
            if (node2.length() > 0 && node2.charAt(0) == '{') {
                return 0;  // Both nodes are parameters; names are irrelevant
            }
            return 1;  // r1 is a parameter but r2 is not, so r2 should come first
        }
        if (node2.length() > 0 && node2.charAt(0) == '{') {
            return -1;   // r2 is a parameter but r1 is not, so r1 should come first
        }
        return node1.compareTo(node2);  // neither node is a parameter
    }
19085
private static int compare(Treenode item1, Treenode item2) {
        String label1 = item1.getLabel();
        String label2 = item2.getLabel();
        return label1 == label2 ? 0 : label1 == null ? -1 : label2 == null ? -1 : label1.compareToIgnoreCase(label2);
    }
1325836
private boolean blockEquals(Block target, Block source)
    {
        boolean found = false;
        if (source instanceof SpecialSymbolBlock && target instanceof SpecialSymbolBlock) {
            if (((SpecialSymbolBlock) target).getSymbol() == ((SpecialSymbolBlock) source).getSymbol()) {
                found = true;
            }
        } else if (source instanceof WordBlock && target instanceof WordBlock) {
            if (((WordBlock) target).getWord().equals(((WordBlock) source).getWord())) {
                found = true;
            }
        } else if (source.equals(target)) {
            found = true;
        }
        return found;
    }