import java.io.File

enum class Tile(val c: String) {
    FLOOR("."),
    FILLED("#"),
    EMPTY("L"),
    UNKNOWN("?");

    fun from(c: Char) : Tile {
        when (c) {
            '.' -> return FLOOR
            '#' -> return FILLED
            'L' -> return EMPTY
        }
        return UNKNOWN;
    }
    override fun toString(): String {
        return c
    }
}

fun main() {
    val map: ArrayList<ArrayList<Tile>> = File("input.txt").readLines().asSequence()
            .map { line -> line.asSequence() }
            .map { it.map {t -> Tile.UNKNOWN.from(t)} }
            .map { it.toCollection(ArrayList()) }
            .toCollection(ArrayList())

    val maxY = map.size -1
    val maxX = map[0].size -1

    var changes = 1
    var iterations = 0
    while (changes != 0) {
        changes = 0
        val mapc = copyMap(map)
        for ((y, row) in mapc.withIndex()) {
            for ((x, tile) in row.withIndex()) {
                if(tile == Tile.FLOOR) {
                    //print(".")
                    continue
                }
                var occupied : Int = 0
                for(vec in genVecs(x, y, maxX, maxY)) {
                    for (v in vec) {
                        if (mapc[v.y][v.x] == Tile.FILLED) {
                            occupied++
                            break
                        }
                        if (mapc[v.y][v.x] == Tile.EMPTY) {
                            break
                        }
                    }
                }
                if(occupied >= 5)
                    if(tile != Tile.EMPTY) {
                        map[y][x] = Tile.EMPTY
                        changes++
                    }
                if(occupied == 0)
                    if(tile != Tile.FILLED) {
                        map[y][x] = Tile.FILLED
                        changes++
                    }
                //print(occupied)
            }
            //print("\n")
        }

        if(changes != 0)
            iterations++
        if(iterations > 100000) {
            println("giving up");
            break;
        }

        //println("Changed: $changes ------")
        //map.forEach{ println(it.joinToString("")) }
        //println("------------------------")
    }
    val filled = map
            .flatten()
            .filter {it == Tile.FILLED}
            .count()
    println("$filled seats filled")
}

fun copyMap(map: ArrayList<ArrayList<Tile>>): ArrayList<ArrayList<Tile>>{
    val mapc: ArrayList<ArrayList<Tile>> = arrayListOf()
    for(m: ArrayList<Tile> in map) {
        mapc.add(m.clone() as java.util.ArrayList<Tile>)
    }
    return mapc;
}

data class Coord(val x: Int, val y: Int) {
}

//Boy this seems silly
//Will update later to make something that take (stepx, stepy)
fun genVecs(x:Int, y:Int, maxX: Int, maxY:Int) : List<List<Coord>> {
    val out: MutableList<MutableList<Coord>> = mutableListOf()
    /**
     * 123
     * 0o4
     * 765
     */
    for (v in 0..7) {
        var list: MutableList<Coord> = mutableListOf()
        when (v) {
            0 -> list = (x-1 downTo 0).map { Coord(it, y) }.toMutableList()
            1 -> {
                for (i in x-1 downTo 0) {
                    val j = y - (x - i)
                    if (j >= 0)
                        list.add(Coord(i, j))
                }
            }
            2 -> list = (y-1 downTo 0).map { Coord(x, it) }.toMutableList()
            3 -> {
                for (i in x+1..maxX) {
                    val j = y - (i - x)
                    if (j in 0..maxY)
                        list.add(Coord(i, j))
                }
            }
            4 -> list = (x+1..maxX).map { Coord(it, y) }.toMutableList()
            5 -> {
                for (i in x+1..maxX) {
                    val j = y + (i - x)
                    if (j in 0..maxY)
                        list.add(Coord(i, j))
                }
            }
            6 -> list = (y+1..maxY).map { Coord(x, it) }.toMutableList()
            7 -> {
                for (i in x-1 downTo 0) {
                    val j = y - (i - x)
                    if (j in 0..maxY)
                        list.add(Coord(i, j))
                }
            }
        }
        out.add(list)
    }
    return out
}

