package de.kauker.unofficial.grocy.utils

import java.util.*

fun String.distanceTo(c: String): Double {
    return similarity(this, c)
}

fun similarity(s1: String, s2: String): Double {
    var longer = s1
    var shorter = s2
    if (s1.length < s2.length) { // longer should always have greater length
        longer = s2
        shorter = s1
    }
    val longerLength = longer.length
    return if (longerLength == 0) {
        1.0 /* both strings are zero length */
    } else (longerLength - editDistance(longer, shorter)) / longerLength.toDouble()
}

fun editDistance(is1: String, is2: String): Int {
    var s1 = is1
    var s2 = is2
    s1 = s1.lowercase(Locale.getDefault())
    s2 = s2.lowercase(Locale.getDefault())
    val costs = IntArray(s2.length + 1)
    for (i in 0..s1.length) {
        var lastValue = i
        for (j in 0..s2.length) {
            if (i == 0) costs[j] = j else {
                if (j > 0) {
                    var newValue = costs[j - 1]
                    if (s1[i - 1] != s2[j - 1]) newValue = Math.min(
                        Math.min(newValue, lastValue),
                        costs[j]
                    ) + 1
                    costs[j - 1] = lastValue
                    lastValue = newValue
                }
            }
        }
        if (i > 0) costs[s2.length] = lastValue
    }
    return costs[s2.length]
}

