rank__c.java

/* ========================================================================
 * PlantUML : a free UML diagram generator
 * ========================================================================
 *
 * Project Info:  https://plantuml.com
 * 
 * If you like this project or if you find it useful, you can support us at:
 * 
 * https://plantuml.com/patreon (only 1$ per month!)
 * https://plantuml.com/paypal
 * 
 * This file is part of Smetana.
 * Smetana is a partial translation of Graphviz/Dot sources from C to Java.
 *
 * (C) Copyright 2009-2022, Arnaud Roques
 *
 * This translation is distributed under the same License as the original C program:
 * 
 *************************************************************************
 * Copyright (c) 2011 AT&T Intellectual Property 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: See CVS logs. Details at http://www.graphviz.org/
 *************************************************************************
 *
 * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
 * LICENSE ("AGREEMENT"). [Eclipse Public License - v 1.0]
 * 
 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
 * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
 * 
 * You may obtain a copy of the License at
 * 
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package gen.lib.dotgen;
import static smetana.core.Macro.ND_set;
import static smetana.core.Macro.ND_rep;
import static smetana.core.Macro.ND_hops;
import static smetana.core.Macro.GD_level;
import static smetana.core.Macro.GD_minrep;
import static smetana.core.Macro.GD_maxrep;
import static smetana.core.Macro.GD_has_sourcerank;
import static smetana.core.Macro.GD_has_sinkrank;
import static gen.lib.cgraph.edge__c.agedge;
import static gen.lib.cgraph.edge__c.agdeledge;
import static gen.lib.cgraph.edge__c.agfstin;
import static gen.lib.cgraph.edge__c.agnxtin;
import static gen.lib.cgraph.edge__c.agtail;
import static gen.lib.cgraph.attr__c.agxget;
import static gen.lib.cgraph.graph__c.agopen;
import static gen.lib.cgraph.graph__c.agnnodes;
import static gen.lib.cgraph.node__c.agnode;
import static gen.lib.cgraph.rec__c.agbindrec;
import static gen.lib.common.ns__c.rank2;
import static gen.lib.common.utils__c.mapBool;
import static gen.lib.common.utils__c.mapbool;
import static smetana.core.JUtils.atof;
import static smetana.core.JUtils.atoi;
import static smetana.core.JUtils.strcmp;
import static smetana.core.Macro.ND_alg;
import static smetana.core.Macro.ND_onstack;
import static smetana.core.Macro.ND_prev;
import static smetana.core.Macro.agfindedge;
import static smetana.core.Macro.alloc_elist;
import static smetana.core.Macro.elist_append;
import static smetana.core.Macro.free_list;
import smetana.core.size_t;
import static gen.lib.cgraph.attr__c.agget;
import static gen.lib.cgraph.edge__c.agfstout;
import static gen.lib.cgraph.edge__c.aghead;
import static gen.lib.cgraph.edge__c.agnxtout;
import static gen.lib.cgraph.edge__c.agsubedge;
import static gen.lib.cgraph.id__c.agnameof;
import static gen.lib.cgraph.node__c.agfstnode;
import static gen.lib.cgraph.node__c.agnxtnode;
import static gen.lib.cgraph.obj__c.agcontains;
import static gen.lib.cgraph.obj__c.agdelete;
import static gen.lib.cgraph.subg__c.agfstsubg;
import static gen.lib.cgraph.subg__c.agnxtsubg;
import static gen.lib.common.input__c.do_graph_label;
import static gen.lib.common.ns__c.rank;
import static gen.lib.common.utils__c.UF_find;
import static gen.lib.common.utils__c.UF_singleton;
import static gen.lib.common.utils__c.UF_union;
import static gen.lib.common.utils__c.maptoken;
import static gen.lib.dotgen.acyclic__c.acyclic_;
import static gen.lib.dotgen.acyclic__c.reverse_edge;
import static gen.lib.dotgen.aspect__c.rank3;
import static gen.lib.dotgen.class1__c.class1_;
import static gen.lib.dotgen.decomp__c.decompose;
import static gen.lib.dotgen.dotinit__c.dot_root;
import static gen.lib.dotgen.fastgr__c.virtual_edge;
import static smetana.core.JUtils.strncmp;
import static smetana.core.Macro.CLUSTER;
import static smetana.core.Macro.EDGE_LABEL;
import static smetana.core.Macro.ED_minlen;
import static smetana.core.Macro.ED_to_orig;
import static smetana.core.Macro.ED_to_virt;
import static smetana.core.Macro.ED_weight;
import static smetana.core.Macro.GD_clust;
import static smetana.core.Macro.GD_comp;
import static smetana.core.Macro.GD_flags;
import static smetana.core.Macro.GD_has_labels;
import static smetana.core.Macro.GD_leader;
import static smetana.core.Macro.GD_maxrank;
import static smetana.core.Macro.GD_maxset;
import static smetana.core.Macro.GD_minrank;
import static smetana.core.Macro.GD_minset;
import static smetana.core.Macro.GD_n_cluster;
import static smetana.core.Macro.GD_nlist;
import static smetana.core.Macro.GD_parent;
import static smetana.core.Macro.GD_ranksep;
import static smetana.core.Macro.GD_set_type;
import static smetana.core.Macro.LEAFSET;
import static smetana.core.Macro.LOCAL;
import static smetana.core.Macro.MAXRANK;
import static smetana.core.Macro.MAXSHORT;
import static smetana.core.Macro.MINRANK;
import static smetana.core.Macro.ND_clust;
import static smetana.core.Macro.ND_in;
import static smetana.core.Macro.ND_mark;
import static smetana.core.Macro.ND_next;
import static smetana.core.Macro.ND_node_type;
import static smetana.core.Macro.ND_out;
import static smetana.core.Macro.ND_rank;
import static smetana.core.Macro.ND_ranktype;
import static smetana.core.Macro.NEW_RANK;
import static smetana.core.Macro.NORMAL;
import static smetana.core.Macro.SAMERANK;
import static smetana.core.Macro.SINKRANK;
import static smetana.core.Macro.SOURCERANK;
import static smetana.core.Macro.UNSUPPORTED;
import static smetana.core.debug.SmetanaDebug.ENTERING;
import static smetana.core.debug.SmetanaDebug.LEAVING;

import gen.annotation.Difficult;
import gen.annotation.HasND_Rank;
import gen.annotation.Original;
import gen.annotation.Reviewed;
import gen.annotation.Todo;
import gen.annotation.Unused;
import h.ST_Agedge_s;
import h.ST_Agnode_s;
import h.ST_Agraph_s;
import h.ST_aspect_t;
import h.ST_elist;
import h.ST_point;
import smetana.core.CArrayOfStar;
import smetana.core.CString;
import smetana.core.Globals;
import smetana.core.Memory;
import smetana.core.ZType;

public class rank__c {


	
	
	
@Reviewed(when = "14/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="renewlist", key="3f1re3nfkhxwjjb90kppwuupr", definition="static void  renewlist(elist * L)")
public static void renewlist(ST_elist L) {
ENTERING("3f1re3nfkhxwjjb90kppwuupr","renewlist");
try {
    int i;
    for (i = L.size; i >= 0; i--)
	L.list.set_(i, null);
    L.size = 0;
} finally {
LEAVING("3f1re3nfkhxwjjb90kppwuupr","renewlist");
}
}




@Difficult
@Reviewed(when = "14/11/2020")
@Todo(what = "check why GD_comp(g).resetList comes from GD_comp(g).list = NULL")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="cleanup1", key="1xov2qhuxj1f9nbzu3xsa6679", definition="static void  cleanup1(graph_t * g)")
public static void cleanup1(Globals zz, ST_Agraph_s g) {
ENTERING("1xov2qhuxj1f9nbzu3xsa6679","cleanup1");
try {
    ST_Agnode_s n;
    ST_Agedge_s e, f;
    int c;
    
    for (c = 0; c < GD_comp(g).size; c++) {
    GD_nlist(g, GD_comp(g).list.get_(c));
	for (n = GD_nlist(g); n!=null; n = ND_next(n)) {
	    renewlist(ND_in(n));
	    renewlist(ND_out(n));
	    ND_mark(n, 0);
	}
    }
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) {
	for (e = agfstout(zz, g, n); e!=null; e = agnxtout(zz, g, e)) {
	    f = ED_to_virt(e);
	    /* Null out any other references to f to make sure we don't 
	     * handle it a second time. For example, parallel multiedges 
	     * share a virtual edge.
	     */
	    if (f!=null && (e == ED_to_orig(f))) {
		ST_Agedge_s e1, f1;
		ST_Agnode_s n1;
		for (n1 = agfstnode(zz, g); n1!=null; n1 = agnxtnode(zz, g, n1)) {
		    for (e1 = agfstout(zz, g, n1); e1!=null; e1 = agnxtout(zz, g, e1)) {
			if ((e != e1)) {
			    f1 = ED_to_virt(e1);
			    if (f1!=null && f == f1) {
				ED_to_virt(e1, null);
			    }
			}
		    }
		}
		Memory.free(f.base.data);
		Memory.free(f);
	    }
	    ED_to_virt(e, null);
	}
    }
    Memory.free(GD_comp(g).list);
    GD_comp(g).list = null;
    GD_comp(g).size = 0;
} finally {
LEAVING("1xov2qhuxj1f9nbzu3xsa6679","cleanup1");
}
}