Compiled from "Day11part2.kt"
public final class Day11part2Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #22                 // class java/lang/Iterable
      18: invokestatic  #28                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      21: invokedynamic #47,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      26: invokestatic  #53                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      29: invokedynamic #60,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      34: invokestatic  #53                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      37: invokedynamic #67,  0             // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
      42: invokestatic  #53                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      45: new           #69                 // class java/util/ArrayList
      48: dup
      49: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
      52: checkcast     #73                 // class java/util/Collection
      55: invokestatic  #77                 // Method kotlin/sequences/SequencesKt.toCollection:(Lkotlin/sequences/Sequence;Ljava/util/Collection;)Ljava/util/Collection;
      58: checkcast     #69                 // class java/util/ArrayList
      61: astore_0
      62: aload_0
      63: invokevirtual #81                 // Method java/util/ArrayList.size:()I
      66: iconst_1
      67: isub
      68: istore_1
      69: aload_0
      70: iconst_0
      71: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      74: checkcast     #69                 // class java/util/ArrayList
      77: invokevirtual #81                 // Method java/util/ArrayList.size:()I
      80: iconst_1
      81: isub
      82: istore_2
      83: iconst_1
      84: istore_3
      85: iconst_0
      86: istore        4
      88: iload_3
      89: ifeq          438
      92: iconst_0
      93: istore_3
      94: aload_0
      95: invokestatic  #89                 // Method copyMap:(Ljava/util/ArrayList;)Ljava/util/ArrayList;
      98: astore        5
     100: aload         5
     102: checkcast     #22                 // class java/lang/Iterable
     105: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     110: astore        6
     112: iconst_0
     113: istore        7
     115: aload         6
     117: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     122: ifeq          412
     125: iload         7
     127: istore        8
     129: iload         7
     131: iconst_1
     132: iadd
     133: istore        7
     135: aload         6
     137: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: checkcast     #69                 // class java/util/ArrayList
     145: astore        9
     147: aload         9
     149: checkcast     #22                 // class java/lang/Iterable
     152: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     157: astore        10
     159: iconst_0
     160: istore        11
     162: aload         10
     164: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     169: ifeq          115
     172: iload         11
     174: istore        12
     176: iload         11
     178: iconst_1
     179: iadd
     180: istore        11
     182: aload         10
     184: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     189: checkcast     #105                // class Tile
     192: astore        13
     194: aload         13
     196: getstatic     #109                // Field Tile.FLOOR:LTile;
     199: if_acmpne     205
     202: goto          162
     205: iconst_0
     206: istore        14
     208: iload         12
     210: iload         8
     212: iload_2
     213: iload_1
     214: invokestatic  #113                // Method genVecs:(IIII)Ljava/util/List;
     217: invokeinterface #116,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     222: astore        15
     224: aload         15
     226: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          340
     234: aload         15
     236: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     241: checkcast     #115                // class java/util/List
     244: astore        16
     246: aload         16
     248: invokeinterface #116,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     253: astore        17
     255: aload         17
     257: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     262: ifeq          224
     265: aload         17
     267: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     272: checkcast     #118                // class Coord
     275: astore        18
     277: aload         5
     279: aload         18
     281: invokevirtual #121                // Method Coord.getY:()I
     284: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     287: checkcast     #69                 // class java/util/ArrayList
     290: aload         18
     292: invokevirtual #124                // Method Coord.getX:()I
     295: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     298: getstatic     #127                // Field Tile.FILLED:LTile;
     301: if_acmpne     310
     304: iinc          14, 1
     307: goto          224
     310: aload         5
     312: aload         18
     314: invokevirtual #121                // Method Coord.getY:()I
     317: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     320: checkcast     #69                 // class java/util/ArrayList
     323: aload         18
     325: invokevirtual #124                // Method Coord.getX:()I
     328: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     331: getstatic     #130                // Field Tile.EMPTY:LTile;
     334: if_acmpne     255
     337: goto          224
     340: iload         14
     342: iconst_5
     343: if_icmplt     375
     346: aload         13
     348: getstatic     #130                // Field Tile.EMPTY:LTile;
     351: if_acmpeq     375
     354: aload_0
     355: iload         8
     357: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     360: checkcast     #69                 // class java/util/ArrayList
     363: iload         12
     365: getstatic     #130                // Field Tile.EMPTY:LTile;
     368: invokevirtual #134                // Method java/util/ArrayList.set:(ILjava/lang/Object;)Ljava/lang/Object;
     371: pop
     372: iinc          3, 1
     375: iload         14
     377: ifne          162
     380: aload         13
     382: getstatic     #127                // Field Tile.FILLED:LTile;
     385: if_acmpeq     162
     388: aload_0
     389: iload         8
     391: invokevirtual #85                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     394: checkcast     #69                 // class java/util/ArrayList
     397: iload         12
     399: getstatic     #127                // Field Tile.FILLED:LTile;
     402: invokevirtual #134                // Method java/util/ArrayList.set:(ILjava/lang/Object;)Ljava/lang/Object;
     405: pop
     406: iinc          3, 1
     409: goto          162
     412: iload_3
     413: ifeq          419
     416: iinc          4, 1
     419: iload         4
     421: ldc           #135                // int 100000
     423: if_icmple     88
     426: ldc           #137                // String giving up
     428: getstatic     #143                // Field java/lang/System.out:Ljava/io/PrintStream;
     431: swap
     432: invokevirtual #149                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     435: goto          438
     438: aload_0
     439: checkcast     #22                 // class java/lang/Iterable
     442: invokestatic  #153                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     445: checkcast     #22                 // class java/lang/Iterable
     448: astore        6
     450: nop
     451: iconst_0
     452: istore        7
     454: aload         6
     456: astore        8
     458: new           #69                 // class java/util/ArrayList
     461: dup
     462: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
     465: checkcast     #73                 // class java/util/Collection
     468: astore        9
     470: iconst_0
     471: istore        10
     473: aload         8
     475: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     480: astore        11
     482: aload         11
     484: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     489: ifeq          540
     492: aload         11
     494: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     499: astore        12
     501: aload         12
     503: checkcast     #105                // class Tile
     506: astore        13
     508: iconst_0
     509: istore        14
     511: aload         13
     513: getstatic     #127                // Field Tile.FILLED:LTile;
     516: if_acmpne     523
     519: iconst_1
     520: goto          524
     523: iconst_0
     524: ifeq          482
     527: aload         9
     529: aload         12
     531: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     536: pop
     537: goto          482
     540: aload         9
     542: checkcast     #115                // class java/util/List
     545: nop
     546: checkcast     #73                 // class java/util/Collection
     549: invokeinterface #158,  1          // InterfaceMethod java/util/Collection.size:()I
     554: istore        5
     556: new           #160                // class java/lang/StringBuilder
     559: dup
     560: invokespecial #161                // Method java/lang/StringBuilder."<init>":()V
     563: iload         5
     565: invokevirtual #165                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     568: ldc           #167                // String  seats filled
     570: invokevirtual #170                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     573: invokevirtual #174                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     576: getstatic     #143                // Field java/lang/System.out:Ljava/io/PrintStream;
     579: swap
     580: invokevirtual #149                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     583: return

  public static final java.util.ArrayList<java.util.ArrayList<Tile>> copyMap(java.util.ArrayList<java.util.ArrayList<Tile>>);
    Code:
       0: aload_0
       1: ldc           #205                // String map
       3: invokestatic  #211                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #69                 // class java/util/ArrayList
       9: dup
      10: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
      13: astore_1
      14: aload_0
      15: invokevirtual #212                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
      18: dup
      19: ldc           #214                // String iterator(...)
      21: invokestatic  #217                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      24: astore_2
      25: aload_2
      26: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          71
      34: aload_2
      35: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      40: dup
      41: ldc           #219                // String next(...)
      43: invokestatic  #217                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      46: checkcast     #69                 // class java/util/ArrayList
      49: astore_3
      50: aload_1
      51: aload_3
      52: invokevirtual #222                // Method java/util/ArrayList.clone:()Ljava/lang/Object;
      55: dup
      56: ldc           #224                // String null cannot be cast to non-null type java.util.ArrayList<<root>.Tile>
      58: invokestatic  #227                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      61: checkcast     #69                 // class java/util/ArrayList
      64: invokevirtual #228                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      67: pop
      68: goto          25
      71: aload_1
      72: areturn

  public static final java.util.List<java.util.List<Coord>> genVecs(int, int, int, int);
    Code:
       0: new           #69                 // class java/util/ArrayList
       3: dup
       4: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #115                // class java/util/List
      10: astore        4
      12: iconst_0
      13: istore        5
      15: iload         5
      17: bipush        8
      19: if_icmpge     853
      22: new           #69                 // class java/util/ArrayList
      25: dup
      26: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
      29: checkcast     #115                // class java/util/List
      32: astore        6
      34: iload         5
      36: tableswitch   { // 0 to 7
                     0: 84
                     1: 204
                     2: 253
                     3: 373
                     4: 447
                     5: 571
                     6: 645
                     7: 769
               default: 837
          }
      84: iload_0
      85: iconst_1
      86: isub
      87: iconst_0
      88: invokestatic  #236                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      91: checkcast     #22                 // class java/lang/Iterable
      94: astore        7
      96: iconst_0
      97: istore        8
      99: aload         7
     101: astore        9
     103: new           #69                 // class java/util/ArrayList
     106: dup
     107: aload         7
     109: bipush        10
     111: invokestatic  #240                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     114: invokespecial #243                // Method java/util/ArrayList."<init>":(I)V
     117: checkcast     #73                 // class java/util/Collection
     120: astore        10
     122: iconst_0
     123: istore        11
     125: aload         9
     127: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     132: astore        12
     134: aload         12
     136: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     141: ifeq          187
     144: aload         12
     146: checkcast     #245                // class kotlin/collections/IntIterator
     149: invokevirtual #248                // Method kotlin/collections/IntIterator.nextInt:()I
     152: istore        13
     154: aload         10
     156: iload         13
     158: istore        14
     160: astore        16
     162: iconst_0
     163: istore        15
     165: new           #118                // class Coord
     168: dup
     169: iload         14
     171: iload_1
     172: invokespecial #251                // Method Coord."<init>":(II)V
     175: aload         16
     177: swap
     178: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     183: pop
     184: goto          134
     187: aload         10
     189: checkcast     #115                // class java/util/List
     192: nop
     193: checkcast     #73                 // class java/util/Collection
     196: invokestatic  #255                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     199: astore        6
     201: goto          837
     204: iload_0
     205: iconst_1
     206: isub
     207: istore        7
     209: iconst_m1
     210: iload         7
     212: if_icmpge     837
     215: iload_1
     216: iload_0
     217: iload         7
     219: isub
     220: isub
     221: istore        8
     223: iload         8
     225: iflt          247
     228: aload         6
     230: new           #118                // class Coord
     233: dup
     234: iload         7
     236: iload         8
     238: invokespecial #251                // Method Coord."<init>":(II)V
     241: invokeinterface #256,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     246: pop
     247: iinc          7, -1
     250: goto          209
     253: iload_1
     254: iconst_1
     255: isub
     256: iconst_0
     257: invokestatic  #236                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
     260: checkcast     #22                 // class java/lang/Iterable
     263: astore        7
     265: iconst_0
     266: istore        8
     268: aload         7
     270: astore        9
     272: new           #69                 // class java/util/ArrayList
     275: dup
     276: aload         7
     278: bipush        10
     280: invokestatic  #240                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     283: invokespecial #243                // Method java/util/ArrayList."<init>":(I)V
     286: checkcast     #73                 // class java/util/Collection
     289: astore        10
     291: iconst_0
     292: istore        11
     294: aload         9
     296: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     301: astore        12
     303: aload         12
     305: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     310: ifeq          356
     313: aload         12
     315: checkcast     #245                // class kotlin/collections/IntIterator
     318: invokevirtual #248                // Method kotlin/collections/IntIterator.nextInt:()I
     321: istore        13
     323: aload         10
     325: iload         13
     327: istore        14
     329: astore        16
     331: iconst_0
     332: istore        15
     334: new           #118                // class Coord
     337: dup
     338: iload_0
     339: iload         14
     341: invokespecial #251                // Method Coord."<init>":(II)V
     344: aload         16
     346: swap
     347: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     352: pop
     353: goto          303
     356: aload         10
     358: checkcast     #115                // class java/util/List
     361: nop
     362: checkcast     #73                 // class java/util/Collection
     365: invokestatic  #255                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     368: astore        6
     370: goto          837
     373: iload_0
     374: iconst_1
     375: iadd
     376: istore        7
     378: iload         7
     380: iload_2
     381: if_icmpgt     837
     384: iload_1
     385: iload         7
     387: iload_0
     388: isub
     389: isub
     390: istore        8
     392: iconst_0
     393: iload         8
     395: if_icmpgt     412
     398: iload         8
     400: iload_3
     401: if_icmpgt     408
     404: iconst_1
     405: goto          413
     408: iconst_0
     409: goto          413
     412: iconst_0
     413: ifeq          435
     416: aload         6
     418: new           #118                // class Coord
     421: dup
     422: iload         7
     424: iload         8
     426: invokespecial #251                // Method Coord."<init>":(II)V
     429: invokeinterface #256,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     434: pop
     435: iload         7
     437: iload_2
     438: if_icmpeq     837
     441: iinc          7, 1
     444: goto          384
     447: new           #258                // class kotlin/ranges/IntRange
     450: dup
     451: iload_0
     452: iconst_1
     453: iadd
     454: iload_2
     455: invokespecial #259                // Method kotlin/ranges/IntRange."<init>":(II)V
     458: checkcast     #22                 // class java/lang/Iterable
     461: astore        7
     463: iconst_0
     464: istore        8
     466: aload         7
     468: astore        9
     470: new           #69                 // class java/util/ArrayList
     473: dup
     474: aload         7
     476: bipush        10
     478: invokestatic  #240                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     481: invokespecial #243                // Method java/util/ArrayList."<init>":(I)V
     484: checkcast     #73                 // class java/util/Collection
     487: astore        10
     489: iconst_0
     490: istore        11
     492: aload         9
     494: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     499: astore        12
     501: aload         12
     503: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     508: ifeq          554
     511: aload         12
     513: checkcast     #245                // class kotlin/collections/IntIterator
     516: invokevirtual #248                // Method kotlin/collections/IntIterator.nextInt:()I
     519: istore        13
     521: aload         10
     523: iload         13
     525: istore        14
     527: astore        16
     529: iconst_0
     530: istore        15
     532: new           #118                // class Coord
     535: dup
     536: iload         14
     538: iload_1
     539: invokespecial #251                // Method Coord."<init>":(II)V
     542: aload         16
     544: swap
     545: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     550: pop
     551: goto          501
     554: aload         10
     556: checkcast     #115                // class java/util/List
     559: nop
     560: checkcast     #73                 // class java/util/Collection
     563: invokestatic  #255                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     566: astore        6
     568: goto          837
     571: iload_0
     572: iconst_1
     573: iadd
     574: istore        7
     576: iload         7
     578: iload_2
     579: if_icmpgt     837
     582: iload_1
     583: iload         7
     585: iload_0
     586: isub
     587: iadd
     588: istore        8
     590: iconst_0
     591: iload         8
     593: if_icmpgt     610
     596: iload         8
     598: iload_3
     599: if_icmpgt     606
     602: iconst_1
     603: goto          611
     606: iconst_0
     607: goto          611
     610: iconst_0
     611: ifeq          633
     614: aload         6
     616: new           #118                // class Coord
     619: dup
     620: iload         7
     622: iload         8
     624: invokespecial #251                // Method Coord."<init>":(II)V
     627: invokeinterface #256,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     632: pop
     633: iload         7
     635: iload_2
     636: if_icmpeq     837
     639: iinc          7, 1
     642: goto          582
     645: new           #258                // class kotlin/ranges/IntRange
     648: dup
     649: iload_1
     650: iconst_1
     651: iadd
     652: iload_3
     653: invokespecial #259                // Method kotlin/ranges/IntRange."<init>":(II)V
     656: checkcast     #22                 // class java/lang/Iterable
     659: astore        7
     661: iconst_0
     662: istore        8
     664: aload         7
     666: astore        9
     668: new           #69                 // class java/util/ArrayList
     671: dup
     672: aload         7
     674: bipush        10
     676: invokestatic  #240                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     679: invokespecial #243                // Method java/util/ArrayList."<init>":(I)V
     682: checkcast     #73                 // class java/util/Collection
     685: astore        10
     687: iconst_0
     688: istore        11
     690: aload         9
     692: invokeinterface #93,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     697: astore        12
     699: aload         12
     701: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     706: ifeq          752
     709: aload         12
     711: checkcast     #245                // class kotlin/collections/IntIterator
     714: invokevirtual #248                // Method kotlin/collections/IntIterator.nextInt:()I
     717: istore        13
     719: aload         10
     721: iload         13
     723: istore        14
     725: astore        16
     727: iconst_0
     728: istore        15
     730: new           #118                // class Coord
     733: dup
     734: iload_0
     735: iload         14
     737: invokespecial #251                // Method Coord."<init>":(II)V
     740: aload         16
     742: swap
     743: invokeinterface #157,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     748: pop
     749: goto          699
     752: aload         10
     754: checkcast     #115                // class java/util/List
     757: nop
     758: checkcast     #73                 // class java/util/Collection
     761: invokestatic  #255                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     764: astore        6
     766: goto          837
     769: iload_0
     770: iconst_1
     771: isub
     772: istore        7
     774: iconst_m1
     775: iload         7
     777: if_icmpge     837
     780: iload_1
     781: iload         7
     783: iload_0
     784: isub
     785: isub
     786: istore        8
     788: iconst_0
     789: iload         8
     791: if_icmpgt     808
     794: iload         8
     796: iload_3
     797: if_icmpgt     804
     800: iconst_1
     801: goto          809
     804: iconst_0
     805: goto          809
     808: iconst_0
     809: ifeq          831
     812: aload         6
     814: new           #118                // class Coord
     817: dup
     818: iload         7
     820: iload         8
     822: invokespecial #251                // Method Coord."<init>":(II)V
     825: invokeinterface #256,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     830: pop
     831: iinc          7, -1
     834: goto          774
     837: aload         4
     839: aload         6
     841: invokeinterface #256,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     846: pop
     847: iinc          5, 1
     850: goto          15
     853: aload         4
     855: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #274                // Method main:()V
       3: return

  private static final kotlin.sequences.Sequence main$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #278                // String line
       4: invokestatic  #211                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #280                // class java/lang/CharSequence
      11: invokestatic  #285                // Method kotlin/text/StringsKt.asSequence:(Ljava/lang/CharSequence;)Lkotlin/sequences/Sequence;
      14: areturn

  private static final Tile main$lambda$2$lambda$1(char);
    Code:
       0: getstatic     #291                // Field Tile.UNKNOWN:LTile;
       3: iload_0
       4: invokevirtual #294                // Method Tile.from:(C)LTile;
       7: areturn

  private static final kotlin.sequences.Sequence main$lambda$2(kotlin.sequences.Sequence);
    Code:
       0: aload_0
       1: ldc_w         #297                // String it
       4: invokestatic  #211                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokedynamic #303,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function1;
      13: invokestatic  #53                 // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      16: areturn

  private static final java.util.ArrayList main$lambda$3(kotlin.sequences.Sequence);
    Code:
       0: aload_0
       1: ldc_w         #297                // String it
       4: invokestatic  #211                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: new           #69                 // class java/util/ArrayList
      11: dup
      12: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
      15: checkcast     #73                 // class java/util/Collection
      18: invokestatic  #77                 // Method kotlin/sequences/SequencesKt.toCollection:(Lkotlin/sequences/Sequence;Ljava/util/Collection;)Ljava/util/Collection;
      21: checkcast     #69                 // class java/util/ArrayList
      24: areturn
}