Compiled from "StringUtils.kt"
public final class de.kauker.unofficial.grocy.utils.StringUtilsKt {
  public static final double distanceTo(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String c
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #20                 // Method similarity:(Ljava/lang/String;Ljava/lang/String;)D
      17: dreturn

  public static final double similarity(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #24                 // String s1
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #26                 // String s2
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: astore_2
      14: aload_1
      15: astore_3
      16: aload_0
      17: invokevirtual #32                 // Method java/lang/String.length:()I
      20: aload_1
      21: invokevirtual #32                 // Method java/lang/String.length:()I
      24: if_icmpge     31
      27: aload_1
      28: astore_2
      29: aload_0
      30: astore_3
      31: aload_2
      32: invokevirtual #32                 // Method java/lang/String.length:()I
      35: istore        4
      37: iload         4
      39: ifne          46
      42: dconst_1
      43: goto          59
      46: iload         4
      48: aload_2
      49: aload_3
      50: invokestatic  #36                 // Method editDistance:(Ljava/lang/String;Ljava/lang/String;)I
      53: isub
      54: i2d
      55: iload         4
      57: i2d
      58: ddiv
      59: dreturn

  public static final int editDistance(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #42                 // String is1
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #44                 // String is2
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: astore_2
      14: aload_1
      15: astore_3
      16: aload_2
      17: astore        4
      19: invokestatic  #50                 // Method java/util/Locale.getDefault:()Ljava/util/Locale;
      22: dup
      23: ldc           #52                 // String getDefault(...)
      25: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      28: aload         4
      30: swap
      31: invokevirtual #59                 // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
      34: dup
      35: ldc           #61                 // String toLowerCase(...)
      37: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      40: astore_2
      41: aload_3
      42: astore        4
      44: invokestatic  #50                 // Method java/util/Locale.getDefault:()Ljava/util/Locale;
      47: dup
      48: ldc           #52                 // String getDefault(...)
      50: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      53: aload         4
      55: swap
      56: invokevirtual #59                 // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
      59: dup
      60: ldc           #61                 // String toLowerCase(...)
      62: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      65: astore_3
      66: aload_3
      67: invokevirtual #32                 // Method java/lang/String.length:()I
      70: iconst_1
      71: iadd
      72: newarray       int
      74: astore        4
      76: iconst_0
      77: istore        5
      79: aload_2
      80: invokevirtual #32                 // Method java/lang/String.length:()I
      83: istore        6
      85: iload         5
      87: iload         6
      89: if_icmpgt     232
      92: iload         5
      94: istore        7
      96: iconst_0
      97: istore        8
      99: aload_3
     100: invokevirtual #32                 // Method java/lang/String.length:()I
     103: istore        9
     105: iload         8
     107: iload         9
     109: if_icmpgt     205
     112: iload         5
     114: ifne          127
     117: aload         4
     119: iload         8
     121: iload         8
     123: iastore
     124: goto          192
     127: iload         8
     129: ifle          192
     132: aload         4
     134: iload         8
     136: iconst_1
     137: isub
     138: iaload
     139: istore        10
     141: aload_2
     142: iload         5
     144: iconst_1
     145: isub
     146: invokevirtual #65                 // Method java/lang/String.charAt:(I)C
     149: aload_3
     150: iload         8
     152: iconst_1
     153: isub
     154: invokevirtual #65                 // Method java/lang/String.charAt:(I)C
     157: if_icmpeq     179
     160: iload         10
     162: iload         7
     164: invokestatic  #71                 // Method java/lang/Math.min:(II)I
     167: aload         4
     169: iload         8
     171: iaload
     172: invokestatic  #71                 // Method java/lang/Math.min:(II)I
     175: iconst_1
     176: iadd
     177: istore        10
     179: aload         4
     181: iload         8
     183: iconst_1
     184: isub
     185: iload         7
     187: iastore
     188: iload         10
     190: istore        7
     192: iload         8
     194: iload         9
     196: if_icmpeq     205
     199: iinc          8, 1
     202: goto          112
     205: iload         5
     207: ifle          219
     210: aload         4
     212: aload_3
     213: invokevirtual #32                 // Method java/lang/String.length:()I
     216: iload         7
     218: iastore
     219: iload         5
     221: iload         6
     223: if_icmpeq     232
     226: iinc          5, 1
     229: goto          92
     232: aload         4
     234: aload_3
     235: invokevirtual #32                 // Method java/lang/String.length:()I
     238: iaload
     239: ireturn
}


package com.problemsolver.androidplayground.utils

import java.util.*

object SortAlgorithm {

    /**
     * TIME COMPLEXITY
     * Best : Ω(n)
     * Average : Θ(n^2)
     * Worst : O(n^2)
     * */
    fun <T : Comparable<T>> bubbleSort(array: List<T>, asc: Boolean = true) {
        val length = array.size - 1
        var count = 0

        if (asc) {
            while (count < length) {
                for (i in 0 until length) {
                    if (array[i] > array[i + 1]) {
                        Collections.swap(array, i, i + 1)
                        count = 0
                        break
                    } else {
                        count++
                    }
                }
            }
        } else {
            while (count < length) {
                for (i in 0 until length) {
                    if (array[i] < array[i + 1]) {
                        Collections.swap(array, i, i + 1)
                        count = 0
                        break
                    } else {
                        count++
                    }
                }
            }
        }
    }

    /**
     * TIME COMPLEXITY
     * Best : Ω(n^2)
     * Average : Θ(n^2)
     * Worst : O(n^2)
     * */
    fun <T : Comparable<T>> selectionSort(array: List<T>, asc: Boolean = true) {
        for (i in 0..array.size - 2) {
            var pointer = i
            for (j in (i + 1) until array.size) {
                if (asc) {
                    if (array[pointer] > array[j]) {
                        pointer = j
                    }
                } else {
                    if (array[pointer] < array[j]) {
                        pointer = j
                    }
                }
            }

            if (asc) {
                if (array[pointer] < array[i]) {
                    Collections.swap(array, i, pointer)
                }
            } else {
                if (array[pointer] > array[i]) {
                    Collections.swap(array, i, pointer)
                }
            }
        }
    }

    /**
     * TIME COMPLEXITY
     * Best : Ω(n log(n))
     * Average : Θ(n log(n))
     * Worst : O(n^2)
     * */
    fun <T : Comparable<T>> quickSort(array: List<T>, l: Int, r: Int) {
        if (l < r) {
            val p = partition(array, l, r)
            quickSort(array, l, p - 1)
            quickSort(array, p, r)
        }
    }

    private fun <T : Comparable<T>> partition(array: List<T>, l: Int, r: Int): Int {
        var left = l
        var right = r
        val mid = (left + right) / 2
        val pivot = array[mid]

        while (left <= right) {
            while (array[left] < pivot) {
                left++
            }

            while (array[right] > pivot) {
                right--
            }

            if (left <= right) {
                Collections.swap(array, left, right)
                left++
                right--
            }
        }

        return left
    }

    /**
     * TIME COMPLEXITY
     * Best : Ω(n log(n))
     * Average : Θ(n log(n))
     * Worst : O(n log(n))
     * */
    fun <T : Comparable<T>> mergeSort(array: Array<T>, l: Int, r: Int) {
        if (l >= r) return
        val mid = (l + r) / 2
        val temp = arrayOfNulls<Comparable<T>>(array.size)

        mergeSort(array, l, mid)
        mergeSort(array, mid + 1, r)
        mergeHalves(array, temp, l, r)
    }

    private fun <T : Comparable<T>> mergeHalves(
        array: Array<T>,
        temp: Array<Comparable<T>?>,
        leftStart: Int,
        rightEnd: Int
    ) {
        val leftEnd = (leftStart + rightEnd) / 2
        val rightStart = leftEnd + 1
        val size = rightEnd - leftStart + 1

        var left = leftStart
        var index = leftStart
        var right = rightStart

        while (left <= leftEnd && right <= rightEnd) {
            if (array[left] < array[right]) {
                temp[index] = array[left]
                left++
            } else {
                temp[index] = array[right]
                right++
            }

            index++
        }

        System.arraycopy(array, left, temp, index, leftEnd - left + 1)
        System.arraycopy(array, right, temp, index, rightEnd - right + 1)
        System.arraycopy(temp, leftStart, array, leftStart, size)
    }
}

Compiled from "SortAlgorithm.kt"
public final class com.problemsolver.androidplayground.utils.SortAlgorithm {
  public static final com.problemsolver.androidplayground.utils.SortAlgorithm INSTANCE;

  private com.problemsolver.androidplayground.utils.SortAlgorithm();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final <T extends java.lang.Comparable<? super T>> void bubbleSort(java.util.List<? extends T>, boolean);
    Code:
       0: aload_1
       1: ldc           #16                 // String array
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      12: iconst_1
      13: isub
      14: istore_3
      15: iconst_0
      16: istore        4
      18: iload_2
      19: ifeq          91
      22: iload         4
      24: iload_3
      25: if_icmpge     160
      28: iconst_0
      29: istore        5
      31: iload         5
      33: iload_3
      34: if_icmpge     22
      37: aload_1
      38: iload         5
      40: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      45: checkcast     #34                 // class java/lang/Comparable
      48: aload_1
      49: iload         5
      51: iconst_1
      52: iadd
      53: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      58: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
      63: ifle          82
      66: aload_1
      67: iload         5
      69: iload         5
      71: iconst_1
      72: iadd
      73: invokestatic  #44                 // Method java/util/Collections.swap:(Ljava/util/List;II)V
      76: iconst_0
      77: istore        4
      79: goto          22
      82: iinc          4, 1
      85: iinc          5, 1
      88: goto          31
      91: iload         4
      93: iload_3
      94: if_icmpge     160
      97: iconst_0
      98: istore        5
     100: iload         5
     102: iload_3
     103: if_icmpge     91
     106: aload_1
     107: iload         5
     109: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     114: checkcast     #34                 // class java/lang/Comparable
     117: aload_1
     118: iload         5
     120: iconst_1
     121: iadd
     122: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     127: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     132: ifge          151
     135: aload_1
     136: iload         5
     138: iload         5
     140: iconst_1
     141: iadd
     142: invokestatic  #44                 // Method java/util/Collections.swap:(Ljava/util/List;II)V
     145: iconst_0
     146: istore        4
     148: goto          91
     151: iinc          4, 1
     154: iinc          5, 1
     157: goto          100
     160: return

  public static void bubbleSort$default(com.problemsolver.androidplayground.utils.SortAlgorithm, java.util.List, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_1
       7: istore_2
       8: aload_0
       9: aload_1
      10: iload_2
      11: invokevirtual #55                 // Method bubbleSort:(Ljava/util/List;Z)V
      14: return

  public final <T extends java.lang.Comparable<? super T>> void selectionSort(java.util.List<? extends T>, boolean);
    Code:
       0: aload_1
       1: ldc           #16                 // String array
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: aload_1
       9: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      14: iconst_2
      15: isub
      16: istore        4
      18: iload_3
      19: iload         4
      21: if_icmpgt     207
      24: iload_3
      25: istore        5
      27: iload_3
      28: iconst_1
      29: iadd
      30: istore        6
      32: aload_1
      33: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      38: istore        7
      40: iload         6
      42: iload         7
      44: if_icmpge     122
      47: iload_2
      48: ifeq          85
      51: aload_1
      52: iload         5
      54: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #34                 // class java/lang/Comparable
      62: aload_1
      63: iload         6
      65: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      70: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
      75: ifle          116
      78: iload         6
      80: istore        5
      82: goto          116
      85: aload_1
      86: iload         5
      88: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      93: checkcast     #34                 // class java/lang/Comparable
      96: aload_1
      97: iload         6
      99: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     104: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     109: ifge          116
     112: iload         6
     114: istore        5
     116: iinc          6, 1
     119: goto          40
     122: iload_2
     123: ifeq          162
     126: aload_1
     127: iload         5
     129: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #34                 // class java/lang/Comparable
     137: aload_1
     138: iload_3
     139: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     144: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     149: ifge          195
     152: aload_1
     153: iload_3
     154: iload         5
     156: invokestatic  #44                 // Method java/util/Collections.swap:(Ljava/util/List;II)V
     159: goto          195
     162: aload_1
     163: iload         5
     165: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     170: checkcast     #34                 // class java/lang/Comparable
     173: aload_1
     174: iload_3
     175: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     180: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     185: ifle          195
     188: aload_1
     189: iload_3
     190: iload         5
     192: invokestatic  #44                 // Method java/util/Collections.swap:(Ljava/util/List;II)V
     195: iload_3
     196: iload         4
     198: if_icmpeq     207
     201: iinc          3, 1
     204: goto          24
     207: return

  public static void selectionSort$default(com.problemsolver.androidplayground.utils.SortAlgorithm, java.util.List, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_1
       7: istore_2
       8: aload_0
       9: aload_1
      10: iload_2
      11: invokevirtual #61                 // Method selectionSort:(Ljava/util/List;Z)V
      14: return

  public final <T extends java.lang.Comparable<? super T>> void quickSort(java.util.List<? extends T>, int, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String array
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_2
       7: iload_3
       8: if_icmpge     38
      11: aload_0
      12: aload_1
      13: iload_2
      14: iload_3
      15: invokespecial #67                 // Method partition:(Ljava/util/List;II)I
      18: istore        4
      20: aload_0
      21: aload_1
      22: iload_2
      23: iload         4
      25: iconst_1
      26: isub
      27: invokevirtual #69                 // Method quickSort:(Ljava/util/List;II)V
      30: aload_0
      31: aload_1
      32: iload         4
      34: iload_3
      35: invokevirtual #69                 // Method quickSort:(Ljava/util/List;II)V
      38: return

  private final <T extends java.lang.Comparable<? super T>> int partition(java.util.List<? extends T>, int, int);
    Code:
       0: iload_2
       1: istore        4
       3: iload_3
       4: istore        5
       6: iload         4
       8: iload         5
      10: iadd
      11: iconst_2
      12: idiv
      13: istore        6
      15: aload_1
      16: iload         6
      18: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      23: checkcast     #34                 // class java/lang/Comparable
      26: astore        7
      28: iload         4
      30: iload         5
      32: if_icmpgt     113
      35: aload_1
      36: iload         4
      38: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      43: checkcast     #34                 // class java/lang/Comparable
      46: aload         7
      48: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
      53: ifge          62
      56: iinc          4, 1
      59: goto          35
      62: aload_1
      63: iload         5
      65: invokeinterface #32,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      70: checkcast     #34                 // class java/lang/Comparable
      73: aload         7
      75: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
      80: ifle          89
      83: iinc          5, -1
      86: goto          62
      89: iload         4
      91: iload         5
      93: if_icmpgt     28
      96: aload_1
      97: iload         4
      99: iload         5
     101: invokestatic  #44                 // Method java/util/Collections.swap:(Ljava/util/List;II)V
     104: iinc          4, 1
     107: iinc          5, -1
     110: goto          28
     113: iload         4
     115: ireturn

  public final <T extends java.lang.Comparable<? super T>> void mergeSort(T[], int, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String array
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_2
       7: iload_3
       8: if_icmplt     12
      11: return
      12: iload_2
      13: iload_3
      14: iadd
      15: iconst_2
      16: idiv
      17: istore        4
      19: aload_1
      20: arraylength
      21: anewarray     #34                 // class java/lang/Comparable
      24: astore        5
      26: aload_0
      27: aload_1
      28: iload_2
      29: iload         4
      31: invokevirtual #83                 // Method mergeSort:([Ljava/lang/Comparable;II)V
      34: aload_0
      35: aload_1
      36: iload         4
      38: iconst_1
      39: iadd
      40: iload_3
      41: invokevirtual #83                 // Method mergeSort:([Ljava/lang/Comparable;II)V
      44: aload_0
      45: aload_1
      46: aload         5
      48: iload_2
      49: iload_3
      50: invokespecial #87                 // Method mergeHalves:([Ljava/lang/Comparable;[Ljava/lang/Comparable;II)V
      53: return

  private final <T extends java.lang.Comparable<? super T>> void mergeHalves(T[], java.lang.Comparable<T>[], int, int);
    Code:
       0: iload_3
       1: iload         4
       3: iadd
       4: iconst_2
       5: idiv
       6: istore        5
       8: iload         5
      10: iconst_1
      11: iadd
      12: istore        6
      14: iload         4
      16: iload_3
      17: isub
      18: iconst_1
      19: iadd
      20: istore        7
      22: iload_3
      23: istore        8
      25: iload_3
      26: istore        9
      28: iload         6
      30: istore        10
      32: iload         8
      34: iload         5
      36: if_icmpgt     93
      39: iload         10
      41: iload         4
      43: if_icmpgt     93
      46: aload_1
      47: iload         8
      49: aaload
      50: aload_1
      51: iload         10
      53: aaload
      54: invokeinterface #38,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
      59: ifge          76
      62: aload_2
      63: iload         9
      65: aload_1
      66: iload         8
      68: aaload
      69: aastore
      70: iinc          8, 1
      73: goto          87
      76: aload_2
      77: iload         9
      79: aload_1
      80: iload         10
      82: aaload
      83: aastore
      84: iinc          10, 1
      87: iinc          9, 1
      90: goto          32
      93: aload_1
      94: iload         8
      96: aload_2
      97: iload         9
      99: iload         5
     101: iload         8
     103: isub
     104: iconst_1
     105: iadd
     106: invokestatic  #96                 // Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V
     109: aload_1
     110: iload         10
     112: aload_2
     113: iload         9
     115: iload         4
     117: iload         10
     119: isub
     120: iconst_1
     121: iadd
     122: invokestatic  #96                 // Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V
     125: aload_2
     126: iload_3
     127: aload_1
     128: iload_3
     129: iload         7
     131: invokestatic  #96                 // Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V
     134: return

  static {};
    Code:
       0: new           #2                  // class com/problemsolver/androidplayground/utils/SortAlgorithm
       3: dup
       4: invokespecial #104                // Method "<init>":()V
       7: putstatic     #107                // Field INSTANCE:Lcom/problemsolver/androidplayground/utils/SortAlgorithm;
      10: return
}


package shmp.utils

import kotlin.math.max
import kotlin.math.pow

/**
 * Adds right text to the left text. right text will be lined up with
 * consideration to longest line from the left text.
 *
 * @param guarantiedLength if left fragment is already has equal length of lines.
 * @return left and right text merged in one.
 */
fun addToRight(left: String, right: String, guarantiedLength: Boolean): StringBuilder {
    if (left.isEmpty())
        return StringBuilder(right)

    val stringBuilder = StringBuilder()
    val lineLength: Int = (left.lines().map { it.length }.maxOrNull() ?: 0) + 4
    val linesAmount = max(left.lines().count(), right.lines().count())
    val list1 = left.lines() + ((0 until linesAmount - left.lines().size).map { "" })
    val list2 = right.lines() + ((0 until linesAmount - right.lines().size).map { "" })

    for (i in 0 until linesAmount) {
        val ss1 = list1[i]
        val ss2 = list2[i]
        stringBuilder
                .append(ss1)
                .append(" ".repeat(if (guarantiedLength) 4 else lineLength - ss1.length))
                .append(ss2)
        if (i != linesAmount - 1)
            stringBuilder.append("\n")
    }

    return stringBuilder
}

fun addToRight(left: StringBuilder, right: StringBuilder, guarantiedLength: Boolean) =
        addToRight(left.toString(), right.toString(), guarantiedLength)

/**
 * Edits text via carrying lines which are longer than size.
 * @param text text which will be edited.
 * @param size maximal acceptable length of a line.
 * @return edited text, each line in it is not longer than size. Words can be cut in the middle.
 */
fun chompToSize(text: String, size: Int): StringBuilder {
    val stringBuilder = StringBuilder()

    for (_line in text.lines()) {
        var line = _line
        while (line.isNotEmpty())
            if (size >= line.length) {
                stringBuilder.append(line)
                break
            } else {
                var part = line.substring(0, size)
                if (part.lastIndexOf(" ") != -1) {
                    line = line.substring(part.lastIndexOf(" ") + 1)
                    part = (if (part.lastIndexOf(" ") == 0)
                        part.substring(1)
                    else
                        part.substring(0, part.lastIndexOf(" ")))
                } else
                    line = line.substring(size)
                stringBuilder.append(part).append("\n")
            }
        stringBuilder.append("\n")
    }

    return stringBuilder
}

/**
 * Edits text via adding lines after size + 1 recursively to the right.
 * @param text text which will be modified.
 * @param size maximal acceptable number of lines.
 * @return edited text, has no more than size lines, greater lines added to the right.
 */
fun chompToLines(text: String, size: Int): StringBuilder {
    val prefix = text.lines().take(size).joinToString("\n")
    val postfix = text.lines().drop(size).joinToString("\n")

    if (postfix == "")
        return java.lang.StringBuilder(prefix)

    return addToRight(
            prefix,
            chompToLines(postfix, size).toString(),
            false
    )

}

fun chompToLines(text: StringBuilder, size: Int) = chompToLines(text.toString(), size)

fun getTruncated(t: Double, signs: Int) = 10.0.pow(signs).toInt().let { p ->
    (t * p).toInt().toDouble() / p
}.toString()

fun <E> E.addLinePrefix(prefix: String = "    ") = this.toString().lines()
        .joinToString("\n") { prefix + it }

Compiled from "OutputFun.kt"
public final class shmp.utils.OutputFunKt {
  public static final java.lang.StringBuilder addToRight(java.lang.String, java.lang.String, boolean);
    Code:
       0: aload_0
       1: ldc           #9                  // String left
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String right
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #19                 // class java/lang/CharSequence
      16: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      21: ifne          28
      24: iconst_1
      25: goto          29
      28: iconst_0
      29: ifeq          41
      32: new           #25                 // class java/lang/StringBuilder
      35: dup
      36: aload_1
      37: invokespecial #29                 // Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
      40: areturn
      41: new           #25                 // class java/lang/StringBuilder
      44: dup
      45: invokespecial #32                 // Method java/lang/StringBuilder."<init>":()V
      48: astore_3
      49: aload_0
      50: checkcast     #19                 // class java/lang/CharSequence
      53: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      56: checkcast     #40                 // class java/lang/Iterable
      59: astore        6
      61: iconst_0
      62: istore        7
      64: aload         6
      66: astore        8
      68: new           #42                 // class java/util/ArrayList
      71: dup
      72: aload         6
      74: bipush        10
      76: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      79: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
      82: checkcast     #53                 // class java/util/Collection
      85: astore        9
      87: iconst_0
      88: istore        10
      90: aload         8
      92: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      97: astore        11
      99: aload         11
     101: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     106: ifeq          152
     109: aload         11
     111: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     116: astore        12
     118: aload         9
     120: aload         12
     122: checkcast     #69                 // class java/lang/String
     125: astore        13
     127: astore        17
     129: iconst_0
     130: istore        14
     132: aload         13
     134: invokevirtual #70                 // Method java/lang/String.length:()I
     137: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     140: aload         17
     142: swap
     143: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: goto          99
     152: aload         9
     154: checkcast     #82                 // class java/util/List
     157: nop
     158: checkcast     #40                 // class java/lang/Iterable
     161: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.maxOrNull:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     164: checkcast     #72                 // class java/lang/Integer
     167: dup
     168: ifnull        177
     171: invokevirtual #89                 // Method java/lang/Integer.intValue:()I
     174: goto          179
     177: pop
     178: iconst_0
     179: iconst_4
     180: iadd
     181: istore        4
     183: nop
     184: aload_0
     185: checkcast     #19                 // class java/lang/CharSequence
     188: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     191: checkcast     #53                 // class java/util/Collection
     194: invokeinterface #92,  1           // InterfaceMethod java/util/Collection.size:()I
     199: aload_1
     200: checkcast     #19                 // class java/lang/CharSequence
     203: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     206: checkcast     #53                 // class java/util/Collection
     209: invokeinterface #92,  1           // InterfaceMethod java/util/Collection.size:()I
     214: invokestatic  #98                 // Method java/lang/Math.max:(II)I
     217: istore        5
     219: aload_0
     220: checkcast     #19                 // class java/lang/CharSequence
     223: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     226: checkcast     #53                 // class java/util/Collection
     229: iconst_0
     230: iload         5
     232: aload_0
     233: checkcast     #19                 // class java/lang/CharSequence
     236: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     239: invokeinterface #99,  1           // InterfaceMethod java/util/List.size:()I
     244: isub
     245: invokestatic  #105                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     248: checkcast     #40                 // class java/lang/Iterable
     251: astore        7
     253: astore        17
     255: iconst_0
     256: istore        8
     258: aload         7
     260: astore        9
     262: new           #42                 // class java/util/ArrayList
     265: dup
     266: aload         7
     268: bipush        10
     270: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     273: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     276: checkcast     #53                 // class java/util/Collection
     279: astore        10
     281: iconst_0
     282: istore        11
     284: aload         9
     286: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     291: astore        12
     293: aload         12
     295: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     300: ifeq          338
     303: aload         12
     305: checkcast     #107                // class kotlin/collections/IntIterator
     308: invokevirtual #110                // Method kotlin/collections/IntIterator.nextInt:()I
     311: istore        13
     313: aload         10
     315: iload         13
     317: istore        14
     319: astore        18
     321: iconst_0
     322: istore        15
     324: ldc           #112                // String
     326: aload         18
     328: swap
     329: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     334: pop
     335: goto          293
     338: aload         10
     340: checkcast     #82                 // class java/util/List
     343: nop
     344: aload         17
     346: swap
     347: checkcast     #40                 // class java/lang/Iterable
     350: invokestatic  #116                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     353: astore        6
     355: aload_1
     356: checkcast     #19                 // class java/lang/CharSequence
     359: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     362: checkcast     #53                 // class java/util/Collection
     365: iconst_0
     366: iload         5
     368: aload_1
     369: checkcast     #19                 // class java/lang/CharSequence
     372: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     375: invokeinterface #99,  1           // InterfaceMethod java/util/List.size:()I
     380: isub
     381: invokestatic  #105                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     384: checkcast     #40                 // class java/lang/Iterable
     387: astore        8
     389: astore        17
     391: iconst_0
     392: istore        9
     394: aload         8
     396: astore        10
     398: new           #42                 // class java/util/ArrayList
     401: dup
     402: aload         8
     404: bipush        10
     406: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     409: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     412: checkcast     #53                 // class java/util/Collection
     415: astore        11
     417: iconst_0
     418: istore        12
     420: aload         10
     422: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     427: astore        13
     429: aload         13
     431: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     436: ifeq          474
     439: aload         13
     441: checkcast     #107                // class kotlin/collections/IntIterator
     444: invokevirtual #110                // Method kotlin/collections/IntIterator.nextInt:()I
     447: istore        14
     449: aload         11
     451: iload         14
     453: istore        15
     455: astore        18
     457: iconst_0
     458: istore        16
     460: ldc           #112                // String
     462: aload         18
     464: swap
     465: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     470: pop
     471: goto          429
     474: aload         11
     476: checkcast     #82                 // class java/util/List
     479: nop
     480: aload         17
     482: swap
     483: checkcast     #40                 // class java/lang/Iterable
     486: invokestatic  #116                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     489: astore        7
     491: iconst_0
     492: istore        8
     494: iload         8
     496: iload         5
     498: if_icmpge     590
     501: aload         6
     503: iload         8
     505: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     510: checkcast     #69                 // class java/lang/String
     513: astore        9
     515: aload         7
     517: iload         8
     519: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     524: checkcast     #69                 // class java/lang/String
     527: astore        10
     529: aload_3
     530: aload         9
     532: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     535: ldc           #126                // String
     537: checkcast     #19                 // class java/lang/CharSequence
     540: iload_2
     541: ifeq          548
     544: iconst_4
     545: goto          556
     548: iload         4
     550: aload         9
     552: invokevirtual #70                 // Method java/lang/String.length:()I
     555: isub
     556: invokestatic  #130                // Method kotlin/text/StringsKt.repeat:(Ljava/lang/CharSequence;I)Ljava/lang/String;
     559: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     562: aload         10
     564: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     567: pop
     568: iload         8
     570: iload         5
     572: iconst_1
     573: isub
     574: if_icmpeq     584
     577: aload_3
     578: ldc           #132                // String \n
     580: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     583: pop
     584: iinc          8, 1
     587: goto          494
     590: aload_3
     591: areturn

  public static final java.lang.StringBuilder addToRight(java.lang.StringBuilder, java.lang.StringBuilder, boolean);
    Code:
       0: aload_0
       1: ldc           #9                  // String left
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String right
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #164                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      16: dup
      17: ldc           #166                // String toString(...)
      19: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      22: aload_1
      23: invokevirtual #164                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      26: dup
      27: ldc           #166                // String toString(...)
      29: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      32: iload_2
      33: invokestatic  #171                // Method addToRight:(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/StringBuilder;
      36: areturn

  public static final java.lang.StringBuilder chompToSize(java.lang.String, int);
    Code:
       0: aload_0
       1: ldc           #175                // String text
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #25                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #32                 // Method java/lang/StringBuilder."<init>":()V
      13: astore_2
      14: aload_0
      15: checkcast     #19                 // class java/lang/CharSequence
      18: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      21: invokeinterface #176,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      26: astore_3
      27: aload_3
      28: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          259
      36: aload_3
      37: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: checkcast     #69                 // class java/lang/String
      45: astore        4
      47: aload         4
      49: astore        5
      51: aload         5
      53: checkcast     #19                 // class java/lang/CharSequence
      56: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      61: ifle          68
      64: iconst_1
      65: goto          69
      68: iconst_0
      69: ifeq          249
      72: iload_1
      73: aload         5
      75: invokevirtual #70                 // Method java/lang/String.length:()I
      78: if_icmplt     91
      81: aload_2
      82: aload         5
      84: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      87: pop
      88: goto          249
      91: aload         5
      93: iconst_0
      94: iload_1
      95: invokevirtual #180                // Method java/lang/String.substring:(II)Ljava/lang/String;
      98: dup
      99: ldc           #182                // String substring(...)
     101: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     104: astore        6
     106: aload         6
     108: checkcast     #19                 // class java/lang/CharSequence
     111: ldc           #126                // String
     113: iconst_0
     114: iconst_0
     115: bipush        6
     117: aconst_null
     118: invokestatic  #186                // Method kotlin/text/StringsKt.lastIndexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     121: iconst_m1
     122: if_icmpeq     220
     125: aload         5
     127: aload         6
     129: checkcast     #19                 // class java/lang/CharSequence
     132: ldc           #126                // String
     134: iconst_0
     135: iconst_0
     136: bipush        6
     138: aconst_null
     139: invokestatic  #186                // Method kotlin/text/StringsKt.lastIndexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     142: iconst_1
     143: iadd
     144: invokevirtual #189                // Method java/lang/String.substring:(I)Ljava/lang/String;
     147: dup
     148: ldc           #182                // String substring(...)
     150: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     153: astore        5
     155: aload         6
     157: checkcast     #19                 // class java/lang/CharSequence
     160: ldc           #126                // String
     162: iconst_0
     163: iconst_0
     164: bipush        6
     166: aconst_null
     167: invokestatic  #186                // Method kotlin/text/StringsKt.lastIndexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     170: ifne          188
     173: aload         6
     175: iconst_1
     176: invokevirtual #189                // Method java/lang/String.substring:(I)Ljava/lang/String;
     179: dup
     180: ldc           #182                // String substring(...)
     182: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     185: goto          215
     188: aload         6
     190: iconst_0
     191: aload         6
     193: checkcast     #19                 // class java/lang/CharSequence
     196: ldc           #126                // String
     198: iconst_0
     199: iconst_0
     200: bipush        6
     202: aconst_null
     203: invokestatic  #186                // Method kotlin/text/StringsKt.lastIndexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     206: invokevirtual #180                // Method java/lang/String.substring:(II)Ljava/lang/String;
     209: dup
     210: ldc           #182                // String substring(...)
     212: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     215: astore        6
     217: goto          234
     220: aload         5
     222: iload_1
     223: invokevirtual #189                // Method java/lang/String.substring:(I)Ljava/lang/String;
     226: dup
     227: ldc           #182                // String substring(...)
     229: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     232: astore        5
     234: aload_2
     235: aload         6
     237: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     240: ldc           #132                // String \n
     242: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     245: pop
     246: goto          51
     249: aload_2
     250: ldc           #132                // String \n
     252: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     255: pop
     256: goto          27
     259: aload_2
     260: areturn

  public static final java.lang.StringBuilder chompToLines(java.lang.String, int);
    Code:
       0: aload_0
       1: ldc           #175                // String text
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #19                 // class java/lang/CharSequence
      10: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      13: checkcast     #40                 // class java/lang/Iterable
      16: iload_1
      17: invokestatic  #197                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      20: checkcast     #40                 // class java/lang/Iterable
      23: ldc           #132                // String \n
      25: checkcast     #19                 // class java/lang/CharSequence
      28: aconst_null
      29: aconst_null
      30: iconst_0
      31: aconst_null
      32: aconst_null
      33: bipush        62
      35: aconst_null
      36: invokestatic  #201                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      39: astore_2
      40: aload_0
      41: checkcast     #19                 // class java/lang/CharSequence
      44: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      47: checkcast     #40                 // class java/lang/Iterable
      50: iload_1
      51: invokestatic  #204                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      54: checkcast     #40                 // class java/lang/Iterable
      57: ldc           #132                // String \n
      59: checkcast     #19                 // class java/lang/CharSequence
      62: aconst_null
      63: aconst_null
      64: iconst_0
      65: aconst_null
      66: aconst_null
      67: bipush        62
      69: aconst_null
      70: invokestatic  #201                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      73: astore_3
      74: aload_3
      75: ldc           #112                // String
      77: invokestatic  #208                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      80: ifeq          92
      83: new           #25                 // class java/lang/StringBuilder
      86: dup
      87: aload_2
      88: invokespecial #29                 // Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
      91: areturn
      92: aload_2
      93: aload_3
      94: iload_1
      95: invokestatic  #210                // Method chompToLines:(Ljava/lang/String;I)Ljava/lang/StringBuilder;
      98: invokevirtual #164                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     101: dup
     102: ldc           #166                // String toString(...)
     104: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     107: iconst_0
     108: invokestatic  #171                // Method addToRight:(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/StringBuilder;
     111: areturn

  public static final java.lang.StringBuilder chompToLines(java.lang.StringBuilder, int);
    Code:
       0: aload_0
       1: ldc           #175                // String text
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #164                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      10: dup
      11: ldc           #166                // String toString(...)
      13: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      16: iload_1
      17: invokestatic  #210                // Method chompToLines:(Ljava/lang/String;I)Ljava/lang/StringBuilder;
      20: areturn

  public static final java.lang.String getTruncated(double, int);
    Code:
       0: ldc2_w        #216                // double 10.0d
       3: iload_2
       4: i2d
       5: invokestatic  #221                // Method java/lang/Math.pow:(DD)D
       8: d2i
       9: istore_3
      10: iconst_0
      11: istore        4
      13: dload_0
      14: iload_3
      15: i2d
      16: dmul
      17: d2i
      18: i2d
      19: iload_3
      20: i2d
      21: ddiv
      22: nop
      23: invokestatic  #224                // Method java/lang/String.valueOf:(D)Ljava/lang/String;
      26: areturn

  public static final <E> java.lang.String addLinePrefix(E, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #233                // String prefix
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #236                // Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
      10: checkcast     #19                 // class java/lang/CharSequence
      13: invokestatic  #38                 // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      16: checkcast     #40                 // class java/lang/Iterable
      19: ldc           #132                // String \n
      21: checkcast     #19                 // class java/lang/CharSequence
      24: aconst_null
      25: aconst_null
      26: iconst_0
      27: aconst_null
      28: aload_1
      29: invokedynamic #256,  0            // InvokeDynamic #0:invoke:(Ljava/lang/String;)Lkotlin/jvm/functions/Function1;
      34: bipush        30
      36: aconst_null
      37: invokestatic  #201                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      40: areturn

  public static java.lang.String addLinePrefix$default(java.lang.Object, java.lang.String, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          10
       6: ldc_w         #261                // String
       9: astore_1
      10: aload_0
      11: aload_1
      12: invokestatic  #263                // Method addLinePrefix:(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;
      15: areturn

  private static final java.lang.CharSequence addLinePrefix$lambda$4(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #264                // String it
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #25                 // class java/lang/StringBuilder
      10: dup
      11: invokespecial #32                 // Method java/lang/StringBuilder."<init>":()V
      14: aload_0
      15: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_1
      19: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: invokevirtual #164                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      25: checkcast     #19                 // class java/lang/CharSequence
      28: areturn
}


package korlibs.datastructure

import kotlin.math.min

fun <T> genericSort(subject: T, left: Int, right: Int, ops: SortOps<T>): T =
    genericSort(subject, left, right, ops, false)

fun <T> genericSort(subject: T, left: Int, right: Int, ops: SortOps<T>, reversed: Boolean): T =
    subject.also {
        timSort(subject, left, right, ops, reversed)
    }

private fun Int.negateIf(doNegate: Boolean) = if (doNegate) -this else this

private fun <T> insertionSort(arr: T, left: Int, right: Int, ops: SortOps<T>, reversed: Boolean) {
    for (n in left + 1..right) {
        var m = n - 1

        while (m >= left) {
            if (ops.compare(arr, m, n).negateIf(reversed) <= 0) break
            m--
        }
        m++

        if (m != n) ops.shiftLeft(arr, m, n)
    }
}

private fun <T> merge(arr: T, start: Int, mid: Int, end: Int, ops: SortOps<T>, reversed: Boolean) {
    var s = start
    var m = mid
    var s2 = m + 1

    if (ops.compare(arr, m, s2).negateIf(reversed) <= 0) return

    while (s <= m && s2 <= end) {
        if (ops.compare(arr, s, s2).negateIf(reversed) <= 0) {
            s++
        } else {
            ops.shiftLeft(arr, s, s2)
            s++
            m++
            s2++
        }
    }
}

private fun <T> mergeSort(arr: T, l: Int, r: Int, ops: SortOps<T>, reversed: Boolean) {
    if (l < r) {
        val m = l + (r - l) / 2
        mergeSort(arr, l, m, ops, reversed)
        mergeSort(arr, m + 1, r, ops, reversed)
        merge(arr, l, m, r, ops, reversed)
    }
}

private fun <T> timSort(arr: T, l: Int, r: Int, ops: SortOps<T>, reversed: Boolean, RUN: Int = 32) {
    val n = r - l + 1
    for (i in 0 until n step RUN) {
        insertionSort(arr, l + i, l + min((i + RUN - 1), (n - 1)), ops, reversed)
    }
    var size = RUN
    while (size < n) {
        for (left in 0 until n step (2 * size)) {
            val rize = min(size, n - left - 1)
            val mid = left + rize - 1
            val right = min((left + 2 * rize - 1), (n - 1))
            merge(arr, l + left, l + mid, l + right, ops, reversed)
        }
        size *= 2
    }
}

abstract class SortOps<T> {
    abstract fun compare(subject: T, l: Int, r: Int): Int
    abstract fun swap(subject: T, indexL: Int, indexR: Int)
    open fun shiftLeft(subject: T, indexL: Int, indexR: Int) {
        for (n in indexR downTo indexL + 1) swap(subject, n - 1, n)
    }
    open fun reverse(subject: T, indexL: Int, indexR: Int) {
        val count = indexR - indexL + 1
        for (n in 0 until count / 2) {
            swap(subject, indexL + n, indexR - n)
        }
    }
}

object SortOpsComparable : SortOps<MutableList<Comparable<Any>>>() {
    override fun compare(subject: MutableList<Comparable<Any>>, l: Int, r: Int): Int
        = subject[l].compareTo(subject[r])

    override fun swap(subject: MutableList<Comparable<Any>>, indexL: Int, indexR: Int) {
        val tmp = subject[indexL]
        subject[indexL] = subject[indexR]
        subject[indexR] = tmp
    }
}

fun <T : Comparable<T>> MutableList<T>.genericSort(left: Int = 0, right: Int = size - 1): MutableList<T> =
    genericSort(this, left, right, SortOpsComparable as SortOps<MutableList<T>>, false)

fun <T : Comparable<T>> List<T>.genericSorted(left: Int = 0, right: Int = size - 1): List<T> =
    this.subList(left, right + 1).toMutableList().genericSort()

fun <T : Comparable<T>> List<T>.timSorted(): List<T> = this.toMutableList().also { it.timSort() }

fun <T : Comparable<T>> MutableList<T>.timSort(left: Int = 0, right: Int = size - 1): MutableList<T> {
    timSort(this, left, right, SortOpsComparable as SortOps<MutableList<T>>, false)
    //genericSort(this, left, right, SortOpsComparable as SortOps<MutableList<T>>, false)
    return this
}

Compiled from "_GenericSort.kt"
public final class korlibs.datastructure._GenericSortKt {
  public static final <T> T genericSort(T, int, int, korlibs.datastructure.SortOps<T>);
    Code:
       0: aload_3
       1: ldc           #10                 // String ops
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: iload_2
       9: aload_3
      10: iconst_0
      11: invokestatic  #19                 // Method genericSort:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;Z)Ljava/lang/Object;
      14: areturn

  public static final <T> T genericSort(T, int, int, korlibs.datastructure.SortOps<T>, boolean);
    Code:
       0: aload_3
       1: ldc           #10                 // String ops
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore        5
       9: aload         5
      11: astore        6
      13: iconst_0
      14: istore        7
      16: aload_0
      17: iload_1
      18: iload_2
      19: aload_3
      20: iload         4
      22: iconst_0
      23: bipush        32
      25: aconst_null
      26: invokestatic  #30                 // Method timSort$default:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;ZIILjava/lang/Object;)V
      29: nop
      30: aload         5
      32: areturn

  private static final int negateIf(int, boolean);
    Code:
       0: iload_1
       1: ifeq          9
       4: iload_0
       5: ineg
       6: goto          10
       9: iload_0
      10: ireturn

  private static final <T> void insertionSort(T, int, int, korlibs.datastructure.SortOps<T>, boolean);
    Code:
       0: iload_1
       1: iconst_1
       2: iadd
       3: istore        5
       5: iload         5
       7: iload_2
       8: if_icmpgt     77
      11: iload         5
      13: iconst_1
      14: isub
      15: istore        6
      17: iload         6
      19: iload_1
      20: if_icmplt     46
      23: aload_3
      24: aload_0
      25: iload         6
      27: iload         5
      29: invokevirtual #47                 // Method korlibs/datastructure/SortOps.compare:(Ljava/lang/Object;II)I
      32: iload         4
      34: invokestatic  #49                 // Method negateIf:(IZ)I
      37: ifle          46
      40: iinc          6, -1
      43: goto          17
      46: iinc          6, 1
      49: iload         6
      51: iload         5
      53: if_icmpeq     65
      56: aload_3
      57: aload_0
      58: iload         6
      60: iload         5
      62: invokevirtual #53                 // Method korlibs/datastructure/SortOps.shiftLeft:(Ljava/lang/Object;II)V
      65: iload         5
      67: iload_2
      68: if_icmpeq     77
      71: iinc          5, 1
      74: goto          11
      77: return

  private static final <T> void merge(T, int, int, int, korlibs.datastructure.SortOps<T>, boolean);
    Code:
       0: iload_1
       1: istore        6
       3: iload_2
       4: istore        7
       6: iload         7
       8: iconst_1
       9: iadd
      10: istore        8
      12: aload         4
      14: aload_0
      15: iload         7
      17: iload         8
      19: invokevirtual #47                 // Method korlibs/datastructure/SortOps.compare:(Ljava/lang/Object;II)I
      22: iload         5
      24: invokestatic  #49                 // Method negateIf:(IZ)I
      27: ifgt          31
      30: return
      31: iload         6
      33: iload         7
      35: if_icmpgt     90
      38: iload         8
      40: iload_3
      41: if_icmpgt     90
      44: aload         4
      46: aload_0
      47: iload         6
      49: iload         8
      51: invokevirtual #47                 // Method korlibs/datastructure/SortOps.compare:(Ljava/lang/Object;II)I
      54: iload         5
      56: invokestatic  #49                 // Method negateIf:(IZ)I
      59: ifgt          68
      62: iinc          6, 1
      65: goto          31
      68: aload         4
      70: aload_0
      71: iload         6
      73: iload         8
      75: invokevirtual #53                 // Method korlibs/datastructure/SortOps.shiftLeft:(Ljava/lang/Object;II)V
      78: iinc          6, 1
      81: iinc          7, 1
      84: iinc          8, 1
      87: goto          31
      90: return

  private static final <T> void mergeSort(T, int, int, korlibs.datastructure.SortOps<T>, boolean);
    Code:
       0: iload_1
       1: iload_2
       2: if_icmpge     47
       5: iload_1
       6: iload_2
       7: iload_1
       8: isub
       9: iconst_2
      10: idiv
      11: iadd
      12: istore        5
      14: aload_0
      15: iload_1
      16: iload         5
      18: aload_3
      19: iload         4
      21: invokestatic  #67                 // Method mergeSort:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;Z)V
      24: aload_0
      25: iload         5
      27: iconst_1
      28: iadd
      29: iload_2
      30: aload_3
      31: iload         4
      33: invokestatic  #67                 // Method mergeSort:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;Z)V
      36: aload_0
      37: iload_1
      38: iload         5
      40: iload_2
      41: aload_3
      42: iload         4
      44: invokestatic  #69                 // Method merge:(Ljava/lang/Object;IIILkorlibs/datastructure/SortOps;Z)V
      47: return

  private static final <T> void timSort(T, int, int, korlibs.datastructure.SortOps<T>, boolean, int);
    Code:
       0: iload_2
       1: iload_1
       2: isub
       3: iconst_1
       4: iadd
       5: istore        6
       7: iconst_0
       8: iload         6
      10: invokestatic  #80                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      13: checkcast     #82                 // class kotlin/ranges/IntProgression
      16: iload         5
      18: invokestatic  #86                 // Method kotlin/ranges/RangesKt.step:(Lkotlin/ranges/IntProgression;I)Lkotlin/ranges/IntProgression;
      21: astore        7
      23: aload         7
      25: invokevirtual #90                 // Method kotlin/ranges/IntProgression.getFirst:()I
      28: istore        8
      30: aload         7
      32: invokevirtual #93                 // Method kotlin/ranges/IntProgression.getLast:()I
      35: istore        9
      37: aload         7
      39: invokevirtual #96                 // Method kotlin/ranges/IntProgression.getStep:()I
      42: istore        10
      44: iload         10
      46: ifle          56
      49: iload         8
      51: iload         9
      53: if_icmple     68
      56: iload         10
      58: ifge          112
      61: iload         9
      63: iload         8
      65: if_icmpgt     112
      68: aload_0
      69: iload_1
      70: iload         8
      72: iadd
      73: iload_1
      74: iload         8
      76: iload         5
      78: iadd
      79: iconst_1
      80: isub
      81: iload         6
      83: iconst_1
      84: isub
      85: invokestatic  #102                // Method java/lang/Math.min:(II)I
      88: iadd
      89: aload_3
      90: iload         4
      92: invokestatic  #104                // Method insertionSort:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;Z)V
      95: iload         8
      97: iload         9
      99: if_icmpeq     112
     102: iload         8
     104: iload         10
     106: iadd
     107: istore        8
     109: goto          68
     112: iload         5
     114: istore        7
     116: iload         7
     118: iload         6
     120: if_icmpge     272
     123: iconst_0
     124: iload         6
     126: invokestatic  #80                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     129: checkcast     #82                 // class kotlin/ranges/IntProgression
     132: iconst_2
     133: iload         7
     135: imul
     136: invokestatic  #86                 // Method kotlin/ranges/RangesKt.step:(Lkotlin/ranges/IntProgression;I)Lkotlin/ranges/IntProgression;
     139: astore        8
     141: aload         8
     143: invokevirtual #90                 // Method kotlin/ranges/IntProgression.getFirst:()I
     146: istore        9
     148: aload         8
     150: invokevirtual #93                 // Method kotlin/ranges/IntProgression.getLast:()I
     153: istore        10
     155: aload         8
     157: invokevirtual #96                 // Method kotlin/ranges/IntProgression.getStep:()I
     160: istore        11
     162: iload         11
     164: ifle          174
     167: iload         9
     169: iload         10
     171: if_icmple     186
     174: iload         11
     176: ifge          263
     179: iload         10
     181: iload         9
     183: if_icmpgt     263
     186: iload         7
     188: iload         6
     190: iload         9
     192: isub
     193: iconst_1
     194: isub
     195: invokestatic  #102                // Method java/lang/Math.min:(II)I
     198: istore        12
     200: iload         9
     202: iload         12
     204: iadd
     205: iconst_1
     206: isub
     207: istore        13
     209: iload         9
     211: iconst_2
     212: iload         12
     214: imul
     215: iadd
     216: iconst_1
     217: isub
     218: iload         6
     220: iconst_1
     221: isub
     222: invokestatic  #102                // Method java/lang/Math.min:(II)I
     225: istore        14
     227: aload_0
     228: iload_1
     229: iload         9
     231: iadd
     232: iload_1
     233: iload         13
     235: iadd
     236: iload_1
     237: iload         14
     239: iadd
     240: aload_3
     241: iload         4
     243: invokestatic  #69                 // Method merge:(Ljava/lang/Object;IIILkorlibs/datastructure/SortOps;Z)V
     246: iload         9
     248: iload         10
     250: if_icmpeq     263
     253: iload         9
     255: iload         11
     257: iadd
     258: istore        9
     260: goto          186
     263: iload         7
     265: iconst_2
     266: imul
     267: istore        7
     269: goto          116
     272: return

  static void timSort$default(java.lang.Object, int, int, korlibs.datastructure.SortOps, boolean, int, int, java.lang.Object);
    Code:
       0: iload         6
       2: bipush        32
       4: iand
       5: ifeq          12
       8: bipush        32
      10: istore        5
      12: aload_0
      13: iload_1
      14: iload_2
      15: aload_3
      16: iload         4
      18: iload         5
      20: invokestatic  #110                // Method timSort:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;ZI)V
      23: return

  public static final <T extends java.lang.Comparable<? super T>> java.util.List<T> genericSort(java.util.List<T>, int, int);
    Code:
       0: aload_0
       1: ldc           #114                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: iload_2
       9: getstatic     #120                // Field korlibs/datastructure/SortOpsComparable.INSTANCE:Lkorlibs/datastructure/SortOpsComparable;
      12: dup
      13: ldc           #122                // String null cannot be cast to non-null type korlibs.datastructure.SortOps<kotlin.collections.MutableList<T of korlibs.datastructure._GenericSortKt.genericSort>>
      15: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      18: checkcast     #43                 // class korlibs/datastructure/SortOps
      21: iconst_0
      22: invokestatic  #19                 // Method genericSort:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;Z)Ljava/lang/Object;
      25: checkcast     #127                // class java/util/List
      28: areturn

  public static java.util.List genericSort$default(java.util.List, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: iload_3
       9: iconst_2
      10: iand
      11: ifeq          23
      14: aload_0
      15: invokeinterface #133,  1          // InterfaceMethod java/util/List.size:()I
      20: iconst_1
      21: isub
      22: istore_2
      23: aload_0
      24: iload_1
      25: iload_2
      26: invokestatic  #135                // Method genericSort:(Ljava/util/List;II)Ljava/util/List;
      29: areturn

  public static final <T extends java.lang.Comparable<? super T>> java.util.List<T> genericSorted(java.util.List<? extends T>, int, int);
    Code:
       0: aload_0
       1: ldc           #114                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: iload_2
       9: iconst_1
      10: iadd
      11: invokeinterface #141,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      16: checkcast     #143                // class java/util/Collection
      19: invokestatic  #149                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      22: iconst_0
      23: iconst_0
      24: iconst_3
      25: aconst_null
      26: invokestatic  #151                // Method genericSort$default:(Ljava/util/List;IIILjava/lang/Object;)Ljava/util/List;
      29: areturn

  public static java.util.List genericSorted$default(java.util.List, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: iload_3
       9: iconst_2
      10: iand
      11: ifeq          23
      14: aload_0
      15: invokeinterface #133,  1          // InterfaceMethod java/util/List.size:()I
      20: iconst_1
      21: isub
      22: istore_2
      23: aload_0
      24: iload_1
      25: iload_2
      26: invokestatic  #155                // Method genericSorted:(Ljava/util/List;II)Ljava/util/List;
      29: areturn

  public static final <T extends java.lang.Comparable<? super T>> java.util.List<T> timSorted(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #114                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #143                // class java/util/Collection
      10: invokestatic  #149                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      13: astore_1
      14: aload_1
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_2
      19: iconst_0
      20: iconst_0
      21: iconst_3
      22: aconst_null
      23: invokestatic  #160                // Method timSort$default:(Ljava/util/List;IIILjava/lang/Object;)Ljava/util/List;
      26: pop
      27: aload_1
      28: areturn

  public static final <T extends java.lang.Comparable<? super T>> java.util.List<T> timSort(java.util.List<T>, int, int);
    Code:
       0: aload_0
       1: ldc           #114                // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: iload_2
       9: getstatic     #120                // Field korlibs/datastructure/SortOpsComparable.INSTANCE:Lkorlibs/datastructure/SortOpsComparable;
      12: dup
      13: ldc           #164                // String null cannot be cast to non-null type korlibs.datastructure.SortOps<kotlin.collections.MutableList<T of korlibs.datastructure._GenericSortKt.timSort>>
      15: invokestatic  #125                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      18: checkcast     #43                 // class korlibs/datastructure/SortOps
      21: iconst_0
      22: iconst_0
      23: bipush        32
      25: aconst_null
      26: invokestatic  #30                 // Method timSort$default:(Ljava/lang/Object;IILkorlibs/datastructure/SortOps;ZIILjava/lang/Object;)V
      29: aload_0
      30: areturn

  public static java.util.List timSort$default(java.util.List, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: iload_3
       9: iconst_2
      10: iand
      11: ifeq          23
      14: aload_0
      15: invokeinterface #133,  1          // InterfaceMethod java/util/List.size:()I
      20: iconst_1
      21: isub
      22: istore_2
      23: aload_0
      24: iload_1
      25: iload_2
      26: invokestatic  #167                // Method timSort:(Ljava/util/List;II)Ljava/util/List;
      29: areturn
}