/* When there are edge labels, extra ranks are reserved here for the virtual
 * nodes of the labels.  This is done by doubling the input edge lengths.
 * The input rank separation is adjusted to compensate.
 */
@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="edgelabel_ranks", key="bxjf5g7g953ii1hfodl1j0y4u", definition="static void  edgelabel_ranks(graph_t * g)")
public static void edgelabel_ranks(Globals zz, ST_Agraph_s g) {
ENTERING("bxjf5g7g953ii1hfodl1j0y4u","edgelabel_ranks");
try {
    ST_Agnode_s n;
    ST_Agedge_s e;
    
    if ((GD_has_labels(g) & EDGE_LABEL)!=0) {
	for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n))
	    for (e = agfstout(zz, g, n); e!=null; e = agnxtout(zz, g, e))
		ED_minlen(e, ED_minlen(e) * 2);
	GD_ranksep(g, (GD_ranksep(g) + 1) / 2);
    }
} finally {
LEAVING("bxjf5g7g953ii1hfodl1j0y4u","edgelabel_ranks");
}
}




//3 9kjpoxcxoy3nhqd9rflwclo7c
// static void  collapse_rankset(graph_t * g, graph_t * subg, int kind) 
@Unused
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="collapse_rankset", key="9kjpoxcxoy3nhqd9rflwclo7c", definition="static void  collapse_rankset(graph_t * g, graph_t * subg, int kind)")
public static void collapse_rankset(Globals zz, ST_Agraph_s g, ST_Agraph_s subg, int kind) {
ENTERING("9kjpoxcxoy3nhqd9rflwclo7c","collapse_rankset");
try {
    ST_Agnode_s u, v; //     node_t *u, *v;
    u = v = agfstnode(zz, subg); //     u = v = agfstnode(subg);
    if (u!=null) { //     if (u) {
	ND_ranktype(u, kind); // 	ND_ranktype(u) = kind;
	while ((v = agnxtnode(zz, subg, v))!=null) { // 	while ((v = agnxtnode(subg, v))) {
	    UF_union(u, v); // 	    UF_union(u, v);
	    ND_ranktype(v, ND_ranktype(u)); // 	    ND_ranktype(v) = ND_ranktype(u);
	} // 	}
	switch (kind) { // 	switch (kind) {
	case MINRANK: // 	case 2:
	case SOURCERANK: // 	case 3:
	    if (GD_minset(g) == null) // 	    if (GD_minset(g) == NULL)
		GD_minset(g, u); // 		GD_minset(g) = u;
	    else // 	    else
		GD_minset(g, UF_union((ST_Agnode_s) GD_minset(g), u)); // 		GD_minset(g) = UF_union(GD_minset(g), u);
	    break; // 	    break;
	case MAXRANK: // 	case 4:
	case SINKRANK: // 	case 5:
	    if (GD_maxset(g) == null) // 	    if (GD_maxset(g) == NULL)
		GD_maxset(g, u); // 		GD_maxset(g) = u;
	    else // 	    else
		GD_maxset(g, UF_union((ST_Agnode_s) GD_maxset(g), u)); // 		GD_maxset(g) = UF_union(GD_maxset(g), u);
	    break; // 	    break;
	} // 	}
	switch (kind) { // 	switch (kind) {
	case SOURCERANK: // 	case 3:
	    ND_ranktype((ST_Agnode_s) GD_minset(g), kind); // 	    ND_ranktype(GD_minset(g)) = kind;
	    break; // 	    break;
	case SINKRANK: // 	case 5:
	    ND_ranktype((ST_Agnode_s) GD_maxset(g), kind); // 	    ND_ranktype(GD_maxset(g)) = kind;
	    break; // 	    break;
	} // 	}
    } //     }
} finally {
LEAVING("9kjpoxcxoy3nhqd9rflwclo7c","collapse_rankset");
}
}




@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="rank_set_class", key="65qi5f0bxp6d6vahhlcolpk88", definition="static int  rank_set_class(graph_t * g)")
public static int rank_set_class(Globals zz, ST_Agraph_s g) {
ENTERING("65qi5f0bxp6d6vahhlcolpk88","rank_set_class");
try {
    CString name[] = new CString[] { new CString("same"), new CString("min"), new CString("source"), new CString("max"), new CString("sink"), null };
    int class_[] = new int[] 
    { SAMERANK, MINRANK, SOURCERANK, MAXRANK, SINKRANK, 0 };
    int val;
    
    if (is_cluster(zz, g))
	return CLUSTER;
    val = maptoken(agget(zz, g, new CString("rank")), name, class_);
    GD_set_type(g, val);
    return val;
} finally {
LEAVING("65qi5f0bxp6d6vahhlcolpk88","rank_set_class");
}
}



@Difficult
@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="make_new_cluster", key="5189iviqj57iztftckz86y6jj", definition="static int  make_new_cluster(graph_t * g, graph_t * subg)")
public static int make_new_cluster(Globals zz, ST_Agraph_s g, ST_Agraph_s subg) {
ENTERING("5189iviqj57iztftckz86y6jj","make_new_cluster");
try {
    int cno;
    GD_n_cluster(g, GD_n_cluster(g)+1);
    cno = GD_n_cluster(g);
    GD_clust(g, CArrayOfStar.<ST_Agraph_s>REALLOC(cno + 1, GD_clust(g), ZType.ST_Agraph_s));
    GD_clust(g).set_(cno, subg);
    do_graph_label(zz, subg);
    return cno;
} finally {
LEAVING("5189iviqj57iztftckz86y6jj","make_new_cluster");
}
}



@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="node_induce", key="9lvm2ufqjzl2bsbpo0zg9go58", definition="static void  node_induce(graph_t * par, graph_t * g)")
public static void node_induce(Globals zz, ST_Agraph_s par, ST_Agraph_s g) {
ENTERING("9lvm2ufqjzl2bsbpo0zg9go58","node_induce");
try {
    ST_Agnode_s n, nn;
    ST_Agedge_s e;
    int i;

    /* enforce that a node is in at most one cluster at this level */
    for (n = agfstnode(zz, g); n!=null; n = nn) {
	nn = agnxtnode(zz, g, n);
	if (ND_ranktype(n)!=0) {
	    agdelete(g, n);
	    continue;
	}
	for (i = 1; i < GD_n_cluster(par); i++)
	    if (agcontains(zz, GD_clust(par).get_(i), n))
		break;
	if (i < GD_n_cluster(par))
	    agdelete(g, n);
	ND_clust(n, null);
    }
    
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) {
	for (e = agfstout(zz, dot_root(g), n); e!=null; e = agnxtout(zz, dot_root(g), e)) {
	    if (agcontains(zz, g, aghead(e)))
		agsubedge(zz, g,e,true);
	}
    }
} finally {
LEAVING("9lvm2ufqjzl2bsbpo0zg9go58","node_induce");
}
}




@Reviewed(when = "14/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="cluster_leader", key="2rbs5deyvlh5s7lkhv6zouqbe", definition="static void cluster_leader(graph_t * clust)")
public static void cluster_leader(Globals zz, ST_Agraph_s clust) {
ENTERING("2rbs5deyvlh5s7lkhv6zouqbe","cluster_leader");
try {
    ST_Agnode_s leader, n;
    int maxrank = 0;
    
    /* find number of ranks and select a leader */
    leader = null;
    for (n = GD_nlist(clust); n!=null; n = ND_next(n)) {
	if ((ND_rank(n) == 0) && (ND_node_type(n) == NORMAL))
	    leader = n;
	if (maxrank < ND_rank(n))
	    maxrank = ND_rank(n);
    }
    assert(leader != null);
    GD_leader(clust, leader);
    
    for (n = agfstnode(zz, clust); n!=null; n = agnxtnode(zz, clust, n)) {
	//assert((ND_UF_size(n) <= 1) || (n == leader));
	UF_union(n, leader);
	ND_ranktype(n, CLUSTER);
    }
} finally {
LEAVING("2rbs5deyvlh5s7lkhv6zouqbe","cluster_leader");
}
}



/*
 * A cluster is collapsed in three steps.
 * 1) The nodes of the cluster are ranked locally.
 * 2) The cluster is collapsed into one node on the least rank.
 * 3) In class1(), any inter-cluster edges are converted using
 *    the "virtual node + 2 edges" trick.
 */
@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="collapse_cluster", key="f3sl627dqmre3kru883bpdxc3", definition="static void  collapse_cluster(graph_t * g, graph_t * subg)")
public static void collapse_cluster(Globals zz, ST_Agraph_s g, ST_Agraph_s subg) {
ENTERING("f3sl627dqmre3kru883bpdxc3","collapse_cluster");
try {
    if (GD_parent(subg)!=null) {
	return;
    }
    GD_parent(subg, g);
    node_induce(zz, g, subg);
    if (agfstnode(zz, subg) == null)
	return;
    make_new_cluster(zz, g, subg);
    if (zz.CL_type == LOCAL) {
	dot1_rank(zz, subg, null);
	cluster_leader(zz, subg);
    } else
    UNSUPPORTED("1os84mtyrb110i4sd8bdjrwk"); // 	dot_scan_ranks(subg);
    
    
} finally {
LEAVING("f3sl627dqmre3kru883bpdxc3","collapse_cluster");
}
}