object PigLatin {
    // List of char sequence that should be considered a single cluster of vowel / consonant.
    // Longer elements must appear first.
    private val clusters: List<Pair<String, Boolean>> = listOf(
        "sch" to false, "thr" to false,
        "xr" to true, "yt" to true,
        "ch" to false, "qu" to false, "th" to false, "rh" to false,
        "a" to true, "e" to true, "i" to true, "o" to true, "u" to true,
        "y" to false
    )

    private data class SplitResult(
        val head: String,
        val headIsVowel: Boolean,
        val tail: String
    )

    // Splits a non-empty word by first vowel / consonant cluster.
    // INVARIANT: head + tail == <input word>, where head and tail are from SplitResult.
    private fun splitFirstCluster(word: String): SplitResult {
        for ((prefix, prefixIsVowel) in clusters) {
            if (word.startsWith(prefix)) {
                return SplitResult(prefix, prefixIsVowel, word.substring(prefix.length))
            }
        }
        return SplitResult(word.substring(0, 1), false, word.substring(1))
    }

    // Translates a single word into Pig Latin. It is assumed that the word is not empty.
    private fun translateWord(word: String): String {
        val (head, headIsVowel, tail) = splitFirstCluster(word)
        return when {
            headIsVowel ->
                // Rule 1
                word + "ay"
            tail.startsWith("y") ->
                // Rule 4
                tail + head + "ay"
            tail.startsWith("qu") ->
                // Rule 3
                tail.substring(2) + head + "quay"
            else ->
                // Rule 2
                tail + head + "ay"
        }
    }

