private static int countRunAndMakeAscending(int[] a, int lo, int hi) {
        if (lo == hi) {
            return 1;
        }
        int runHi = lo + 1;
        if (runHi == hi)
            return 2;
        // Find end of run, and reverse range if descending
        if (a[runHi++] < a[lo]) { // Descending
            while (runHi < hi && a[runHi] < a[runHi - 1])
                runHi++;
            reverseRange(a, lo, runHi);
        } else {                              // Ascending
            while (runHi < hi && a[runHi] >= a[runHi - 1])
                runHi++;
        }

        return runHi - lo;
    }