/* Execute union commands for "same rank" subgraphs and clusters. */
@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="collapse_sets", key="din4qnipewrwnelaimzvlplft", definition="static void  collapse_sets(graph_t *rg, graph_t *g)")
public static void collapse_sets(Globals zz, ST_Agraph_s rg, ST_Agraph_s g) {
ENTERING("din4qnipewrwnelaimzvlplft","collapse_sets");
try {
    int c;
    ST_Agraph_s  subg;
    
    for (subg = agfstsubg(zz, g); subg!=null; subg = agnxtsubg(zz, subg)) {
	c = rank_set_class(zz, subg);
	if (c!=0) {
	    if ((c == CLUSTER) && zz.CL_type == LOCAL)
		collapse_cluster(zz, rg, subg);
	    else
		collapse_rankset(zz, rg, subg, c);
	}
	else collapse_sets(zz, rg, subg);
	
	
	
    }
} finally {
LEAVING("din4qnipewrwnelaimzvlplft","collapse_sets");
}
}




//3 5n9mgh7vlru5mb1j9oienvbvs
// static void  find_clusters(graph_t * g) 
@Unused
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="find_clusters", key="5n9mgh7vlru5mb1j9oienvbvs", definition="static void  find_clusters(graph_t * g)")
public static Object find_clusters(Object... arg_) {
UNSUPPORTED("59dl3yc4jbcy2pb7j1njhlybi"); // static void 
UNSUPPORTED("cdsgmo50taekqgk95mfn25930"); // find_clusters(graph_t * g)
UNSUPPORTED("erg9i1970wdri39osu8hx2a6e"); // {
UNSUPPORTED("8uujemixuhlf040icq3zsh7j8"); //     graph_t *subg;
UNSUPPORTED("39msf2samfrjyh2h1a0nh0bnq"); //     for (subg = agfstsubg(dot_root(g)); subg; subg = agnxtsubg(subg)) {
UNSUPPORTED("zmexivcsx1b4oppz6cjwhzd9"); // 	if (GD_set_type(subg) == 7)
UNSUPPORTED("xqwyd1xyo86onxfw4s7p8at4"); // 	    collapse_cluster(g, subg);
UNSUPPORTED("dvgyxsnyeqqnyzq696k3vskib"); //     }
UNSUPPORTED("c24nfmv9i7o5eoqaymbibp7m7"); // }

throw new UnsupportedOperationException();
}




