#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 */
scalar_t__ pow(double, int);
double simpsonsRule(double (*f)(double), double a, double b, int n) {
  int i;
  double sum = 0, h, integral, x;
  sum = (f(a) + f(b)) / 3.0;
  h = (b - a) / (double)n;
  for (i = 1; i < n; i++) {
    x = a + (i * h);
    if (pow(-1.0, i) < 0) {
      sum += f(x) * (4.0 / 3.0);
    } else {
      sum += f(x) * (2.0 / 3.0);
    }
  }
  integral = h * sum;
  return integral;
}


x86 assembly (clang, -O0):
<simpsonsRule>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x48(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x18(%rbp),%xmm0
call   *%rax
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xea0(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    122c <simpsonsRule+0x11c>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%edi
movsd  0xe4d(%rip),%xmm0
call   1030 <pow@plt>
cmp    $0x0,%rax
jge    11f4 <simpsonsRule+0xe4>
mov    -0x8(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  -0x28(%rbp),%xmm1
movsd  0xe36(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1219 <simpsonsRule+0x109>
mov    -0x8(%rbp),%rax
movsd  -0x40(%rbp),%xmm0
call   *%rax
movsd  -0x28(%rbp),%xmm1
movsd  0xe04(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    121e <simpsonsRule+0x10e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1188 <simpsonsRule+0x78>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpsonsRule>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %esi,%r14d
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%r15
call   *%rdi
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   *%r15
movsd  0x18(%rsp),%xmm1
movapd %xmm0,%xmm2
addsd  0x10(%rsp),%xmm2
divsd  0xea9(%rip),%xmm2
movsd  0x8(%rsp),%xmm3
subsd  %xmm1,%xmm3
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
cmp    $0x2,%r14d
jl     120b <simpsonsRule+0xfb>
mov    $0x1,%ebp
movsd  0xe80(%rip),%xmm3
lea    0xe89(%rip),%r12
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm3,0x28(%rsp)
movsd  %xmm2,0x10(%rsp)
mulsd  %xmm0,%xmm3
addsd  %xmm1,%xmm3
movsd  %xmm3,0x20(%rsp)
movsd  0xe4e(%rip),%xmm0
mov    %ebp,%edi
call   1030 <pow@plt>
mov    %rax,%rbx
movsd  0x20(%rsp),%xmm0
call   *%r15
movsd  0x28(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
shr    $0x3f,%rbx
mulsd  (%r12,%rbx,8),%xmm0
addsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
addsd  0xe05(%rip),%xmm3
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    11a0 <simpsonsRule+0x90>
mulsd  %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @simpsonsRule(double (double)* %0, double %1, double %2, i32 %3) {
%5 = alloca double (double)*
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store double (double)* %0, double (double)** %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
store double 0.000000e+00, double* %10
%14 = load double (double)*, double (double)** %5
%15 = load double, double* %6
%16 = call double %14(double %15)
%17 = load double (double)*, double (double)** %5
%18 = load double, double* %7
%19 = call double %17(double %18)
%20 = fadd double %16, %19
%21 = fdiv double %20, 3.000000e+00
store double %21, double* %10
%22 = load double, double* %7
%23 = load double, double* %6
%24 = fsub double %22, %23
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to double
%27 = fdiv double %24, %26
store double %27, double* %11
store i32 1, i32* %9
br label %28
28: ; preds = %54, %4
%29 = load i32, i32* %9
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %57
32: ; preds = %28
%33 = load double, double* %6
%34 = load i32, i32* %9
%35 = sitofp i32 %34 to double
%36 = load double, double* %11
%37 = call double @llvm.fmuladd.f64(double %35, double %36, double %33)
store double %37, double* %13
%38 = load i32, i32* %9
%39 = call i64 @pow(double -1.000000e+00, i32 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %32
%42 = load double (double)*, double (double)** %5
%43 = load double, double* %13
%44 = call double %42(double %43)
%45 = load double, double* %10
%46 = call double @llvm.fmuladd.f64(double %44, double 0x3FF5555555555555, double %45)
store double %46, double* %10
br label %53
47: ; preds = %32
%48 = load double (double)*, double (double)** %5
%49 = load double, double* %13
%50 = call double %48(double %49)
%51 = load double, double* %10
%52 = call double @llvm.fmuladd.f64(double %50, double 0x3FE5555555555555, double %51)
store double %52, double* %10
br label %53
53: ; preds = %47, %41
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %28
57: ; preds = %28
%58 = load double, double* %11
%59 = load double, double* %10
%60 = fmul double %58, %59
store double %60, double* %12
%61 = load double, double* %12
ret double %61
}

LLVM IR (-O2):
define double @simpsonsRule(double (double)* nocapture %0, double %1, double %2, i32 %3) {
%5 = tail call double %0(double %1)
%6 = tail call double %0(double %2)
%7 = fadd double %5, %6
%8 = fdiv double %7, 3.000000e+00
%9 = fsub double %2, %1
%10 = sitofp i32 %3 to double
%11 = fdiv double %9, %10
%12 = icmp sgt i32 %3, 1
br i1 %12, label %13, label %26
13: ; preds = %4, %13
%14 = phi i32 [ %24, %13 ], [ 1, %4 ]
%15 = phi double [ %23, %13 ], [ %8, %4 ]
%16 = sitofp i32 %14 to double
%17 = tail call double @llvm.fmuladd.f64(double %16, double %11, double %1)
%18 = tail call i64 @pow(double -1.000000e+00, i32 %14)
%19 = icmp slt i64 %18, 0
%20 = tail call double %0(double %17)
%21 = tail call double @llvm.fmuladd.f64(double %20, double 0x3FF5555555555555, double %15)
%22 = tail call double @llvm.fmuladd.f64(double %20, double 0x3FE5555555555555, double %15)
%23 = select i1 %19, double %21, double %22
%24 = add nuw nsw i32 %14, 1
%25 = icmp eq i32 %24, %3
br i1 %25, label %26, label %13
26: ; preds = %13, %4
%27 = phi double [ %8, %4 ], [ %23, %13 ]
%28 = fmul double %11, %27
ret double %28
}