#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double multi_apply(double (*)(double), int, double);
double multi_apply_2(double (*f)(double), double (*g)(double), int n,
                     double s) {
  if (n == 1)
    return f(g(s));
  return f(g(multi_apply(f, n - 1, s)));
}


x86 assembly (clang, -O0):
<multi_apply_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1155 <multi_apply_2+0x45>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsd  -0x28(%rbp),%xmm0
call   *%rax
mov    -0x30(%rbp),%rax
call   *%rax
movsd  %xmm0,-0x8(%rbp)
jmp    118a <multi_apply_2+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
movsd  -0x28(%rbp),%xmm0
call   1030 <multi_apply@plt>
mov    -0x40(%rbp),%rax
call   *%rax
mov    -0x38(%rbp),%rax
call   *%rax
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multi_apply_2>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x1,%edx
jne    1121 <multi_apply_2+0x11>
mov    %rdi,%rbx
jmp    112e <multi_apply_2+0x1e>
add    $0xffffffff,%edx
mov    %rdi,%rbx
mov    %edx,%esi
call   1030 <multi_apply@plt>
call   *%r14
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    *%rax

LLVM IR (-O0):
define double @multi_apply_2(double (double)* %0, double (double)* %1, i32 %2, double %3) {
%5 = alloca double
%6 = alloca double (double)*
%7 = alloca double (double)*
%8 = alloca i32
%9 = alloca double
store double (double)* %0, double (double)** %6
store double (double)* %1, double (double)** %7
store i32 %2, i32* %8
store double %3, double* %9
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %4
%13 = load double (double)*, double (double)** %6
%14 = load double (double)*, double (double)** %7
%15 = load double, double* %9
%16 = call double %14(double %15)
%17 = call double %13(double %16)
store double %17, double* %5
br label %28
18: ; preds = %4
%19 = load double (double)*, double (double)** %6
%20 = load double (double)*, double (double)** %7
%21 = load double (double)*, double (double)** %6
%22 = load i32, i32* %8
%23 = sub nsw i32 %22, 1
%24 = load double, double* %9
%25 = call double @multi_apply(double (double)* %21, i32 %23, double %24)
%26 = call double %20(double %25)
%27 = call double %19(double %26)
store double %27, double* %5
br label %28
28: ; preds = %18, %12
%29 = load double, double* %5
ret double %29
}

LLVM IR (-O2):
define double @multi_apply_2(double (double)* %0, double (double)* nocapture %1, i32 %2, double %3) {
%5 = icmp eq i32 %2, 1
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = add nsw i32 %2, -1
%8 = tail call double @multi_apply(double (double)* %0, i32 %7, double %3)
br label %9
9: ; preds = %4, %6
%10 = phi double [ %8, %6 ], [ %3, %4 ]
%11 = tail call double %1(double %10)
%12 = tail call double %0(double %11)
ret double %12
}