@Reviewed(when = "14/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="set_minmax", key="12fw0esv4unfin6waf9mknc1o", definition="static void  set_minmax(graph_t * g)")
public static void set_minmax(ST_Agraph_s g) {
ENTERING("12fw0esv4unfin6waf9mknc1o","set_minmax");
try {
    int c;
    
    GD_minrank(g, GD_minrank(g) + ND_rank(GD_leader(g)));
    GD_maxrank(g, GD_maxrank(g) + ND_rank(GD_leader(g)));
    for (c = 1; c <= GD_n_cluster(g); c++)
	set_minmax(GD_clust(g).get_(c));
} finally {
LEAVING("12fw0esv4unfin6waf9mknc1o","set_minmax");
}
}



/* To ensure that min and max rank nodes always have the intended rank
 * assignment, reverse any incompatible edges.
 */
@Reviewed(when = "14/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="minmax_edges", key="3bcr1748gqnu8ogb73jeja7ly", definition="static point  minmax_edges(graph_t * g)")
public static ST_point minmax_edges(ST_Agraph_s g) {
// WARNING!! STRUCT
return (ST_point) minmax_edges_w_(g).copy();
}
private static ST_point minmax_edges_w_(ST_Agraph_s g) {
ENTERING("3bcr1748gqnu8ogb73jeja7ly","minmax_edges");
try {
    ST_Agnode_s n;
    ST_Agedge_s e;
    final ST_point slen = new ST_point();
    
    slen.x = slen.y = 0;
    if ((GD_maxset(g) == null) && (GD_minset(g) == null))
	return slen;
    if (GD_minset(g) != null) //     if (GD_minset(g) != NULL)
	GD_minset(g, UF_find((ST_Agnode_s) GD_minset(g))); // 	GD_minset(g) = UF_find(GD_minset(g));
    if (GD_maxset(g) != null) //     if (GD_maxset(g) != NULL)
	GD_maxset(g, UF_find((ST_Agnode_s) GD_maxset(g))); // 	GD_maxset(g) = UF_find(GD_maxset(g));
    if ((n = (ST_Agnode_s) GD_maxset(g))!=null) { //     if ((n = GD_maxset(g))) {
	slen.y = (ND_ranktype((ST_Agnode_s) GD_maxset(g)) == SINKRANK) ? 1 : 0; // 	slen.y = (ND_ranktype(GD_maxset(g)) == SINKRANK);
	// The C list is NULL terminated: "while ((e = ND_out(n).list[0]))" loops until it is empty
	while (ND_out(n).size > 0) { // 	while ((e = ND_out(n).list[0])) {
	    e = ND_out(n).list.get_(0);
	    // 	    assert(agtail(e) == UF_find(agtail(e)));
	    reverse_edge(e); // 	    reverse_edge(e);
	} // 	}
    } //     }
    if ((n = (ST_Agnode_s) GD_minset(g))!=null) { //     if ((n = GD_minset(g))) {
	slen.x = (ND_ranktype((ST_Agnode_s) GD_minset(g)) == SOURCERANK) ? 1 : 0; // 	slen.x = (ND_ranktype(GD_minset(g)) == SOURCERANK);
	while (ND_in(n).size > 0) { // 	while ((e = ND_in(n).list[0])) {
	    e = ND_in(n).list.get_(0);
	    // 	    assert(aghead(e) == UF_find(aghead(e)));
	    reverse_edge(e); // 	    reverse_edge(e);
	} // 	}
    } //     }
    return slen; //     return slen;
} finally {
LEAVING("3bcr1748gqnu8ogb73jeja7ly","minmax_edges");
}
}




@Reviewed(when = "14/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="minmax_edges2", key="1rmlm1wo3t94wyet9rlwrmith", definition="static int  minmax_edges2(graph_t * g, point slen)")
public static boolean minmax_edges2(Globals zz, ST_Agraph_s g, final ST_point slen) {
// WARNING!! STRUCT
return minmax_edges2_w_(zz, g, (ST_point) slen.copy());
}
private static boolean minmax_edges2_w_(Globals zz, ST_Agraph_s g, final ST_point slen) {
ENTERING("1rmlm1wo3t94wyet9rlwrmith","minmax_edges2");
try {
    ST_Agnode_s n;
    ST_Agedge_s e = null;
    if ((GD_maxset(g)!=null) || (GD_minset(g)!=null)) {
	for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { // 	for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	    if (n != UF_find(n)) // 	    if (n != UF_find(n))
		continue; // 		continue;
	    if ((ND_out(n).size == 0) && (GD_maxset(g)!=null) && (n != GD_maxset(g))) { // 	    if ((ND_out(n).size == 0) && GD_maxset(g) && (n != GD_maxset(g))) {
		e = virtual_edge(n, (ST_Agnode_s) GD_maxset(g), null); // 		e = virtual_edge(n, GD_maxset(g), NULL);
		ED_minlen(e, slen.y); // 		ED_minlen(e) = slen.y;
		ED_weight(e, 0); // 		ED_weight(e) = 0;
	    } // 	    }
	    if ((ND_in(n).size == 0) && (GD_minset(g)!=null) && (n != GD_minset(g))) { // 	    if ((ND_in(n).size == 0) && GD_minset(g) && (n != GD_minset(g))) {
		e = virtual_edge((ST_Agnode_s) GD_minset(g), n, null); // 		e = virtual_edge(GD_minset(g), n, NULL);
		ED_minlen(e, slen.x); // 		ED_minlen(e) = slen.x;
		ED_weight(e, 0); // 		ED_weight(e) = 0;
	    } // 	    }
	} // 	}
    }
    return (e != null);
} finally {
LEAVING("1rmlm1wo3t94wyet9rlwrmith","minmax_edges2");
}
}




@Reviewed(when = "14/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="rank1", key="3vpthwso788idvycelpnqijys", definition="void rank1(graph_t * g)")
public static void rank1(Globals zz, ST_Agraph_s g) {
ENTERING("3vpthwso788idvycelpnqijys","rank1");
try {
    int maxiter = Integer.MAX_VALUE;
    int c;
    CString s;
    
    if ((s = agget(zz, g, new CString("nslimit1")))!=null)
    UNSUPPORTED("9tp2zk1tsr4ce9rwsr0is9u3o"); // 	maxiter = atof(s) * agnnodes(g);
    for (c = 0; c < GD_comp(g).size; c++) {
	GD_nlist(g, GD_comp(g).list.get_(c));
	rank(zz, g, (GD_n_cluster(g) == 0 ? 1 : 0), maxiter);	/* TB balance */
    }
} finally {
LEAVING("3vpthwso788idvycelpnqijys","rank1");
}
}




/* 
 * Assigns ranks of non-leader nodes.
 * Expands same, min, max rank sets.
 * Leaf sets and clusters remain merged.
 * Sets minrank and maxrank appropriately.
 */
@Reviewed(when = "14/11/2020")
@HasND_Rank
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="expand_ranksets", key="cdh8wnb99v90dy6efpbzmrjix", definition="static void expand_ranksets(graph_t * g, aspect_t* asp)")
public static void expand_ranksets(Globals zz, ST_Agraph_s g, ST_aspect_t asp) {
ENTERING("cdh8wnb99v90dy6efpbzmrjix","expand_ranksets");
try {
    int c;
    ST_Agnode_s n, leader;
    
    if ((n = agfstnode(zz, g))!=null) {
	GD_minrank(g, MAXSHORT);
	GD_maxrank(g, -1);
	while (n!=null) {
	    leader = UF_find(n);
	    /* The following works because ND_rank(n) == 0 if n is not in a
	     * cluster, and ND_rank(n) = the local rank offset if n is in
	     * a cluster. */
	    if ((leader != n) && ((asp) == null || (ND_rank(n) == 0)))
		ND_rank(n, ND_rank(n) + ND_rank(leader));
	    
	    if (GD_maxrank(g) < ND_rank(n))
		GD_maxrank(g, ND_rank(n));
	    if (GD_minrank(g) > ND_rank(n))
		GD_minrank(g, ND_rank(n));
	    
	    if (ND_ranktype(n)!=0 && (ND_ranktype(n) != LEAFSET))
		UF_singleton(n);
	    n = agnxtnode(zz, g, n);
	}
	if (g == dot_root(g)) {
	    if (zz.CL_type == LOCAL) {
		for (c = 1; c <= GD_n_cluster(g); c++)
		    set_minmax(GD_clust(g).get_(c));
	    } else {
		find_clusters(g);
	    }
	}
    } else {
	GD_maxrank(g, 0);
	GD_minrank(g, 0);
    }
} finally {
LEAVING("cdh8wnb99v90dy6efpbzmrjix","expand_ranksets");
}
}



/* dot1_rank:
 * asp != NULL => g is root
 */
@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="dot1_rank", key="2o4rmb4o6f6zh46ak3se91rwr", definition="static void dot1_rank(graph_t * g, aspect_t* asp)")
public static void dot1_rank(Globals zz, ST_Agraph_s g, ST_aspect_t asp) {
ENTERING("2o4rmb4o6f6zh46ak3se91rwr","dot1_rank");
try {
    final ST_point p = new ST_point();
    
    edgelabel_ranks(zz, g);
    
    if (asp!=null) {
	UNSUPPORTED("kh7e20nqwuserrnpf3zpvuyl"); // 	init_UF_size(g);
	UNSUPPORTED("d88j5oswhz0d3yvd4wlvxohmu"); // 	initEdgeTypes(g);
    }
    
    
    collapse_sets(zz, g,g);
    /*collapse_leaves(g); */
    class1_(zz, g);
    p.___(minmax_edges(g));
    decompose(zz, g, 0);
    if (asp!=null && ((GD_comp(g).size > 1)||(GD_n_cluster(g) > 0))) {
	UNSUPPORTED("evcjt85irnaa02v8cam07i009"); // 	asp->badGraph = 1;
	UNSUPPORTED("45nxv6kczal9hnytkfcyt2jk8"); // 	asp = NULL;
    }
    acyclic_(g);
    if (minmax_edges2(zz, g, p))
	decompose(zz, g, 0); // 	decompose(g, 0);
    if (asp!=null)
	rank3(g, asp);
    else
	rank1(zz, g);
    
    expand_ranksets(zz, g, asp);
    cleanup1(zz, g);
} finally {
LEAVING("2o4rmb4o6f6zh46ak3se91rwr","dot1_rank");
}
}




@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="dot_rank", key="asyfujgwqa407ffvqn5psbtsc", definition="void dot_rank(graph_t * g, aspect_t* asp)")
public static void dot_rank(Globals zz, ST_Agraph_s g, ST_aspect_t asp) {
ENTERING("asyfujgwqa407ffvqn5psbtsc","dot_rank");
try {
    if (agget (zz, g, new CString("newrank"))!=null) {
	GD_flags(g, GD_flags(g) | NEW_RANK);
	dot2_rank (zz, g, asp);
    }
    else
	dot1_rank (zz, g, asp);
    //if (Verbose)
	//fprintf (stderr, "Maxrank = %d, minrank = %d\n", (((Agraphinfo_t*)(((Agobj_t*)(g))->data))->maxrank), (((Agraphinfo_t*)(((Agobj_t*)(g))->data))->minrank));
} finally {
LEAVING("asyfujgwqa407ffvqn5psbtsc","dot_rank");
}
}




@Reviewed(when = "13/11/2020")
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="is_cluster", key="cdncou6d2ng5i48rd1mk2cpnw", definition="int is_cluster(graph_t * g)")
public static boolean is_cluster(Globals zz, ST_Agraph_s g) {
ENTERING("cdncou6d2ng5i48rd1mk2cpnw","is_cluster");
try {
    return (strncmp(agnameof(zz, g), new CString("cluster"), 7) == 0);
} finally {
LEAVING("cdncou6d2ng5i48rd1mk2cpnw","is_cluster");
}
}





/* new ranking code:
 * Allows more constraints
 * Copy of level.c in dotgen2
 * Many of the utility functions are simpler or gone with
 * cgraph library.
 *
 * Ported from lib/dotgen/rank.c (Graphviz 2.38). The C original is kept as a
 * trailing comment on each line.
 */
private static final int BACKWARD_PENALTY = 1000; // #define	BACKWARD_PENALTY	1000
private static final int STRONG_CLUSTER_WEIGHT = 1000; // #define STRONG_CLUSTER_WEIGHT   1000
private static final int NORANK = 6; // #define	NORANK		6
private static final CString ROOT = new CString("\177root"); // #define ROOT    "\177root"
private static final CString TOPNODE = new CString("\177top"); // #define TOPNODE     "\177top"
private static final CString BOTNODE = new CString("\177bot"); // #define BOTNODE     "\177bot"

/* hops is not used in dot, so we overload it to
 * contain the index of the connected component
 */
private static int ND_comp(ST_Agnode_s n) { // #define ND_comp(n)  ND_hops(n)
	return ND_hops(n);
}

private static void ND_comp(ST_Agnode_s n, int v) {
	ND_hops(n, v);
}

