data class Counter {
  var i: Int
    field = i
    get
    set

  constructor(i: Int = 0) /* primary */ {
    super/*Any*/()
    /* <init>() */

  }

  operator fun component1(): Int {
    return <this>.#i
  }

  fun copy(i: Int = <this>.#i): Counter {
    return Counter(i = i)
  }

  override operator fun equals(other: Any?): Boolean {
    when {
      EQEQEQ(arg0 = <this>, arg1 = other) -> return true
    }
    when {
      other !is Counter -> return false
    }
    val tmp_0: Counter = other as Counter
    when {
      EQEQ(arg0 = <this>.#i, arg1 = tmp_0.#i).not() -> return false
    }
    return true
  }

  override fun hashCode(): Int {
    return <this>.#i.hashCode()
  }

  override fun toString(): String {
    return "Counter(" + "i=" + <this>.#i + ")"
  }

}

data class CounterConfig {
  val max: Int
    field = max
    get

  constructor(max: Int = 10) /* primary */ {
    super/*Any*/()
    /* <init>() */

  }

  operator fun component1(): Int {
    return <this>.#max
  }

  fun copy(max: Int = <this>.#max): CounterConfig {
    return CounterConfig(max = max)
  }

  override operator fun equals(other: Any?): Boolean {
    when {
      EQEQEQ(arg0 = <this>, arg1 = other) -> return true
    }
    when {
      other !is CounterConfig -> return false
    }
    val tmp_1: CounterConfig = other as CounterConfig
    when {
      EQEQ(arg0 = <this>.#max, arg1 = tmp_1.#max).not() -> return false
    }
    return true
  }

  override fun hashCode(): Int {
    return <this>.#max.hashCode()
  }

  override fun toString(): String {
    return "CounterConfig(" + "max=" + <this>.#max + ")"
  }

}

class CounterIterator : Iterator<Int> {
  private /* final field */ val contextReceiverField0: CounterConfig
  private val counter: Counter
    field = counter
    private get

  constructor($context_receiver_0: CounterConfig, counter: Counter) /* primary */ {
    super/*Any*/()
    <this>.#contextReceiverField0 = $context_receiver_0
    /* <init>() */

  }

  override operator fun hasNext(): Boolean {
    return less(arg0 = <this>.<get-counter>().<get-i>(), arg1 = <this>.#contextReceiverField0.<get-max>())
  }

  override operator fun next(): Int {
    return { // BLOCK
      val tmp_2: Counter = <this>.<get-counter>()
      { // BLOCK
        val tmp_3: Int = tmp_2.<get-i>()
        tmp_2.<set-i>(<set-?> = tmp_3.inc())
        tmp_3
      }
    }
  }

}

fun box(): String {
  var result: Int = 0
  with<CounterConfig, Unit>(receiver = CounterConfig(), block = local fun CounterConfig.<anonymous>() {
    { // BLOCK
      val tmp_4: CounterIterator = Counter().iterator($context_receiver_0 = $this$with)
      while (tmp_4.hasNext()) { // BLOCK
        val i: Int = tmp_4.next()
        { // BLOCK
          result = result.plus(other = i)
        }
      }
    }
  }
)
  return when {
    EQEQ(arg0 = result, arg1 = 45) -> "OK"
    else -> "fail"
  }
}

operator fun Counter.iterator($context_receiver_0: CounterConfig): CounterIterator {
  return with<CounterConfig, CounterIterator>(receiver = $context_receiver_0, block = local fun CounterConfig.<anonymous>(): CounterIterator {
    return CounterIterator($context_receiver_0 = $this$with, counter = <this>)
  }
)
}

