//
// Source
// ------------------------------------------

@file:OptIn(
  InternalComposeApi::class,
)
package test

import androidx.compose.runtime.InternalComposeApi
import androidx.compose.runtime.ComposeCompilerApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.NonRestartableComposable


    import kotlin.reflect.KProperty

    class Foo
    @Composable
    operator fun Foo.getValue(thisObj: Any?, property: KProperty<*>): Foo = this

    class FooDelegate {
        @Composable
        operator fun getValue(thisObj: Any?, property: KProperty<*>): FooDelegate = this
    }

    class Bar {
        @get:Composable
        val foo by Foo()
    }

    @Composable
    fun test() {
        val foo by Foo()
        val fooDelegate by FooDelegate()
        val bar = Bar()
        println(foo)
        println(fooDelegate)
        println(bar.foo)
    }

//
// Transformed IR
// ------------------------------------------

@StabilityInferred(parameters = 1)
class Foo {
  static val %stable: Int = 0
}
@Composable
@FunctionKeyMeta(key = 1275113351, startOffset = 342, endOffset = 409)
fun Foo.getValue(thisObj: Any?, property: KProperty<*>, %composer: Composer?, %changed: Int): Foo {
  sourceInformationMarkerStart(%composer, <>, "C(getValue)N(thisObj,property):Test.kt#2487m")
  if (isTraceInProgress()) {
    traceEventStart(<>, %changed, -1, <>)
  }
  val tmp0 = <this>
  if (isTraceInProgress()) {
    traceEventEnd()
  }
  sourceInformationMarkerEnd(%composer)
  return tmp0
}
@StabilityInferred(parameters = 1)
class FooDelegate {
  @Composable
  @FunctionKeyMeta(key = -734324405, startOffset = 472, endOffset = 543)
  fun getValue(thisObj: Any?, property: KProperty<*>, %composer: Composer?, %changed: Int): FooDelegate {
    sourceInformationMarkerStart(%composer, <>, "C(getValue)N(thisObj,property):Test.kt#2487m")
    if (isTraceInProgress()) {
      traceEventStart(<>, %changed, -1, <>)
    }
    val tmp0 = <this>
    if (isTraceInProgress()) {
      traceEventEnd()
    }
    sourceInformationMarkerEnd(%composer)
    return tmp0
  }
  static val %stable: Int = 0
}
@StabilityInferred(parameters = 1)
class Bar {
  val foo: Foo = Foo()
    @Composable @JvmName(name = "getFoo") @FunctionKeyMeta(key = -231152804, startOffset = 599, endOffset = 615)
    get() {
      sourceInformationMarkerStart(%composer, <>, "C(<get-foo>)<Foo()>:Test.kt#2487m")
      if (isTraceInProgress()) {
        traceEventStart(<>, %changed, -1, <>)
      }
      val tmp0 = <this>.foo%delegate.getValue(<this>, ::foo, %composer, 0b01110000 and %changed shl 0b0011)
      if (isTraceInProgress()) {
        traceEventEnd()
      }
      sourceInformationMarkerEnd(%composer)
      return tmp0
    }
  static val %stable: Int = 0
}
@Composable
@FunctionKeyMeta(key = 1149099302, startOffset = 643, endOffset = 826)
fun test(%composer: Composer?, %changed: Int) {
  %composer = %composer.startRestartGroup(<>)
  sourceInformation(%composer, "C(test)<foo>,<fooDel...>,<foo>:Test.kt#2487m")
  if (%composer.shouldExecute(%changed != 0, %changed and 0b0001)) {
    if (isTraceInProgress()) {
      traceEventStart(<>, %changed, -1, <>)
    }
    val foo by {
      val foo%delegate = Foo()
      @Composable @FunctionKeyMeta(key = -199623493, startOffset = 664, endOffset = 680)
      get(%composer: Composer?, %changed: Int) {
        sourceInformationMarkerStart(%composer, <>, "C(<get-foo>)<Foo()>:Test.kt#2487m")
        if (isTraceInProgress()) {
          traceEventStart(<>, %changed, -1, <>)
        }
        val tmp0 = foo%delegate.getValue(null, ::foo%delegate, %composer, 0b00110000)
        if (isTraceInProgress()) {
          traceEventEnd()
        }
        sourceInformationMarkerEnd(%composer)
        return tmp0
      }
    }
    val fooDelegate by {
      val fooDelegate%delegate = FooDelegate()
      @Composable @FunctionKeyMeta(key = 1996230513, startOffset = 689, endOffset = 721)
      get(%composer: Composer?, %changed: Int) {
        sourceInformationMarkerStart(%composer, <>, "C(<get-fooDelegate>)<FooDel...>:Test.kt#2487m")
        if (isTraceInProgress()) {
          traceEventStart(<>, %changed, -1, <>)
        }
        val tmp0 = fooDelegate%delegate.getValue(null, ::fooDelegate%delegate, %composer, 0b0110)
        if (isTraceInProgress()) {
          traceEventEnd()
        }
        sourceInformationMarkerEnd(%composer)
        return tmp0
      }
    }
    val bar = Bar()
    println(<get-foo>(%composer, 0))
    println(<get-fooDelegate>(%composer, 0))
    println(bar.<get-foo>(%composer, 0))
    if (isTraceInProgress()) {
      traceEventEnd()
    }
  } else {
    %composer.skipToGroupEnd()
  }
  %composer.endRestartGroup()?.updateScope { %composer: Composer?, %force: Int ->
    test(%composer, updateChangedFlags(%changed or 0b0001))
  }
}