@Original(version="2.38.0", path="lib/common/utils.c", name="is_a_cluster", key="", definition="int is_a_cluster (Agraph_t* g)")
private static boolean is_a_cluster(Globals zz, ST_Agraph_s g) {
    //     return ((g == g->root) || (!strncasecmp(agnameof(g), "cluster", 7)));
    if (g == g.root)
	return true;
    final CString name = agnameof(zz, g);
    return name != null && name.length() >= 7 && name.getContent().substring(0, 7).equalsIgnoreCase("cluster");
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="set_parent", key="", definition="static void set_parent(graph_t* g, graph_t* p)")
private static void set_parent(Globals zz, ST_Agraph_s g, ST_Agraph_s p) {
    GD_parent(g, p); //     GD_parent(g) = p;
    make_new_cluster(zz, p, g); //     make_new_cluster(p, g);
    node_induce(zz, p, g); //     node_induce(p, g);
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="is_empty", key="", definition="static int is_empty(graph_t * g)")
private static boolean is_empty(Globals zz, ST_Agraph_s g) {
    return agfstnode(zz, g) == null; //     return (!agfstnode(g));
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="is_a_strong_cluster", key="", definition="static int is_a_strong_cluster(graph_t * g)")
private static boolean is_a_strong_cluster(Globals zz, ST_Agraph_s g) {
    boolean rv; //     int rv;
    CString str = agget(zz, g, new CString("compact")); //     char *str = agget(g, "compact");
    /* rv = mapBool((str), TRUE); */
    rv = mapBool((str), false); //     rv = mapBool((str), FALSE);
    return rv; //     return rv;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="rankset_kind", key="", definition="static int rankset_kind(graph_t * g)")
private static int rankset_kind(Globals zz, ST_Agraph_s g) {
    CString str = agget(zz, g, new CString("rank")); //     char *str = agget(g, "rank");
    if (str!=null && str.charAt(0)!='\0') { //     if (str && str[0]) {
	if (strcmp(str, new CString("min")) == 0) // 	if (!strcmp(str, "min"))
	    return MINRANK; // 	    return MINRANK;
	if (strcmp(str, new CString("source")) == 0) // 	if (!strcmp(str, "source"))
	    return SOURCERANK; // 	    return SOURCERANK;
	if (strcmp(str, new CString("max")) == 0) // 	if (!strcmp(str, "max"))
	    return MAXRANK; // 	    return MAXRANK;
	if (strcmp(str, new CString("sink")) == 0) // 	if (!strcmp(str, "sink"))
	    return SINKRANK; // 	    return SINKRANK;
	if (strcmp(str, new CString("same")) == 0) // 	if (!strcmp(str, "same"))
	    return SAMERANK; // 	    return SAMERANK;
    } //     }
    return NORANK; //     return NORANK;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="is_nonconstraint", key="", definition="static int is_nonconstraint(edge_t * e)")
private static boolean is_nonconstraint(Globals zz, ST_Agedge_s e) {
    CString constr; //     char *constr;
    if (zz.E_constr!=null && (constr = agxget(e, zz.E_constr))!=null) { //     if (E_constr && (constr = agxget(e, E_constr))) {
	if (constr.charAt(0)!='\0' && mapbool(constr) == false) // 	if (constr[0] && mapbool(constr) == FALSE)
	    return true; // 	    return TRUE;
    } //     }
    return false; //     return FALSE;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="find", key="", definition="static node_t *find(node_t * n)")
private static ST_Agnode_s find(ST_Agnode_s n) {
    ST_Agnode_s set; //     node_t *set;
    if ((set = ND_set(n))!=null) { //     if ((set = ND_set(n))) {
	if (set != n) { // 	if (set != n)
	    set = find(set); // 	    set = ND_set(n) = find(set);
	    ND_set(n, set);
	}
    } else { //     } else
	set = n; // 	set = ND_set(n) = n;
	ND_set(n, set);
    }
    return set; //     return set;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="union_one", key="", definition="static node_t *union_one(node_t * leader, node_t * n)")
private static ST_Agnode_s union_one(ST_Agnode_s leader, ST_Agnode_s n) {
    if (n!=null) { //     if (n)
	final ST_Agnode_s set = find(leader); // 	return (ND_set(find(n)) = find(leader));
	ND_set(find(n), set);
	return set;
    }
    else //     else
	return leader; // 	return leader;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="union_all", key="", definition="static node_t *union_all(graph_t * g)")
private static ST_Agnode_s union_all(Globals zz, ST_Agraph_s g) {
    ST_Agnode_s n, leader; //     node_t *n, *leader;
    n = agfstnode(zz, g); //     n = agfstnode(g);
    if (n == null) //     if (!n)
	return n; // 	return n;
    leader = find(n); //     leader = find(n);
    while ((n = agnxtnode(zz, g, n))!=null) //     while ((n = agnxtnode(g, n)))
	union_one(leader, n); // 	union_one(leader, n);
    return leader; //     return leader;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="compile_samerank", key="", definition="static void compile_samerank(graph_t * ug, graph_t * parent_clust)")
private static void compile_samerank(Globals zz, ST_Agraph_s ug, ST_Agraph_s parent_clust) {
    ST_Agraph_s s;			/* subgraph being scanned */ //     graph_t *s;
    ST_Agraph_s clust;		/* cluster that contains the rankset */ //     graph_t *clust;
    ST_Agnode_s n, leader; //     node_t *n, *leader;
    if (is_empty(zz, ug)) //     if (is_empty(ug))
	return; // 	return;
    if (is_a_cluster(zz, ug)) { //     if (is_a_cluster(ug)) {
	clust = ug; // 	clust = ug;
	if (parent_clust!=null) { // 	if (parent_clust) {
	    GD_level(ug, GD_level(parent_clust) + 1); // 	    GD_level(ug) = GD_level(parent_clust) + 1;
	    set_parent(zz, ug, parent_clust); // 	    set_parent(ug, parent_clust);
	} // 	}
	else // 	else
	    GD_level(ug, 0); // 	    GD_level(ug) = 0;
    } else //     } else
	clust = parent_clust; // 	clust = parent_clust;
    /* process subgraphs of this subgraph */
    for (s = agfstsubg(zz, ug); s!=null; s = agnxtsubg(zz, s)) //     for (s = agfstsubg(ug); s; s = agnxtsubg(s))
	compile_samerank(zz, s, clust); // 	compile_samerank(s, clust);
    /* process this subgraph as a cluster */
    if (is_a_cluster(zz, ug)) { //     if (is_a_cluster(ug)) {
	for (n = agfstnode(zz, ug); n!=null; n = agnxtnode(zz, ug, n)) { // 	for (n = agfstnode(ug); n; n = agnxtnode(ug, n)) {
	    if (ND_clust(n) == null) // 	    if (ND_clust(n) == 0)
		ND_clust(n, ug); // 		ND_clust(n) = ug;
	} // 	}
    } //     }
    /* process this subgraph as a rankset */
    switch (rankset_kind(zz, ug)) { //     switch (rankset_kind(ug)) {
    case SOURCERANK: //     case SOURCERANK:
	GD_has_sourcerank(clust, true);	/* fall through */ // 	GD_has_sourcerank(clust) = TRUE;
    case MINRANK: //     case MINRANK:
	leader = union_all(zz, ug); // 	leader = union_all(ug);
	GD_minrep(clust, union_one(leader, GD_minrep(clust))); // 	GD_minrep(clust) = union_one(leader, GD_minrep(clust));
	break; // 	break;
    case SINKRANK: //     case SINKRANK:
	GD_has_sinkrank(clust, true);	/* fall through */ // 	GD_has_sinkrank(clust) = TRUE;
    case MAXRANK: //     case MAXRANK:
	leader = union_all(zz, ug); // 	leader = union_all(ug);
	GD_maxrep(clust, union_one(leader, GD_maxrep(clust))); // 	GD_maxrep(clust) = union_one(leader, GD_maxrep(clust));
	break; // 	break;
    case SAMERANK: //     case SAMERANK:
	leader = union_all(zz, ug); // 	leader = union_all(ug);
	/* do we need to record these ranksets? */
	break; // 	break;
    case NORANK: //     case NORANK:
	break; // 	break;
    default:			/* unrecognized - warn and do nothing */ //     default:
	// 	agerr(AGWARN, "%s has unrecognized rank=%s", agnameof(ug), agget(ug, "rank"));
	break;
    } //     }
    /* a cluster may become degenerate */
    if (is_a_cluster(zz, ug) && GD_minrep(ug)!=null) { //     if (is_a_cluster(ug) && GD_minrep(ug)) {
	if (GD_minrep(ug) == GD_maxrep(ug)) { // 	if (GD_minrep(ug) == GD_maxrep(ug)) {
	    ST_Agnode_s up = union_all(zz, ug); // 	    node_t *up = union_all(ug);
	    GD_minrep(ug, up); // 	    GD_minrep(ug) = up;
	    GD_maxrep(ug, up); // 	    GD_maxrep(ug) = up;
	} // 	}
    } //     }
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="dot_lca", key="", definition="static graph_t *dot_lca(graph_t * c0, graph_t * c1)")
private static ST_Agraph_s dot_lca(ST_Agraph_s c0, ST_Agraph_s c1) {
    while (c0 != c1) { //     while (c0 != c1) {
	if (GD_level(c0) >= GD_level(c1)) // 	if (GD_level(c0) >= GD_level(c1))
	    c0 = (ST_Agraph_s) GD_parent(c0); // 	    c0 = GD_parent(c0);
	else // 	else
	    c1 = (ST_Agraph_s) GD_parent(c1); // 	    c1 = GD_parent(c1);
    } //     }
    return c0; //     return c0;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="is_internal_to_cluster", key="", definition="static int is_internal_to_cluster(edge_t * e)")
private static boolean is_internal_to_cluster(ST_Agedge_s e) {
    ST_Agraph_s par, ct, ch; //     graph_t *par, *ct, *ch;
    ct = ND_clust(agtail(e)); //     ct = ND_clust(agtail(e));
    ch = ND_clust(aghead(e)); //     ch = ND_clust(aghead(e));
    if (ct == ch) //     if (ct == ch)
	return true; // 	return TRUE;
    par = dot_lca(ct, ch); //     par = dot_lca(ct, ch);
    /* if (par == agroot(par)) */
	/* return FALSE; */
    if ((par == ct) || (par == ch)) //     if ((par == ct) || (par == ch))
	return true; // 	return TRUE;
    return false; //     return FALSE;
}

// The records of the constraint graph Xg were bound by a discipline in C
// (agpushdisc(Xg,&mydisc,infosizes), see my_init_node and my_init_edge): they
// are bound here when a node or an edge is created.
private static ST_Agedge_s agedge_Xg(Globals zz, ST_Agraph_s g, ST_Agnode_s t, ST_Agnode_s h) {
    final ST_Agedge_s e = agedge(zz, g, t, h, null, true); // agedge(g, t, h, 0, 1)
    if (e != null)
	agbindrec(zz, e, new CString("level edge rec"), new size_t(ZType.ST_Agedgeinfo_t), true); // my_init_edge
    return e;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="makeXnode", key="", definition="static node_t* makeXnode (graph_t* G, char* name)")
private static ST_Agnode_s makeXnode(Globals zz, ST_Agraph_s G, CString name) {
    ST_Agnode_s n = agnode(zz, G, name, true); //     node_t *n = agnode(G, name, 1);
    agbindrec(zz, n, new CString("level node rec"), new size_t(ZType.ST_Agnodeinfo_t), true); // my_init_node
    alloc_elist(4, ND_in(n)); //     alloc_elist(4, ND_in(n));
    alloc_elist(4, ND_out(n)); //     alloc_elist(4, ND_out(n));
    if (zz.Last_node!=null) { //     if (Last_node) {
	ND_prev(n, zz.Last_node); // 	ND_prev(n) = Last_node;
	ND_next(zz.Last_node, n); // 	ND_next(Last_node) = n;
    } else { //     } else {
	ND_prev(n, null); // 	ND_prev(n) = NULL;
	GD_nlist(G, n); // 	GD_nlist(G) = n;
    } //     }
    zz.Last_node = n; //     Last_node = n;
    ND_next(n, null); //     ND_next(n) = NULL;
    return n; //     return n;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="compile_nodes", key="", definition="static void compile_nodes(graph_t * g, graph_t * Xg)")
private static void compile_nodes(Globals zz, ST_Agraph_s g, ST_Agraph_s Xg) {
    /* build variables */
    ST_Agnode_s n; //     node_t *n;
    zz.Last_node = null; //     Last_node = NULL;
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	if (find(n) == n) // 	if (find(n) == n)
	    ND_rep(n, makeXnode (zz, Xg, agnameof(zz, n))); // 	    ND_rep(n) = makeXnode (Xg, agnameof(n));
    } //     }
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	if (ND_rep(n) == null) // 	if (ND_rep(n) == 0)
	    ND_rep(n, ND_rep(find(n))); // 	    ND_rep(n) = ND_rep(find(n));
    } //     }
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="merge", key="", definition="static void merge(edge_t * e, int minlen, int weight)")
private static void merge(ST_Agedge_s e, int minlen, int weight) {
    ED_minlen(e, Math.max(ED_minlen(e), minlen)); //     ED_minlen(e) = MAX(ED_minlen(e), minlen);
    ED_weight(e, ED_weight(e) + weight); //     ED_weight(e) += weight;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="strong", key="", definition="static void strong(graph_t * g, node_t * t, node_t * h, edge_t * orig)")
private static void strong(Globals zz, ST_Agraph_s g, ST_Agnode_s t, ST_Agnode_s h, ST_Agedge_s orig) {
    ST_Agedge_s e; //     edge_t *e;
    if ((e = agfindedge(zz, g, t, h))!=null || //     if ((e = agfindedge(g, t, h)) ||
	(e = agfindedge(zz, g, h, t))!=null || (e = agedge_Xg(zz, g, t, h))!=null) // 	(e = agfindedge(g, h, t)) || (e = agedge(g, t, h, 0, 1)))
	merge(e, ED_minlen(orig), ED_weight(orig)); // 	merge(e, ED_minlen(orig), ED_weight(orig));
    else //     else
	throw new IllegalStateException("ranking: failure to create strong constraint edge between nodes " // 	agerr(AGERR, "ranking: failure to create strong constraint edge between nodes %s and %s\n",
		+ agnameof(zz, t) + " and " + agnameof(zz, h)); // 	    agnameof(t), agnameof(h));
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="weak", key="", definition="static void weak(graph_t * g, node_t * t, node_t * h, edge_t * orig)")
private static void weak(Globals zz, ST_Agraph_s g, ST_Agnode_s t, ST_Agnode_s h, ST_Agedge_s orig) {
    ST_Agnode_s v; //     node_t *v;
    ST_Agedge_s e, f = null; //     edge_t *e, *f;
    for (e = agfstin(zz, g, t); e!=null; e = agnxtin(zz, g, e)) { //     for (e = agfstin(g, t); e; e = agnxtin(g, e)) {
	/* merge with existing weak edge (e,f) */
	v = agtail(e); // 	v = agtail(e);
	if ((f = agfstout(zz, g, v))!=null && (aghead(f) == h)) { // 	if ((f = agfstout(g, v)) && (aghead(f) == h)) {
	    return; // 	    return;
	} // 	}
    } //     }
    if (e == null) { //     if (!e) {
	final CString buf = new CString("_weak_" + (zz.weak_id++)); // 	sprintf (buf, "_weak_%d", id++);
	v = makeXnode(zz, g, buf); // 	v = makeXnode(g, buf);
	e = agedge_Xg(zz, g, v, t); // 	e = agedge(g, v, t, 0, 1);
	f = agedge_Xg(zz, g, v, h); // 	f = agedge(g, v, h, 0, 1);
    } //     }
    ED_minlen(e, Math.max(ED_minlen(e), 0));	/* effectively a nop */ //     ED_minlen(e) = MAX(ED_minlen(e), 0);
    ED_weight(e, ED_weight(e) + ED_weight(orig) * BACKWARD_PENALTY); //     ED_weight(e) += ED_weight(orig) * BACKWARD_PENALTY;
    ED_minlen(f, Math.max(ED_minlen(f), ED_minlen(orig))); //     ED_minlen(f) = MAX(ED_minlen(f), ED_minlen(orig));
    ED_weight(f, ED_weight(f) + ED_weight(orig)); //     ED_weight(f) += ED_weight(orig);
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="compile_edges", key="", definition="static void compile_edges(graph_t * ug, graph_t * Xg)")
private static void compile_edges(Globals zz, ST_Agraph_s ug, ST_Agraph_s Xg) {
    ST_Agnode_s n; //     node_t *n;
    ST_Agedge_s e; //     edge_t *e;
    ST_Agnode_s Xt, Xh; //     node_t *Xt, *Xh;
    ST_Agraph_s tc, hc; //     graph_t *tc, *hc;
    /* build edge constraints */
    for (n = agfstnode(zz, ug); n!=null; n = agnxtnode(zz, ug, n)) { //     for (n = agfstnode(ug); n; n = agnxtnode(ug, n)) {
	Xt = ND_rep(n); // 	Xt = ND_rep(n);
	for (e = agfstout(zz, ug, n); e!=null; e = agnxtout(zz, ug, e)) { // 	for (e = agfstout(ug, n); e; e = agnxtout(ug, e)) {
	    if (is_nonconstraint(zz, e)) // 	    if (is_nonconstraint(e))
		continue; // 		continue;
	    Xh = ND_rep(find(aghead(e))); // 	    Xh = ND_rep(find(aghead(e)));
	    if (Xt == Xh) // 	    if (Xt == Xh)
		continue; // 		continue;
	    tc = ND_clust(agtail(e)); // 	    tc = ND_clust(agtail(e));
	    hc = ND_clust(aghead(e)); // 	    hc = ND_clust(aghead(e));
	    if (is_internal_to_cluster(e)) { // 	    if (is_internal_to_cluster(e)) {
		/* determine if graph requires reversed edge */
		if ((find(agtail(e)) == GD_maxrep(ND_clust(agtail(e)))) // 		if ((find(agtail(e)) == GD_maxrep(ND_clust(agtail(e))))
		    || (find(aghead(e)) == GD_minrep(ND_clust(aghead(e))))) { // 		    || (find(aghead(e)) == GD_minrep(ND_clust(aghead(e))))) {
		    ST_Agnode_s temp = Xt; // 		    node_t *temp = Xt;
		    Xt = Xh; // 		    Xt = Xh;
		    Xh = temp; // 		    Xh = temp;
		} // 		}
		strong(zz, Xg, Xt, Xh, e); // 		strong(Xg, Xt, Xh, e);
	    } else { // 	    } else {
		if (is_a_strong_cluster(zz, tc) || is_a_strong_cluster(zz, hc)) // 		if (is_a_strong_cluster(tc) || is_a_strong_cluster(hc))
		    weak(zz, Xg, Xt, Xh, e); // 		    weak(Xg, Xt, Xh, e);
		else // 		else
		    strong(zz, Xg, Xt, Xh, e); // 		    strong(Xg, Xt, Xh, e);
	    } // 	    }
	} // 	}
    } //     }
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="compile_clusters", key="", definition="static void compile_clusters(graph_t* g, graph_t* Xg, node_t* top, node_t* bot)")
private static void compile_clusters(Globals zz, ST_Agraph_s g, ST_Agraph_s Xg, ST_Agnode_s top, ST_Agnode_s bot) {
    ST_Agnode_s n; //     node_t *n;
    ST_Agnode_s rep; //     node_t *rep;
    ST_Agedge_s e; //     edge_t *e;
    ST_Agraph_s sub; //     graph_t *sub;
    if (is_a_cluster(zz, g) && is_a_strong_cluster(zz, g)) { //     if (is_a_cluster(g) && is_a_strong_cluster(g)) {
	for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { // 	for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	    if (agfstin(zz, g, n) == null) { // 	    if (agfstin(g, n) == 0) {
		rep = ND_rep(find(n)); // 		rep = ND_rep(find(n));
		if (top == null) top = makeXnode(zz, Xg, TOPNODE); // 		if (!top) top = makeXnode(Xg,TOPNODE);
		agedge_Xg(zz, Xg, top, rep); // 		agedge(Xg, top, rep, 0, 1);
	    } // 	    }
	    if (agfstout(zz, g, n) == null) { // 	    if (agfstout(g, n) == 0) {
		rep = ND_rep(find(n)); // 		rep = ND_rep(find(n));
		if (bot == null)  bot = makeXnode(zz, Xg, BOTNODE); // 		if (!bot)  bot = makeXnode(Xg,BOTNODE);
		agedge_Xg(zz, Xg, rep, bot); // 		agedge(Xg, rep, bot, 0, 1);
	    } // 	    }
	} // 	}
	if (top!=null && bot!=null) { // 	if (top && bot) {
	    e = agedge_Xg(zz, Xg, top, bot); // 	    e = agedge(Xg, top, bot, 0, 1);
	    merge(e, 0, STRONG_CLUSTER_WEIGHT); // 	    merge(e, 0, STRONG_CLUSTER_WEIGHT);
	} // 	}
    } //     }
    for (sub = agfstsubg(zz, g); sub!=null; sub = agnxtsubg(zz, sub)) //     for (sub = agfstsubg(g); sub; sub = agnxtsubg(sub))
	compile_clusters(zz, sub, Xg, top, bot); // 	compile_clusters(sub, Xg, top, bot);
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="reverse_edge2", key="", definition="static void reverse_edge2(graph_t * g, edge_t * e)")
private static void reverse_edge2(Globals zz, ST_Agraph_s g, ST_Agedge_s e) {
    ST_Agedge_s rev; //     edge_t *rev;
    rev = agfindedge(zz, g, aghead(e), agtail(e)); //     rev = agfindedge(g, aghead(e), agtail(e));
    if (rev == null) //     if (!rev)
	rev = agedge_Xg(zz, g, aghead(e), agtail(e)); // 	rev = agedge(g, aghead(e), agtail(e), 0, 1);
    merge(rev, ED_minlen(e), ED_weight(e)); //     merge(rev, ED_minlen(e), ED_weight(e));
    agdeledge(zz, g, e); //     agdelete(g, e);
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="dfs", key="", definition="static void dfs(graph_t * g, node_t * v)")
private static void dfs(Globals zz, ST_Agraph_s g, ST_Agnode_s v) {
    ST_Agedge_s e, f; //     edge_t *e, *f;
    ST_Agnode_s w; //     node_t *w;
    if (ND_mark(v)!=0) //     if (ND_mark(v))
	return; // 	return;
    ND_mark(v, true); //     ND_mark(v) = TRUE;
    ND_onstack(v, true); //     ND_onstack(v) = TRUE;
    for (e = agfstout(zz, g, v); e!=null; e = f) { //     for (e = agfstout(g, v); e; e = f) {
	f = agnxtout(zz, g, e); // 	f = agnxtout(g, e);
	w = aghead(e); // 	w = aghead(e);
	if (ND_onstack(w)) // 	if (ND_onstack(w))
	    reverse_edge2(zz, g, e); // 	    reverse_edge2(g, e);
	else { // 	else {
	    if (ND_mark(w) == 0) // 	    if (ND_mark(w) == FALSE)
		dfs(zz, g, w); // 		dfs(g, w);
	} // 	}
    } //     }
    ND_onstack(v, false); //     ND_onstack(v) = FALSE;
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="break_cycles", key="", definition="static void break_cycles(graph_t * g)")
private static void break_cycles(Globals zz, ST_Agraph_s g) {
    ST_Agnode_s n; //     node_t *n;
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n))
	ND_mark(n, false); // 	ND_mark(n) = ND_onstack(n) = FALSE;
	ND_onstack(n, false);
    }
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) //     for (n = agfstnode(g); n; n = agnxtnode(g, n))
	dfs(zz, g, n); // 	dfs(g, n);
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="setMinMax", key="", definition="static void setMinMax (graph_t* g, int doRoot)")
private static void setMinMax(Globals zz, ST_Agraph_s g, boolean doRoot) {
    int c, v; //     int c, v;
    ST_Agnode_s n; //     node_t *n;
    ST_Agnode_s leader = null; //     node_t* leader;
      /* Do child clusters */
    for (c = 1; c <= GD_n_cluster(g); c++) //     for (c = 1; c <= GD_n_cluster(g); c++)
	    setMinMax(zz, GD_clust(g).get_(c), false); // 	    setMinMax(GD_clust(g)[c], 0);
    if (GD_parent(g) == null && !doRoot) // root graph //     if (!GD_parent(g) && !doRoot) // root graph
	return; // 	return;
    GD_minrank(g, MAXSHORT); //     GD_minrank(g) = MAXSHORT;
    GD_maxrank(g, -1); //     GD_maxrank(g) = -1;
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	v = ND_rank(n); // 	v = ND_rank(n);
	if (GD_maxrank(g) < v) // 	if (GD_maxrank(g) < v)
	    GD_maxrank(g, v); // 	    GD_maxrank(g) = v;
	if (GD_minrank(g) > v) { // 	if (GD_minrank(g) > v) {
	    GD_minrank(g, v); // 	    GD_minrank(g) = v;
	    leader = n; // 	    leader = n;
	} // 	}
    } //     }
    GD_leader(g, leader); //     GD_leader(g) = leader;
}

/* readout_levels:
 * Store node rank information in original graph.
 * Set rank bounds in graph and clusters
 * Free added data structures.
 *
 * rank2 is called with balance=1, which ensures that minrank=0
 */
@Original(version="2.38.0", path="lib/dotgen/rank.c", name="readout_levels", key="", definition="static void readout_levels(graph_t * g, graph_t * Xg, int ncc)")
private static void readout_levels(Globals zz, ST_Agraph_s g, ST_Agraph_s Xg, int ncc) {
    ST_Agnode_s n; //     node_t *n;
    ST_Agnode_s xn; //     node_t *xn;
    int[] minrk = null; //     int* minrk = NULL;
    boolean doRoot = false; //     int doRoot = 0;
    GD_minrank(g, MAXSHORT); //     GD_minrank(g) = MAXSHORT;
    GD_maxrank(g, -1); //     GD_maxrank(g) = -1;
    if (ncc > 1) { //     if (ncc > 1) {
	int i; // 	int i;
	minrk = new int[ncc+1]; // 	minrk = N_NEW(ncc+1,int);
	for (i = 1; i <= ncc; i++) // 	for (i = 1; i <= ncc; i++)
	    minrk[i] = MAXSHORT; // 	    minrk[i] = MAXSHORT;
    } //     }
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	xn = ND_rep(find(n)); // 	xn = ND_rep(find(n));
	ND_rank(n, ND_rank(xn)); // 	ND_rank(n) = ND_rank(xn);
	if (GD_maxrank(g) < ND_rank(n)) // 	if (GD_maxrank(g) < ND_rank(n))
	    GD_maxrank(g, ND_rank(n)); // 	    GD_maxrank(g) = ND_rank(n);
	if (GD_minrank(g) > ND_rank(n)) // 	if (GD_minrank(g) > ND_rank(n))
	    GD_minrank(g, ND_rank(n)); // 	    GD_minrank(g) = ND_rank(n);
	if (minrk!=null) { // 	if (minrk) {
	    ND_comp(n, ND_comp(xn)); // 	    ND_comp(n) = ND_comp(xn);
	    minrk[ND_comp(n)] = Math.min(minrk[ND_comp(n)],ND_rank(n)); // 	    minrk[ND_comp(n)] = MIN(minrk[ND_comp(n)],ND_rank(n));
	} // 	}
    } //     }
    if (minrk!=null) { //     if (minrk) {
	for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) // 	for (n = agfstnode(g); n; n = agnxtnode(g, n))
	    ND_rank(n, ND_rank(n) - minrk[ND_comp(n)]); // 	    ND_rank(n) -= minrk[ND_comp(n)];
	/* Non-uniform shifting, so recompute maxrank/minrank of root graph */
	doRoot = true; // 	doRoot = 1;
    } //     }
    else if (GD_minrank(g) > 0) {  /* should never happen */ //     else if (GD_minrank(g) > 0) {
	int delta = GD_minrank(g); // 	int delta = GD_minrank(g);
	for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) // 	for (n = agfstnode(g); n; n = agnxtnode(g, n))
	    ND_rank(n, ND_rank(n) - delta); // 	    ND_rank(n) -= delta;
	GD_minrank(g, GD_minrank(g) - delta); // 	GD_minrank(g) -= delta;
	GD_maxrank(g, GD_maxrank(g) - delta); // 	GD_maxrank(g) -= delta;
    } //     }
    setMinMax(zz, g, doRoot); //     setMinMax(g, doRoot);
    /* release fastgraph memory from Xg */
    for (n = agfstnode(zz, Xg); n!=null; n = agnxtnode(zz, Xg, n)) { //     for (n = agfstnode(Xg); n; n = agnxtnode(Xg, n)) {
	free_list(ND_in(n)); // 	free_list(ND_in(n));
	free_list(ND_out(n)); // 	free_list(ND_out(n));
    } //     }
    //     free(ND_alg(agfstnode(g)));
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	ND_alg(n, null); // 	ND_alg(n) = NULL;
    } //     }
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="dfscc", key="", definition="static void dfscc(graph_t * g, node_t * n, int cc)")
private static void dfscc(Globals zz, ST_Agraph_s g, ST_Agnode_s n, int cc) {
    ST_Agedge_s e; //     edge_t *e;
    if (ND_comp(n) == 0) { //     if (ND_comp(n) == 0) {
	ND_comp(n, cc); // 	ND_comp(n) = cc;
	for (e = agfstout(zz, g, n); e!=null; e = agnxtout(zz, g, e)) // 	for (e = agfstout(g, n); e; e = agnxtout(g, e))
	    dfscc(zz, g, aghead(e), cc); // 	    dfscc(g, aghead(e), cc);
	for (e = agfstin(zz, g, n); e!=null; e = agnxtin(zz, g, e)) // 	for (e = agfstin(g, n); e; e = agnxtin(g, e))
	    dfscc(zz, g, agtail(e), cc); // 	    dfscc(g, agtail(e), cc);
    } //     }
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="connect_components", key="", definition="static int connect_components(graph_t * g)")
private static int connect_components(Globals zz, ST_Agraph_s g) {
    int cc = 0; //     int cc = 0;
    ST_Agnode_s n; //     node_t *n;
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) //     for (n = agfstnode(g); n; n = agnxtnode(g, n))
	ND_comp(n, 0); // 	ND_comp(n) = 0;
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) //     for (n = agfstnode(g); n; n = agnxtnode(g, n))
	if (ND_comp(n) == 0) // 	if (ND_comp(n) == 0)
	    dfscc(zz, g, n, ++cc); // 	    dfscc(g, n, ++cc);
    if (cc > 1) { //     if (cc > 1) {
	ST_Agnode_s root = makeXnode(zz, g, ROOT); // 	node_t *root = makeXnode(g, ROOT);
	int ncc = 1; // 	int ncc = 1;
	for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { // 	for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	    if (ND_comp(n) == ncc) { // 	    if (ND_comp(n) == ncc) {
		agedge_Xg(zz, g, root, n); // 		(void) agedge(g, root, n, 0, 1);
		ncc++; // 		ncc++;
	    } // 	    }
	} // 	}
    } //     }
    return (cc); //     return (cc);
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="add_fast_edges", key="", definition="static void add_fast_edges (graph_t * g)")
private static void add_fast_edges(Globals zz, ST_Agraph_s g) {
    ST_Agnode_s n; //     node_t *n;
    ST_Agedge_s e; //     edge_t *e;
    for (n = agfstnode(zz, g); n!=null; n = agnxtnode(zz, g, n)) { //     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
	for (e = agfstout(zz, g, n); e!=null; e = agnxtout(zz, g, e)) { // 	for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
	    elist_append(e, ND_out(n)); // 	    elist_append(e, ND_out(n));
	    elist_append(e, ND_in(aghead(e))); // 	    elist_append(e, ND_in(aghead(e)));
	} // 	}
    } //     }
}

