Repository: JetBrains/kotlin
File: compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/inline/FunctionInlining.kt (Kotlin)

Code before:
                        if (callSite.getValueArgument(index) == null) {
                            // Default values can recursively reference [callee] - transform only needed.
                            param.defaultValue = param.defaultValue?.transform(this@FunctionInlining, null)
                        }
                    }
                }
            }

            val evaluationStatements = evaluateArguments(callSite, copiedCallee)
            val statements = (copiedCallee.body as? IrBlockBody)?.statements
                ?: error("Body not found for function ${callee.render()}")

            val irReturnableBlockSymbol = IrReturnableBlockSymbolImpl()
            val endOffset = statements.lastOrNull()?.endOffset ?: callee.endOffset
            /* creates irBuilder appending to the end of the given returnable block: thus why we initialize
             * irBuilder with (..., endOffset, endOffset).
             */
            val irBuilder = context.createIrBuilder(irReturnableBlockSymbol, endOffset, endOffset)

            val transformer = ParameterSubstitutor()
            val newStatements = mutableListOf<IrStatement>()

            newStatements.addAll(evaluationStatements)
            statements.mapTo(newStatements) { it.transform(transformer, data = null) as IrStatement }

            saveParameterToExpressionMapping(callee, copiedCallee)

            return IrReturnableBlockImpl(
                startOffset = callSite.startOffset,
                endOffset = callSite.endOffset,
                type = callSite.type,
                symbol = irReturnableBlockSymbol,
                origin = null,
                statements = newStatements,
                inlineFunctionSymbol = callee.symbol
            ).apply {
                transformChildrenVoid(object : IrElementTransformerVoid() {
                    override fun visitReturn(expression: IrReturn): IrExpression {
                        expression.transformChildrenVoid(this)

                        if (expression.returnTargetSymbol == copiedCallee.symbol) {
                            val expr =
                                if (insertAdditionalImplicitCasts)
                                    expression.value.implicitCastIfNeededTo(callSite.type)
                                else
                                    expression.value
                            return irBuilder.at(expression).irReturn(expr)
                        }
                        return expression
                    }
                })

Review comment (performance):
There should be variables for these parameters in most cases. I think they are not shown now, as they are temporary variables. What do you think about creating a separate origin for them? I'm not sure about the name and scope, but this should be an easier solution, at least for cases, where variables are not optimized-out. 

Code after:
                // to be removed ASAP along with registering every PIR declaration.

                parent = callee.parent
                if (performRecursiveInline) {
                    body?.transformChildrenVoid()
                    valueParameters.forEachIndexed { index, param ->
                        if (callSite.getValueArgument(index) == null) {
                            // Default values can recursively reference [callee] - transform only needed.
                            param.defaultValue = param.defaultValue?.transform(this@FunctionInlining, null)
                        }
                    }
                }
            }

            val evaluationStatements = evaluateArguments(callSite, copiedCallee)
            val statements = (copiedCallee.body as? IrBlockBody)?.statements
                ?: error("Body not found for function ${callee.render()}")

            val irReturnableBlockSymbol = IrReturnableBlockSymbolImpl()
            val endOffset = statements.lastOrNull()?.endOffset ?: callee.endOffset
            /* creates irBuilder appending to the end of the given returnable block: thus why we initialize
             * irBuilder with (..., endOffset, endOffset).
             */
            val irBuilder = context.createIrBuilder(irReturnableBlockSymbol, endOffset, endOffset)

            val transformer = ParameterSubstitutor()
            val newStatements = mutableListOf<IrStatement>()

            newStatements.addAll(evaluationStatements)
            statements.mapTo(newStatements) { it.transform(transformer, data = null) as IrStatement }

            return IrReturnableBlockImpl(
                startOffset = callSite.startOffset,
                endOffset = callSite.endOffset,
                type = callSite.type,
                symbol = irReturnableBlockSymbol,
                origin = null,
                statements = newStatements,
                inlineFunctionSymbol = inlineFunctionResolver.getFunctionSymbol(callee)
            ).apply {
                transformChildrenVoid(object : IrElementTransformerVoid() {
                    override fun visitReturn(expression: IrReturn): IrExpression {
                        expression.transformChildrenVoid(this)

                        if (expression.returnTargetSymbol == copiedCallee.symbol) {
                            val expr =
                                if (insertAdditionalImplicitCasts)
                                    expression.value.implicitCastIfNeededTo(callSite.type)
                                else
                                    expression.value
                            return irBuilder.at(expression).irReturn(expr)