#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 intCompTrap(double *X, double h, int n) {
  double integral = f(X[0]);
  int i;
  for (i = 1; i < n; i++)
    integral += 2 * f(X[i]);
  integral += f(X[n]);
  return (integral * (h / 2));
}


x86 assembly (clang, -O0):
<intCompTrap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
call   1030 <f@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117b <intCompTrap+0x6b>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <f@plt>
movsd  -0x20(%rbp),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113d <intCompTrap+0x2d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <f@plt>
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe57(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intCompTrap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
movsd  %xmm0,0x10(%rsp)
mov    %rdi,%r15
movsd  (%rdi),%xmm0
call   1030 <f@plt>
cmp    $0x2,%r14d
movsd  %xmm0,0x8(%rsp)
jl     1178 <intCompTrap+0x68>
mov    %r14d,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  (%r15,%rbx,8),%xmm0
call   1030 <f@plt>
addsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <intCompTrap+0x40>
movslq %r14d,%rax
movsd  (%r15,%rax,8),%xmm0
call   1030 <f@plt>
addsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0xe66(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define double @intCompTrap(double* nocapture %0, double %1, i32 %2) {
%4 = load double, double* %0
%5 = tail call double @f(double %4)
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 1, %7 ], [ %16, %9 ]
%11 = phi double [ %5, %7 ], [ %15, %9 ]
%12 = getelementptr inbounds double, double* %0, i64 %10
%13 = load double, double* %12
%14 = tail call double @f(double %13)
%15 = tail call double @llvm.fmuladd.f64(double %14, double 2.000000e+00, double %11)
%16 = add nuw nsw i64 %10, 1
%17 = icmp eq i64 %16, %8
br i1 %17, label %18, label %9
18: ; preds = %9, %3
%19 = phi double [ %5, %3 ], [ %15, %9 ]
%20 = sext i32 %2 to i64
%21 = getelementptr inbounds double, double* %0, i64 %20
%22 = load double, double* %21
%23 = tail call double @f(double %22)
%24 = fadd double %19, %23
%25 = fmul double %1, 5.000000e-01
%26 = fmul double %25, %24
ret double %26
}