    fun translate(phrase: String): String =
        phrase.split(" ").map(::translateWord).joinToString(" ")
}

Compiled from "PigLatin.kt"
public final class PigLatin {
  public static final PigLatin INSTANCE;

  private static final java.util.List<kotlin.Pair<java.lang.String, java.lang.Boolean>> clusters;

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

  private final PigLatin$SplitResult splitFirstCluster(java.lang.String);
    Code:
       0: getstatic     #16                 // Field clusters:Ljava/util/List;
       3: invokeinterface #22,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       8: astore_2
       9: aload_2
      10: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      15: ifeq          88
      18: aload_2
      19: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      24: checkcast     #34                 // class kotlin/Pair
      27: astore_3
      28: aload_3
      29: invokevirtual #37                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      32: checkcast     #39                 // class java/lang/String
      35: astore        4
      37: aload_3
      38: invokevirtual #42                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      41: checkcast     #44                 // class java/lang/Boolean
      44: invokevirtual #47                 // Method java/lang/Boolean.booleanValue:()Z
      47: istore        5
      49: aload_1
      50: aload         4
      52: iconst_0
      53: iconst_2
      54: aconst_null
      55: invokestatic  #53                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      58: ifeq          9
      61: new           #55                 // class PigLatin$SplitResult
      64: dup
      65: aload         4
      67: iload         5
      69: aload_1
      70: aload         4
      72: invokevirtual #59                 // Method java/lang/String.length:()I
      75: invokevirtual #63                 // Method java/lang/String.substring:(I)Ljava/lang/String;
      78: dup
      79: ldc           #65                 // String substring(...)
      81: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      84: invokespecial #74                 // Method PigLatin$SplitResult."<init>":(Ljava/lang/String;ZLjava/lang/String;)V
      87: areturn
      88: new           #55                 // class PigLatin$SplitResult
      91: dup
      92: aload_1
      93: iconst_0
      94: iconst_1
      95: invokevirtual #77                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      98: dup
      99: ldc           #65                 // String substring(...)
     101: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     104: iconst_0
     105: aload_1
     106: iconst_1
     107: invokevirtual #63                 // Method java/lang/String.substring:(I)Ljava/lang/String;
     110: dup
     111: ldc           #65                 // String substring(...)
     113: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     116: invokespecial #74                 // Method PigLatin$SplitResult."<init>":(Ljava/lang/String;ZLjava/lang/String;)V
     119: areturn