@Original(version="2.38.0", path="lib/dotgen/rank.c", name="dot2_rank", key="590k5zi3mrpwbc3lib0w3rmr2", definition="void dot2_rank(graph_t * g, aspect_t* asp)")
public static void dot2_rank(Globals zz, ST_Agraph_s g, ST_aspect_t asp) {
ENTERING("590k5zi3mrpwbc3lib0w3rmr2","dot2_rank");
try {
    int ssize; //     int ssize;
    int ncc, maxiter = Integer.MAX_VALUE; //     int ncc, maxiter = INT_MAX;
    CString s; //     char *s;
    ST_Agraph_s Xg; //     graph_t *Xg;
    zz.Last_node = null; //     Last_node = NULL;
    Xg = agopen(zz, new CString("level assignment constraints"), zz.Agstrictdirected, null); //     Xg = agopen("level assignment constraints", Agstrictdirected, 0);
    agbindrec(zz, Xg, new CString("level graph rec"), new size_t(ZType.ST_Agraphinfo_t), true); //     agbindrec(Xg,"level graph rec",sizeof(Agraphinfo_t),TRUE);
    //     agpushdisc(Xg,&mydisc,infosizes);
    // (the node and edge records are bound by makeXnode and agedge_Xg)
    edgelabel_ranks(zz, g); //     edgelabel_ranks(g);
    if ((s = agget(zz, g, new CString("nslimit1")))!=null) //     if ((s = agget(g, "nslimit1")))
	maxiter = (int) (atof(s) * agnnodes(g)); // 	maxiter = atof(s) * agnnodes(g);
    else //     else
	maxiter = Integer.MAX_VALUE; // 	maxiter = INT_MAX;
    compile_samerank(zz, g, null); //     compile_samerank(g, 0);
    compile_nodes(zz, g, Xg); //     compile_nodes(g, Xg);
    compile_edges(zz, g, Xg); //     compile_edges(g, Xg);
    compile_clusters(zz, g, Xg, null, null); //     compile_clusters(g, Xg, 0, 0);
    break_cycles(zz, Xg); //     break_cycles(Xg);
    ncc = connect_components(zz, Xg); //     ncc = connect_components(Xg);
    add_fast_edges (zz, Xg); //     add_fast_edges (Xg);
    if (asp!=null) { //     if (asp) {
UNSUPPORTED("8ow3lzc6gh107g9bcn4szm7hj"); // 	init_UF_size(Xg);
UNSUPPORTED("9503vlimf1i2zv76ua88ooepc"); // 	initEdgeTypes(Xg);
    } //     }
    if ((s = agget(zz, g, new CString("searchsize")))!=null) //     if ((s = agget(g, "searchsize")))
	ssize = atoi(s); // 	ssize = atoi(s);
    else //     else
	ssize = -1; // 	ssize = -1;
    rank2(zz, Xg, 1, maxiter, ssize); //     rank2(Xg, 1, maxiter, ssize);
/* fastgr(Xg); */
    readout_levels(zz, g, Xg, ncc); //     readout_levels(g, Xg, ncc);
    //     agclose(Xg);
    // (Xg is left to the garbage collector)
} finally {
LEAVING("590k5zi3mrpwbc3lib0w3rmr2","dot2_rank");
}
}



}