class C {
  val c: Int
    field = 42
    get

  constructor() /* primary */ {
    super/*Any*/()
    /* <init>() */

  }

}

class Param {
  constructor() /* primary */ {
    super/*Any*/()
    /* <init>() */

  }

}

class R {
  val r: Int
    field = 42
    get

  constructor() /* primary */ {
    super/*Any*/()
    /* <init>() */

  }

}

context($context_receiver_0: C)
fun R.f1(g: @ExtensionFunctionType Function3<C, R, Param, Unit>) {
  g.invoke(p1 = $context_receiver_0, p2 = <this>, p3 = Param())
}

context($context_receiver_0: C)
fun f2(g: Function2<C, Param, Unit>) {
  g.invoke(p1 = $context_receiver_0, p2 = Param())
}

context($context_receiver_0: C)
fun R.f3(g: @ExtensionFunctionType Function2<C, R, Unit>) {
  g.invoke(p1 = $context_receiver_0, p2 = <this>)
}

context($context_receiver_0: C)
fun f4(g: Function1<C, Unit>) {
  g.invoke(p1 = $context_receiver_0)
}

fun test() {
  val lf1: @ExtensionFunctionType Function3<C, R, Param, Unit> = context($context_receiver_0: C)
  local fun R.<anonymous>(<unused var>: Param) {
    <this>.<get-r>() /*~> Unit */
    $context_receiver_0.<get-c>() /*~> Unit */
  }

  val lf2: Function2<C, Param, Unit> = context($context_receiver_0: C)
  local fun <anonymous>(<unused var>: Param) {
    $context_receiver_0.<get-c>() /*~> Unit */
  }

  val lf3: @ExtensionFunctionType Function2<C, R, Unit> = context($context_receiver_0: C)
  local fun R.<anonymous>() {
    <this>.<get-r>() /*~> Unit */
    $context_receiver_0.<get-c>() /*~> Unit */
  }

  val lf4: Function1<C, Unit> = context($context_receiver_0: C)
  local fun <anonymous>() {
    $context_receiver_0.<get-c>() /*~> Unit */
  }

  with<C, Unit>(receiver = C(), block = local fun C.<anonymous>() {
    with<R, Unit>(receiver = R(), block = local fun R.<anonymous>() {
      f1(/* $context_receiver_0 = $this$with, <this> = $this$with, */ g = lf1)
      f1(/* $context_receiver_0 = $this$with, <this> = $this$with, */ g = context($context_receiver_0: C)
      local fun R.<anonymous>(<unused var>: Param) {
        $this$f1.<get-r>() /*~> Unit */
        $this$with.<get-c>() /*~> Unit */
      }
)
      f2(/* $context_receiver_0 = $this$with, */ g = lf2)
      f2(/* $context_receiver_0 = $this$with, */ g = context($context_receiver_0: C)
      local fun <anonymous>(<unused var>: Param) {
        $this$with.<get-c>() /*~> Unit */
      }
)
      f3(/* $context_receiver_0 = $this$with, <this> = $this$with, */ g = lf3)
      f3(/* $context_receiver_0 = $this$with, <this> = $this$with, */ g = context($context_receiver_0: C)
      local fun R.<anonymous>() {
        $this$f3.<get-r>() /*~> Unit */
        $this$with.<get-c>() /*~> Unit */
      }
)
      f4(/* $context_receiver_0 = $this$with, */ g = lf4)
      f4(/* $context_receiver_0 = $this$with, */ g = context($context_receiver_0: C)
      local fun <anonymous>() {
        $this$with.<get-c>() /*~> Unit */
      }
)
    }
)
  }
)
}