  private final java.lang.String translateWord(java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #86                 // Method splitFirstCluster:(Ljava/lang/String;)LPigLatin$SplitResult;
       5: astore_2
       6: aload_2
       7: invokevirtual #89                 // Method PigLatin$SplitResult.component1:()Ljava/lang/String;
      10: astore_3
      11: aload_2
      12: invokevirtual #91                 // Method PigLatin$SplitResult.component2:()Z
      15: istore        4
      17: aload_2
      18: invokevirtual #94                 // Method PigLatin$SplitResult.component3:()Ljava/lang/String;
      21: astore        5
      23: nop
      24: iload         4
      26: ifeq          51
      29: new           #96                 // class java/lang/StringBuilder
      32: dup
      33: invokespecial #97                 // Method java/lang/StringBuilder."<init>":()V
      36: aload_1
      37: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      40: ldc           #103                // String ay
      42: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      45: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      48: goto          165
      51: aload         5
      53: ldc           #108                // String y
      55: iconst_0
      56: iconst_2
      57: aconst_null
      58: invokestatic  #53                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      61: ifeq          91
      64: new           #96                 // class java/lang/StringBuilder
      67: dup
      68: invokespecial #97                 // Method java/lang/StringBuilder."<init>":()V
      71: aload         5
      73: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      76: aload_3
      77: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      80: ldc           #103                // String ay
      82: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      85: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      88: goto          165
      91: aload         5
      93: ldc           #110                // String qu
      95: iconst_0
      96: iconst_2
      97: aconst_null
      98: invokestatic  #53                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     101: ifeq          141
     104: new           #96                 // class java/lang/StringBuilder
     107: dup
     108: invokespecial #97                 // Method java/lang/StringBuilder."<init>":()V
     111: aload         5
     113: iconst_2
     114: invokevirtual #63                 // Method java/lang/String.substring:(I)Ljava/lang/String;
     117: dup
     118: ldc           #65                 // String substring(...)
     120: invokestatic  #71                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     123: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     126: aload_3
     127: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     130: ldc           #112                // String quay
     132: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     135: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     138: goto          165
     141: new           #96                 // class java/lang/StringBuilder
     144: dup
     145: invokespecial #97                 // Method java/lang/StringBuilder."<init>":()V
     148: aload         5
     150: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     153: aload_3
     154: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     157: ldc           #103                // String ay
     159: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     162: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     165: areturn

  public final java.lang.String translate(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #119                // String phrase
       3: invokestatic  #122                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #124                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #39                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #126                // String
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #130                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #132                // class java/lang/Iterable
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: astore        4
      38: new           #134                // class java/util/ArrayList
      41: dup
      42: aload_2
      43: bipush        10
      45: invokestatic  #140                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #143                // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #145                // class java/util/Collection
      54: astore        5
      56: iconst_0
      57: istore        6
      59: aload         4
      61: invokeinterface #146,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      66: astore        7
      68: aload         7
      70: invokeinterface #28,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      75: ifeq          119
      78: aload         7
      80: invokeinterface #32,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      85: astore        8
      87: aload         5
      89: aload         8
      91: checkcast     #39                 // class java/lang/String
      94: astore        9
      96: astore        11
      98: iconst_0
      99: istore        10
     101: aload_0
     102: aload         9
     104: invokespecial #148                // Method translateWord:(Ljava/lang/String;)Ljava/lang/String;
     107: aload         11
     109: swap
     110: invokeinterface #152,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          68
     119: aload         5
     121: checkcast     #18                 // class java/util/List
     124: nop
     125: checkcast     #132                // class java/lang/Iterable
     128: ldc           #126                // String
     130: checkcast     #124                // class java/lang/CharSequence
     133: aconst_null
     134: aconst_null
     135: iconst_0
     136: aconst_null
     137: aconst_null
     138: bipush        62
     140: aconst_null
     141: invokestatic  #156                // 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;
     144: areturn

  static {};
    Code:
       0: new           #2                  // class PigLatin
       3: dup
       4: invokespecial #170                // Method "<init>":()V
       7: putstatic     #173                // Field INSTANCE:LPigLatin;
      10: bipush        14
      12: anewarray     #34                 // class kotlin/Pair
      15: astore_0
      16: aload_0
      17: iconst_0
      18: ldc           #175                // String sch
      20: iconst_0
      21: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      24: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      27: aastore
      28: aload_0
      29: iconst_1
      30: ldc           #187                // String thr
      32: iconst_0
      33: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      36: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      39: aastore
      40: aload_0
      41: iconst_2
      42: ldc           #189                // String xr
      44: iconst_1
      45: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      48: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      51: aastore
      52: aload_0
      53: iconst_3
      54: ldc           #191                // String yt
      56: iconst_1
      57: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      60: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      63: aastore
      64: aload_0
      65: iconst_4
      66: ldc           #193                // String ch
      68: iconst_0
      69: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      72: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      75: aastore
      76: aload_0
      77: iconst_5
      78: ldc           #110                // String qu
      80: iconst_0
      81: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      84: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      87: aastore
      88: aload_0
      89: bipush        6
      91: ldc           #195                // String th
      93: iconst_0
      94: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      97: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     100: aastore
     101: aload_0
     102: bipush        7
     104: ldc           #197                // String rh
     106: iconst_0
     107: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     110: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     113: aastore
     114: aload_0
     115: bipush        8
     117: ldc           #199                // String a
     119: iconst_1
     120: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     123: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     126: aastore
     127: aload_0
     128: bipush        9
     130: ldc           #201                // String e
     132: iconst_1
     133: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     136: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     139: aastore
     140: aload_0
     141: bipush        10
     143: ldc           #203                // String i
     145: iconst_1
     146: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     149: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     152: aastore
     153: aload_0
     154: bipush        11
     156: ldc           #205                // String o
     158: iconst_1
     159: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     162: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     165: aastore
     166: aload_0
     167: bipush        12
     169: ldc           #207                // String u
     171: iconst_1
     172: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     175: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     178: aastore
     179: aload_0
     180: bipush        13
     182: ldc           #108                // String y
     184: iconst_0
     185: invokestatic  #179                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     188: invokestatic  #185                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     191: aastore
     192: aload_0
     193: invokestatic  #211                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     196: putstatic     #16                 // Field clusters:Ljava/util/List;
     199: return
}

Compiled from "PigLatin.kt"
final class PigLatin$SplitResult {
  private final java.lang.String head;

  private final boolean headIsVowel;

  private final java.lang.String tail;

  public PigLatin$SplitResult(java.lang.String, boolean, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String head
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #17                 // String tail
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #20                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #23                 // Field head:Ljava/lang/String;
      21: aload_0
      22: iload_2
      23: putfield      #27                 // Field headIsVowel:Z
      26: aload_0
      27: aload_3
      28: putfield      #29                 // Field tail:Ljava/lang/String;
      31: return

  public final java.lang.String getHead();
    Code:
       0: aload_0
       1: getfield      #23                 // Field head:Ljava/lang/String;
       4: areturn

  public final boolean getHeadIsVowel();
    Code:
       0: aload_0
       1: getfield      #27                 // Field headIsVowel:Z
       4: ireturn

  public final java.lang.String getTail();
    Code:
       0: aload_0
       1: getfield      #29                 // Field tail:Ljava/lang/String;
       4: areturn

  public final java.lang.String component1();
    Code:
       0: aload_0
       1: getfield      #23                 // Field head:Ljava/lang/String;
       4: areturn

  public final boolean component2();
    Code:
       0: aload_0
       1: getfield      #27                 // Field headIsVowel:Z
       4: ireturn

  public final java.lang.String component3();
    Code:
       0: aload_0
       1: getfield      #29                 // Field tail:Ljava/lang/String;
       4: areturn

  public final PigLatin$SplitResult copy(java.lang.String, boolean, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String head
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #17                 // String tail
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class PigLatin$SplitResult
      15: dup
      16: aload_1
      17: iload_2
      18: aload_3
      19: invokespecial #43                 // Method "<init>":(Ljava/lang/String;ZLjava/lang/String;)V
      22: areturn

  public static PigLatin$SplitResult copy$default(PigLatin$SplitResult, java.lang.String, boolean, java.lang.String, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #23                 // Field head:Ljava/lang/String;
      11: astore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #27                 // Field headIsVowel:Z
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #29                 // Field tail:Ljava/lang/String;
      35: astore_3
      36: aload_0
      37: aload_1
      38: iload_2
      39: aload_3
      40: invokevirtual #47                 // Method copy:(Ljava/lang/String;ZLjava/lang/String;)LPigLatin$SplitResult;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #50                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #51                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #53                 // String SplitResult(head=
       9: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #23                 // Field head:Ljava/lang/String;
      16: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: ldc           #59                 // String , headIsVowel=
      21: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #27                 // Field headIsVowel:Z
      28: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
      31: ldc           #64                 // String , tail=
      33: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #29                 // Field tail:Ljava/lang/String;
      40: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #67                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #23                 // Field head:Ljava/lang/String;
       4: invokevirtual #75                 // Method java/lang/String.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #27                 // Field headIsVowel:Z
      16: invokestatic  #80                 // Method java/lang/Boolean.hashCode:(Z)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #29                 // Field tail:Ljava/lang/String;
      29: invokevirtual #75                 // Method java/lang/String.hashCode:()I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class PigLatin$SplitResult
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class PigLatin$SplitResult
      20: astore_2
      21: aload_0
      22: getfield      #23                 // Field head:Ljava/lang/String;
      25: aload_2
      26: getfield      #23                 // Field head:Ljava/lang/String;
      29: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #27                 // Field headIsVowel:Z
      41: aload_2
      42: getfield      #27                 // Field headIsVowel:Z
      45: if_icmpeq     50
      48: iconst_0
      49: ireturn
      50: aload_0
      51: getfield      #29                 // Field tail:Ljava/lang/String;
      54: aload_2
      55: getfield      #29                 // Field tail:Ljava/lang/String;
      58: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      61: ifne          66
      64: iconst_0
      65: ireturn
      66: iconst_1
      67: ireturn
}


fun <T:Comparable<T>> merge(a: List<T>, b: List<T>): List<T> {
    if (a.isEmpty() && b.isNotEmpty()) return b
    if (b.isEmpty() && a.isNotEmpty()) return a

    val (ah, at) = Pair(a[0], a.drop(1))
    val (bh, bt) = Pair(b[0], b.drop(1))

    return when {
        ah >= bh -> listOf(bh) + merge(a, bt)
        else -> listOf(ah) + merge(at, b)
    }
}

fun <T:Comparable<T>> mergeSort(list: List<T>): List<T> {
    val len = list.count()
    if (len < 2) return list

    val half = kotlin.math.ceil((len.toDouble() / 2)).toInt()
    val (left, right) = list.chunked(half)

    return merge(mergeSort(left), mergeSort(right))
}

fun main() {
    val sorted = mergeSort(listOf(6, 5, 2, 3, 0, 1))
    println("sorted: $sorted")
}

Compiled from "mergeSort.kt"
public final class MergeSortKt {
  public static final <T extends java.lang.Comparable<? super T>> java.util.List<T> merge(java.util.List<? extends T>, java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #10                 // String a
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String b
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokeinterface #24,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      18: ifeq          43
      21: aload_1
      22: checkcast     #26                 // class java/util/Collection
      25: invokeinterface #27,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      30: ifne          37
      33: iconst_1
      34: goto          38
      37: iconst_0
      38: ifeq          43
      41: aload_1
      42: areturn
      43: aload_1
      44: invokeinterface #24,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      49: ifeq          74
      52: aload_0
      53: checkcast     #26                 // class java/util/Collection
      56: invokeinterface #27,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      61: ifne          68
      64: iconst_1
      65: goto          69
      68: iconst_0
      69: ifeq          74
      72: aload_0
      73: areturn
      74: new           #29                 // class kotlin/Pair
      77: dup
      78: aload_0
      79: iconst_0
      80: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      85: aload_0
      86: checkcast     #35                 // class java/lang/Iterable
      89: iconst_1
      90: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      93: invokespecial #45                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      96: astore_2
      97: aload_2
      98: invokevirtual #49                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     101: checkcast     #51                 // class java/lang/Comparable
     104: astore_3
     105: aload_2
     106: invokevirtual #54                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     109: checkcast     #20                 // class java/util/List
     112: astore        4
     114: new           #29                 // class kotlin/Pair
     117: dup
     118: aload_1
     119: iconst_0
     120: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: aload_1
     126: checkcast     #35                 // class java/lang/Iterable
     129: iconst_1
     130: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     133: invokespecial #45                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     136: astore        5
     138: aload         5
     140: invokevirtual #49                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     143: checkcast     #51                 // class java/lang/Comparable
     146: astore        6
     148: aload         5
     150: invokevirtual #54                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     153: checkcast     #20                 // class java/util/List
     156: astore        7
     158: nop
     159: aload_3
     160: aload         6
     162: invokeinterface #58,  2           // InterfaceMethod java/lang/Comparable.compareTo:(Ljava/lang/Object;)I
     167: iflt          193
     170: aload         6
     172: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     175: checkcast     #26                 // class java/util/Collection
     178: aload_0
     179: aload         7
     181: invokestatic  #64                 // Method merge:(Ljava/util/List;Ljava/util/List;)Ljava/util/List;
     184: checkcast     #35                 // class java/lang/Iterable
     187: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     190: goto          212
     193: aload_3
     194: invokestatic  #62                 // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     197: checkcast     #26                 // class java/util/Collection
     200: aload         4
     202: aload_1
     203: invokestatic  #64                 // Method merge:(Ljava/util/List;Ljava/util/List;)Ljava/util/List;
     206: checkcast     #35                 // class java/lang/Iterable
     209: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     212: areturn

  public static final <T extends java.lang.Comparable<? super T>> java.util.List<T> mergeSort(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #79                 // String list
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #26                 // class java/util/Collection
      10: invokeinterface #83,  1           // InterfaceMethod java/util/Collection.size:()I
      15: istore_1
      16: iload_1
      17: iconst_2
      18: if_icmpge     23
      21: aload_0
      22: areturn
      23: iload_1
      24: i2d
      25: iconst_2
      26: i2d
      27: ddiv
      28: invokestatic  #89                 // Method java/lang/Math.ceil:(D)D
      31: d2i
      32: istore_2
      33: aload_0
      34: checkcast     #35                 // class java/lang/Iterable
      37: iload_2
      38: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
      41: astore_3
      42: aload_3
      43: iconst_0
      44: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      49: checkcast     #20                 // class java/util/List
      52: astore        4
      54: aload_3
      55: iconst_1
      56: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      61: checkcast     #20                 // class java/util/List
      64: astore        5
      66: aload         4
      68: invokestatic  #94                 // Method mergeSort:(Ljava/util/List;)Ljava/util/List;
      71: aload         5
      73: invokestatic  #94                 // Method mergeSort:(Ljava/util/List;)Ljava/util/List;
      76: invokestatic  #64                 // Method merge:(Ljava/util/List;Ljava/util/List;)Ljava/util/List;
      79: areturn

  public static final void main();
    Code:
       0: bipush        6
       2: anewarray     #103                // class java/lang/Integer
       5: astore_1
       6: aload_1
       7: iconst_0
       8: bipush        6
      10: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: aastore
      14: aload_1
      15: iconst_1
      16: iconst_5
      17: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: aastore
      21: aload_1
      22: iconst_2
      23: iconst_2
      24: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: aastore
      28: aload_1
      29: iconst_3
      30: iconst_3
      31: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: aastore
      35: aload_1
      36: iconst_4
      37: iconst_0
      38: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: aastore
      42: aload_1
      43: iconst_5
      44: iconst_1
      45: invokestatic  #107                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      48: aastore
      49: aload_1
      50: invokestatic  #110                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      53: invokestatic  #94                 // Method mergeSort:(Ljava/util/List;)Ljava/util/List;
      56: astore_0
      57: new           #112                // class java/lang/StringBuilder
      60: dup
      61: invokespecial #114                // Method java/lang/StringBuilder."<init>":()V
      64: ldc           #116                // String sorted:
      66: invokevirtual #120                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      69: aload_0
      70: invokevirtual #123                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      73: invokevirtual #127                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      76: getstatic     #133                // Field java/lang/System.out:Ljava/io/PrintStream;
      79: swap
      80: invokevirtual #139                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      83: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #143                // Method main:()V
       3: return
}


private fun largestPrimeDivisors(n: Int): IntArray {
	val largestPrimeDivisors = IntArray(n + 1) { it }
	for (i in 2..n) {
		if (largestPrimeDivisors[i] < i) continue
		var j = i * i
		if (j > n) break
		do {
			largestPrimeDivisors[j] = i
			j += i
		} while (j <= n)
	}
	return largestPrimeDivisors
}

private fun divisorsOf(n: Int, largestPrimeDivisors: IntArray): IntArray {
	if (n == 1) return intArrayOf(1)
	val p = largestPrimeDivisors[n]
	if (p == n) return intArrayOf(1, n)
	var m = n / p
	var counter = 2
	while (m % p == 0) {
		m /= p
		counter++
	}
	val divisorsOfM = divisorsOf(m, largestPrimeDivisors)
	val result = IntArray(divisorsOfM.size * counter)
	for (i in divisorsOfM.indices) {
		var d = divisorsOfM[i]
		for (j in 0 until counter) {
			result[i * counter + j] = d
			d *= p
		}
	}
	return result
}

Compiled from "numberTheory.kt"
public final class NumberTheoryKt {
  private static final int[] largestPrimeDivisors(int);
    Code:
       0: iconst_0
       1: istore_2
       2: iload_0
       3: iconst_1
       4: iadd
       5: istore_3
       6: iload_3
       7: newarray       int
       9: astore        4
      11: iload_2
      12: iload_3
      13: if_icmpge     32
      16: iload_2
      17: istore        5
      19: aload         4
      21: iload         5
      23: iload         5
      25: iastore
      26: iinc          2, 1
      29: goto          11
      32: aload         4
      34: astore_1
      35: iconst_2
      36: istore_2
      37: iload_2
      38: iload_0
      39: if_icmpgt     82
      42: aload_1
      43: iload_2
      44: iaload
      45: iload_2
      46: if_icmplt     71
      49: iload_2
      50: iload_2
      51: imul
      52: istore_3
      53: iload_3
      54: iload_0
      55: if_icmpgt     82
      58: aload_1
      59: iload_3
      60: iload_2
      61: iastore
      62: iload_3
      63: iload_2
      64: iadd
      65: istore_3
      66: iload_3
      67: iload_0
      68: if_icmple     58
      71: iload_2
      72: iload_0
      73: if_icmpeq     82
      76: iinc          2, 1
      79: goto          42
      82: aload_1
      83: areturn

  private static final int[] divisorsOf(int, int[]);
    Code:
       0: iload_0
       1: iconst_1
       2: if_icmpne     15
       5: iconst_1
       6: newarray       int
       8: astore_2
       9: aload_2
      10: iconst_0
      11: iconst_1
      12: iastore
      13: aload_2
      14: areturn
      15: aload_1
      16: iload_0
      17: iaload
      18: istore_2
      19: iload_2
      20: iload_0
      21: if_icmpne     38
      24: iconst_2
      25: newarray       int
      27: astore_3
      28: aload_3
      29: iconst_0
      30: iconst_1
      31: iastore
      32: aload_3
      33: iconst_1
      34: iload_0
      35: iastore
      36: aload_3
      37: areturn
      38: iload_0
      39: iload_2
      40: idiv
      41: istore_3
      42: iconst_2
      43: istore        4
      45: iload_3
      46: iload_2
      47: irem
      48: ifne          61
      51: iload_3
      52: iload_2
      53: idiv
      54: istore_3
      55: iinc          4, 1
      58: goto          45
      61: iload_3
      62: aload_1
      63: invokestatic  #16                 // Method divisorsOf:(I[I)[I
      66: astore        5
      68: aload         5
      70: arraylength
      71: iload         4
      73: imul
      74: newarray       int
      76: astore        6
      78: iconst_0
      79: istore        7
      81: aload         5
      83: arraylength
      84: istore        8
      86: iload         7
      88: iload         8
      90: if_icmpge     145
      93: aload         5
      95: iload         7
      97: iaload
      98: istore        9
     100: iconst_0
     101: istore        10
     103: iload         4
     105: istore        11
     107: iload         10
     109: iload         11
     111: if_icmpge     139
     114: aload         6
     116: iload         7
     118: iload         4
     120: imul
     121: iload         10
     123: iadd
     124: iload         9
     126: iastore
     127: iload         9
     129: iload_2
     130: imul
     131: istore        9
     133: iinc          10, 1
     136: goto          107
     139: iinc          7, 1
     142: goto          86
     145: aload         6
     147: areturn
}