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


x86 assembly (clang, -O0):
<intCompSimp>:
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    11c5 <intCompSimp+0xb5>
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1186 <intCompSimp+0x76>
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)
jmp    11b2 <intCompSimp+0xa2>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <f@plt>
movsd  -0x20(%rbp),%xmm1
movsd  0xe63(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11b7 <intCompSimp+0xa7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113d <intCompSimp+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  0xe0d(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intCompSimp>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
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     1183 <intCompSimp+0x73>
mov    %r14d,%r13d
mov    $0x1,%ebx
lea    0xeb2(%rip),%r12
xchg   %ax,%ax
xor    %ebp,%ebp
test   $0x1,%bl
sete   %bpl
movsd  (%r15,%rbx,8),%xmm0
call   1030 <f@plt>
mulsd  (%r12,%rbp,8),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <intCompSimp+0x40>
movslq %r14d,%rax
movsd  (%r15,%rax,8),%xmm0
call   1030 <f@plt>
addsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
divsd  0xe6b(%rip),%xmm1
mulsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @intCompSimp(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 = %40, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load i32, i32* %8
%19 = srem i32 %18, 2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = load double*, double** %4
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = call double @f(double %26)
%28 = load double, double* %7
%29 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %27, double %28)
store double %29, double* %7
br label %39
30: ; preds = %17
%31 = load double*, double** %4
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = call double @f(double %35)
%37 = load double, double* %7
%38 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %36, double %37)
store double %38, double* %7
br label %39
39: ; preds = %30, %21
br label %40
40: ; preds = %39
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %13
43: ; preds = %13
%44 = load double*, double** %4
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
%48 = load double, double* %47
%49 = call double @f(double %48)
%50 = load double, double* %7
%51 = fadd double %50, %49
store double %51, double* %7
%52 = load double, double* %7
%53 = load double, double* %5
%54 = fdiv double %53, 3.000000e+00
%55 = fmul double %52, %54
ret double %55
}

LLVM IR (-O2):
define double @intCompSimp(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 %22
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 1, %7 ], [ %20, %9 ]
%11 = phi double [ %5, %7 ], [ %19, %9 ]
%12 = and i64 %10, 1
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds double, double* %0, i64 %10
%15 = load double, double* %14
%16 = tail call double @f(double %15)
%17 = tail call double @llvm.fmuladd.f64(double %16, double 2.000000e+00, double %11)
%18 = tail call double @llvm.fmuladd.f64(double %16, double 4.000000e+00, double %11)
%19 = select i1 %13, double %17, double %18
%20 = add nuw nsw i64 %10, 1
%21 = icmp eq i64 %20, %8
br i1 %21, label %22, label %9
22: ; preds = %9, %3
%23 = phi double [ %5, %3 ], [ %19, %9 ]
%24 = sext i32 %2 to i64
%25 = getelementptr inbounds double, double* %0, i64 %24
%26 = load double, double* %25
%27 = tail call double @f(double %26)
%28 = fadd double %23, %27
%29 = fdiv double %1, 3.000000e+00
%30 = fmul double %29, %28
ret double %30
}