#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 */
int h_equation(double, double, double);
int sum_function(double, double, double, double (*)(double));
double trap(double a, double b, double n, double (*f)(double)) {
  return (h_equation(a, b, n) / 2) * (f(a) + f(b) + sum_function(a, b, n, f));
}


x86 assembly (clang, -O0):
<trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %rdi,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
call   1030 <h_equation@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x8(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
mov    -0x20(%rbp),%rdi
call   1040 <sum_function@plt>
movsd  -0x30(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %eax,%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trap>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  %xmm2,0x28(%rsp)
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <h_equation@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
call   *%rbx
movsd  %xmm0,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
call   *%rbx
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x28(%rsp),%xmm2
mov    %rbx,%rdi
call   1040 <sum_function@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x8(%rsp),%xmm0
mulsd  0x20(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @trap(double %0, double %1, double %2, double (double)* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double (double)*
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store double (double)* %3, double (double)** %8
%9 = load double, double* %5
%10 = load double, double* %6
%11 = load double, double* %7
%12 = call i32 @h_equation(double %9, double %10, double %11)
%13 = sdiv i32 %12, 2
%14 = sitofp i32 %13 to double
%15 = load double (double)*, double (double)** %8
%16 = load double, double* %5
%17 = call double %15(double %16)
%18 = load double (double)*, double (double)** %8
%19 = load double, double* %6
%20 = call double %18(double %19)
%21 = fadd double %17, %20
%22 = load double, double* %5
%23 = load double, double* %6
%24 = load double, double* %7
%25 = load double (double)*, double (double)** %8
%26 = call i32 @sum_function(double %22, double %23, double %24, double (double)* %25)
%27 = sitofp i32 %26 to double
%28 = fadd double %21, %27
%29 = fmul double %14, %28
ret double %29
}

LLVM IR (-O2):
define double @trap(double %0, double %1, double %2, double (double)* %3) {
%5 = tail call i32 @h_equation(double %0, double %1, double %2)
%6 = sdiv i32 %5, 2
%7 = sitofp i32 %6 to double
%8 = tail call double %3(double %0)
%9 = tail call double %3(double %1)
%10 = fadd double %8, %9
%11 = tail call i32 @sum_function(double %0, double %1, double %2, double (double)* %3)
%12 = sitofp i32 %11 to double
%13 = fadd double %10, %12
%14 = fmul double %13, %7
ret double %14
}