public static boolean isDominator(ControlFlowGraph graph, BasicBlock block, BasicBlock dom) {
    if (block == dom) {
      return true;
    }

    Set<BasicBlock> marked = new HashSet<>();
    List<BasicBlock> lstNodes = new LinkedList<>();
    lstNodes.add(block);

    while (!lstNodes.isEmpty()) {
      BasicBlock node = lstNodes.remove(0);
      if (marked.contains(node)) {
        continue;
      }
      else {
        marked.add(node);
      }

      if (node == graph.getFirst()) {
        return false;
      }

      for (int i = 0; i < node.getPredecessors().size(); i++) {
        BasicBlock predecessor = node.getPredecessors().get(i);
        if (predecessor != dom && !marked.contains(predecessor)) {
          lstNodes.add(predecessor);
        }
      }

      for (int i = 0; i < node.getPredecessorExceptions().size(); i++) {
        BasicBlock predecessor = node.getPredecessorExceptions().get(i);
        if (predecessor != dom && !marked.contains(predecessor)) {
          lstNodes.add(predecessor);
        }
      }
    }

    return true;
  }
public static boolean isDominator(ControlFlowGraph graph, BasicBlock block, BasicBlock dom)