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


x86 assembly (clang, -O0):
<Trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xea9(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11c7 <Trap+0xb7>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <f@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1167 <Trap+0x57>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x50,%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 double
%11 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double %3, double* %8
%12 = load double, double* %5
%13 = call double @f(double %12)
%14 = load double, double* %6
%15 = call double @f(double %14)
%16 = fadd double %13, %15
%17 = fdiv double %16, 2.000000e+00
store double %17, double* %9
store i32 1, i32* %11
br label %18
18: ; preds = %33, %4
%19 = load i32, i32* %11
%20 = load i32, i32* %7
%21 = sub nsw i32 %20, 1
%22 = icmp sle i32 %19, %21
br i1 %22, label %23, label %36
23: ; preds = %18
%24 = load double, double* %5
%25 = load i32, i32* %11
%26 = sitofp i32 %25 to double
%27 = load double, double* %8
%28 = call double @llvm.fmuladd.f64(double %26, double %27, double %24)
store double %28, double* %10
%29 = load double, double* %9
%30 = load double, double* %10
%31 = call double @f(double %30)
%32 = fadd double %29, %31
store double %32, double* %9
br label %33
33: ; preds = %23
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %18
36: ; preds = %18
%37 = load double, double* %9
%38 = load double, double* %8
%39 = fmul double %37, %38
store double %39, double* %9
%40 = load double, double* %9
ret double %40
}

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
}