#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);
int /*<<< orphan*/ printf(char *, int);
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]);
  printf("%d\n", 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    118b <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    114d <intCompTrap+0x2d>
mov    -0x24(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
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  0xe38(%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>
mov    $0x1,%esi
cmp    $0x2,%r14d
jl     1199 <intCompTrap+0x79>
mov    %r14d,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x8(%rsp)
movsd  (%r15,%rbx,8),%xmm0
call   1030 <f@plt>
addsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <intCompTrap+0x40>
mov    %r14d,%esi
jmp    119f <intCompTrap+0x7f>
movsd  %xmm0,0x8(%rsp)
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
movslq %r14d,%rax
movsd  (%r15,%rax,8),%xmm0
call   1030 <f@plt>
addsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  0xe33(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
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 i32, i32* %8
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = load double*, double** %4
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = call double @f(double %36)
%38 = load double, double* %7
%39 = fadd double %38, %37
store double %39, double* %7
%40 = load double, double* %7
%41 = load double, double* %5
%42 = fdiv double %41, 2.000000e+00
%43 = fmul double %40, %42
ret double %43
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
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 = phi i32 [ 1, %3 ], [ %2, %9 ]
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = sext i32 %2 to i64
%23 = getelementptr inbounds double, double* %0, i64 %22
%24 = load double, double* %23
%25 = tail call double @f(double %24)
%26 = fadd double %19, %25
%27 = fmul double %1, 5.000000e-01
%28 = fmul double %27, %26
ret double %28
}