#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__ amsp_integrate_simpsonRule(double const, double const, double const,
                                      double const, double const, double const);
double amsp_integrate_simpson(const double *x, const double *y, int n) {
  double ret = 0.;
  int i;
  for (i = 0; i < n - 1; i += 2) {
    if (i + 2 >= n)
      return ret;
    ret += amsp_integrate_simpsonRule(x[i], y[i], x[i + 1], y[i + 1], x[i + 2],
                                      y[i + 2]);
  }
  return ret;
}


x86 assembly (clang, -O0):
<amsp_integrate_simpson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11e5 <amsp_integrate_simpson+0xd5>
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
cmp    -0x1c(%rbp),%eax
jl     1161 <amsp_integrate_simpson+0x51>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ef <amsp_integrate_simpson+0xdf>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm3
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm4
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm5
call   1030 <amsp_integrate_simpsonRule@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x2c(%rbp)
jmp    1132 <amsp_integrate_simpson+0x22>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amsp_integrate_simpson>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
cmp    $0x2,%edx
jl     119d <amsp_integrate_simpson+0x8d>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    -0x1(%r14),%r12d
xorps  %xmm0,%xmm0
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
lea    0x2(%rax),%rbp
cmp    %r14d,%ebp
jge    119d <amsp_integrate_simpson+0x8d>
movsd  %xmm0,0x8(%rsp)
movsd  (%rbx,%rax,8),%xmm0
movsd  (%r15,%rax,8),%xmm1
movsd  -0x8(%rbx,%rbp,8),%xmm2
movsd  (%rbx,%rbp,8),%xmm4
movsd  -0x8(%r15,%rbp,8),%xmm3
movsd  (%r15,%rbp,8),%xmm5
call   1030 <amsp_integrate_simpsonRule@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mov    %rbp,%rax
cmp    %ebp,%r12d
jg     1140 <amsp_integrate_simpson+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @amsp_integrate_simpson(double* %0, double* %1, i32 %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %8
store i32 0, i32* %9
br label %10
10: ; preds = %61, %3
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %64
15: ; preds = %10
%16 = load i32, i32* %9
%17 = add nsw i32 %16, 2
%18 = load i32, i32* %7
%19 = icmp sge i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load double, double* %8
store double %21, double* %4
br label %66
22: ; preds = %15
%23 = load double*, double** %5
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double*, double** %6
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %5
%34 = load i32, i32* %9
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %33, i64 %36
%38 = load double, double* %37
%39 = load double*, double** %6
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %39, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %5
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 2
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %45, i64 %48
%50 = load double, double* %49
%51 = load double*, double** %6
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %51, i64 %54
%56 = load double, double* %55
%57 = call i64 @amsp_integrate_simpsonRule(double %27, double %32, double %38, double %44, double %50, double %56)
%58 = sitofp i64 %57 to double
%59 = load double, double* %8
%60 = fadd double %59, %58
store double %60, double* %8
br label %61
61: ; preds = %22
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 2
store i32 %63, i32* %9
br label %10
64: ; preds = %10
%65 = load double, double* %8
store double %65, double* %4
br label %66
66: ; preds = %64, %20
%67 = load double, double* %4
ret double %67
}

LLVM IR (-O2):
define double @amsp_integrate_simpson(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = add nsw i32 %2, -1
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %30
6: ; preds = %3, %12
%7 = phi i64 [ %9, %12 ], [ 0, %3 ]
%8 = phi double [ %28, %12 ], [ 0.000000e+00, %3 ]
%9 = add nuw i64 %7, 2
%10 = trunc i64 %9 to i32
%11 = icmp slt i32 %10, %2
br i1 %11, label %12, label %30
12: ; preds = %6
%13 = getelementptr inbounds double, double* %0, i64 %7
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %1, i64 %7
%16 = load double, double* %15
%17 = or i64 %7, 1
%18 = getelementptr inbounds double, double* %0, i64 %17
%19 = load double, double* %18
%20 = getelementptr inbounds double, double* %1, i64 %17
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %0, i64 %9
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %1, i64 %9
%25 = load double, double* %24
%26 = tail call i64 @amsp_integrate_simpsonRule(double %14, double %16, double %19, double %21, double %23, double %25)
%27 = sitofp i64 %26 to double
%28 = fadd double %8, %27
%29 = icmp sgt i32 %4, %10
br i1 %29, label %6, label %30
30: ; preds = %6, %12, %3
%31 = phi double [ 0.000000e+00, %3 ], [ %28, %12 ], [ %8, %6 ]
ret double %31
}