public static int compare(Variable v1, Variable v2) {

		if ((v1 instanceof Parameter) && (v2 instanceof Parameter)) {
			// All dynamic/unmapped variables should be parameters
			return ((Parameter) v1).getOrdinal() - ((Parameter) v2).getOrdinal();
		}
		int diff = getPrecedence(v1) - getPrecedence(v2);
		if (diff != 0) {
			return diff;
		}
		//
		VariableStorage otherStorage = v2.getVariableStorage();
		VariableStorage variableStorage = v1.getVariableStorage();

		// null storage should never occur

		if (v1.isStackVariable() && v2.isStackVariable()) {
			// For some reason we like to reverse the natural order of stack variable addresses
			diff = v2.getStackOffset() - v1.getStackOffset();
			if (diff != 0) {
				return diff;
			}
		}

		diff = v1.getFirstUseOffset() - v2.getFirstUseOffset();
		if (diff != 0) {
			// give precedence to 0 first-use-offset
			if (v1.getFirstUseOffset() == 0) {
				return -1;
			}
			if (v2.getFirstUseOffset() == 0) {
				return 1;
			}
			return diff;
		}

		return variableStorage.compareTo(otherStorage);
	}
Compare two variables without using the instance specific compareTo method.
@param v1 a function variable
@param v2 another function variable
@return a negative value if v1 &lt; v2, 0 if equal, and
positive if v1 &gt; v2
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/listing/VariableUtilities.java