#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 f(double);
double Trap(double a, double b, int n, double h) {
  double integral;
  int k;
  integral = (f(a) + f(b)) / 2.0;
  for (k = 1; k <= n - 1; k++) {
    integral += f(a + k * h);
  }
  integral = integral * h;
  return integral;
}


x86 assembly (clang, -O0):
<Trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xea9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11ac <Trap+0x9c>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <f@plt>
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1167 <Trap+0x57>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Trap>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm2,0x10(%rsp)
mov    %edi,%ebx
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x18(%rsp)
call   1030 <f@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1030 <f@plt>
addsd  0x8(%rsp),%xmm0
mulsd  0xeb5(%rip),%xmm0
cmp    $0x2,%ebx
jl     11a6 <Trap+0x96>
add    $0xffffffff,%ebx
movsd  0xead(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
movapd %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
call   1030 <f@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm0
addsd  0xe67(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1160 <Trap+0x50>
mulsd  0x10(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @Trap(double %0, double %1, i32 %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double %3, double* %8
%11 = load double, double* %5
%12 = call double @f(double %11)
%13 = load double, double* %6
%14 = call double @f(double %13)
%15 = fadd double %12, %14
%16 = fdiv double %15, 2.000000e+00
store double %16, double* %9
store i32 1, i32* %10
br label %17
17: ; preds = %31, %4
%18 = load i32, i32* %10
%19 = load i32, i32* %7
%20 = sub nsw i32 %19, 1
%21 = icmp sle i32 %18, %20
br i1 %21, label %22, label %34
22: ; preds = %17
%23 = load double, double* %5
%24 = load i32, i32* %10
%25 = sitofp i32 %24 to double
%26 = load double, double* %8
%27 = call double @llvm.fmuladd.f64(double %25, double %26, double %23)
%28 = call double @f(double %27)
%29 = load double, double* %9
%30 = fadd double %29, %28
store double %30, double* %9
br label %31
31: ; preds = %22
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %17
34: ; preds = %17
%35 = load double, double* %9
%36 = load double, double* %8
%37 = fmul double %35, %36
store double %37, double* %9
%38 = load double, double* %9
ret double %38
}

LLVM IR (-O2):
define double @Trap(double %0, double %1, i32 %2, double %3) {
%5 = tail call double @f(double %0)
%6 = tail call double @f(double %1)
%7 = fadd double %5, %6
%8 = fmul double %7, 5.000000e-01
%9 = icmp sgt i32 %2, 1
br i1 %9, label %10, label %19
10: ; preds = %4, %10
%11 = phi i32 [ %17, %10 ], [ 1, %4 ]
%12 = phi double [ %16, %10 ], [ %8, %4 ]
%13 = sitofp i32 %11 to double
%14 = tail call double @llvm.fmuladd.f64(double %13, double %3, double %0)
%15 = tail call double @f(double %14)
%16 = fadd double %12, %15
%17 = add nuw nsw i32 %11, 1
%18 = icmp eq i32 %17, %2
br i1 %18, label %19, label %10
19: ; preds = %10, %4
%20 = phi double [ %8, %4 ], [ %16, %10 ]
%21 = fmul double %20, %3
ret double %21
}