#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 fabs(double);
double fu(int, double);
double simpson(int f, double n, double a, double b, double h) {
  double s1 = 0.0;
  double s2 = 0.0;
  int token = 1;
  while (token < n) {
    s1 += fu(f, a + (token * h));
    token++;
  }
  token = 0;
  while (token < n) {
    s2 += fu(f, a + (token * h) + (h / 2.0));
    token++;
  }
  return fabs(
      (((b - a) / (6.0 * n)) * (fu(f, a) + fu(f, b) + (2.0 * s1 + 4.0 * s2))) -
      1.0);
}


x86 assembly (clang, -O0):
<simpson>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x3c(%rbp)
cvtsi2sdl -0x3c(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1191 <simpson+0x81>
mov    -0x4(%rbp),%edi
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x3c(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <fu@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1146 <simpson+0x36>
movl   $0x0,-0x3c(%rbp)
cvtsi2sdl -0x3c(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f8 <simpson+0xe8>
mov    -0x4(%rbp),%edi
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x3c(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe55(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
call   1030 <fu@plt>
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1198 <simpson+0x88>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe16(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1030 <fu@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x20(%rbp),%xmm0
call   1030 <fu@plt>
movsd  -0x50(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
addsd  %xmm2,%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xdc3(%rip),%xmm3
mulsd  -0x38(%rbp),%xmm3
addsd  %xmm2,%xmm2
addsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9e(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps 0xd83(%rip),%xmm1
pand   %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simpson>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  %xmm2,0x20(%rsp)
movapd %xmm1,%xmm2
movapd %xmm0,%xmm4
mov    %edi,%ebx
ucomisd 0xed2(%rip),%xmm0
xorpd  %xmm1,%xmm1
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm3,0x28(%rsp)
jbe    11b1 <simpson+0xa1>
xorpd  %xmm1,%xmm1
movsd  0xeae(%rip),%xmm0
mov    $0x2,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
mov    %ebx,%edi
call   1030 <fu@plt>
movsd  0x28(%rsp),%xmm3
movsd  0x10(%rsp),%xmm4
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
add    $0x1,%ebp
ucomisd %xmm0,%xmm4
ja     1160 <simpson+0x50>
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm4
jbe    123b <simpson+0x12b>
movsd  0xe3f(%rip),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x30(%rsp)
xorpd  %xmm0,%xmm0
mov    $0x1,%ebp
xorpd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
addsd  0x30(%rsp),%xmm0
mov    %ebx,%edi
call   1030 <fu@plt>
movsd  0x28(%rsp),%xmm3
movsd  0x10(%rsp),%xmm4
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rsp)
movsd  0x18(%rsp),%xmm2
movsd  (%rsp),%xmm1
add    $0x1,%ebp
ucomisd %xmm0,%xmm4
ja     11e0 <simpson+0xd0>
mulsd  0xdd5(%rip),%xmm1
movsd  %xmm1,(%rsp)
movsd  0x20(%rsp),%xmm0
subsd  %xmm2,%xmm0
mulsd  0xdc6(%rip),%xmm4
divsd  %xmm4,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %ebx,%edi
movapd %xmm2,%xmm0
call   1030 <fu@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
movsd  0x20(%rsp),%xmm0
call   1030 <fu@plt>
addsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  (%rsp),%xmm1
addsd  %xmm1,%xmm0
mulsd  0x18(%rsp),%xmm0
addsd  0xd7f(%rip),%xmm0
andpd  0xd87(%rip),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @simpson(i32 %0, double %1, double %2, double %3, double %4) {
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i32
store i32 %0, i32* %6
store double %1, double* %7
store double %2, double* %8
store double %3, double* %9
store double %4, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store i32 1, i32* %13
br label %14
14: ; preds = %19, %5
%15 = load i32, i32* %13
%16 = sitofp i32 %15 to double
%17 = load double, double* %7
%18 = fcmp olt double %16, %17
br i1 %18, label %19, label %31
19: ; preds = %14
%20 = load i32, i32* %6
%21 = load double, double* %8
%22 = load i32, i32* %13
%23 = sitofp i32 %22 to double
%24 = load double, double* %10
%25 = call double @llvm.fmuladd.f64(double %23, double %24, double %21)
%26 = call double @fu(i32 %20, double %25)
%27 = load double, double* %11
%28 = fadd double %27, %26
store double %28, double* %11
%29 = load i32, i32* %13
%30 = add nsw i32 %29, 1
store i32 %30, i32* %13
br label %14
31: ; preds = %14
store i32 0, i32* %13
br label %32
32: ; preds = %37, %31
%33 = load i32, i32* %13
%34 = sitofp i32 %33 to double
%35 = load double, double* %7
%36 = fcmp olt double %34, %35
br i1 %36, label %37, label %52
37: ; preds = %32
%38 = load i32, i32* %6
%39 = load double, double* %8
%40 = load i32, i32* %13
%41 = sitofp i32 %40 to double
%42 = load double, double* %10
%43 = call double @llvm.fmuladd.f64(double %41, double %42, double %39)
%44 = load double, double* %10
%45 = fdiv double %44, 2.000000e+00
%46 = fadd double %43, %45
%47 = call double @fu(i32 %38, double %46)
%48 = load double, double* %12
%49 = fadd double %48, %47
store double %49, double* %12
%50 = load i32, i32* %13
%51 = add nsw i32 %50, 1
store i32 %51, i32* %13
br label %32
52: ; preds = %32
%53 = load double, double* %9
%54 = load double, double* %8
%55 = fsub double %53, %54
%56 = load double, double* %7
%57 = fmul double 6.000000e+00, %56
%58 = fdiv double %55, %57
%59 = load i32, i32* %6
%60 = load double, double* %8
%61 = call double @fu(i32 %59, double %60)
%62 = load i32, i32* %6
%63 = load double, double* %9
%64 = call double @fu(i32 %62, double %63)
%65 = fadd double %61, %64
%66 = load double, double* %11
%67 = load double, double* %12
%68 = fmul double 4.000000e+00, %67
%69 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %66, double %68)
%70 = fadd double %65, %69
%71 = call double @llvm.fmuladd.f64(double %58, double %70, double -1.000000e+00)
%72 = call double @llvm.fabs.f64(double %71)
ret double %72
}

LLVM IR (-O2):
define double @simpson(i32 %0, double %1, double %2, double %3, double %4) {
%6 = fcmp ogt double %1, 1.000000e+00
br i1 %6, label %12, label %7
7: ; preds = %12, %5
%8 = phi double [ 0.000000e+00, %5 ], [ %18, %12 ]
%9 = fcmp ogt double %1, 0.000000e+00
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = fmul double %4, 5.000000e-01
br label %22
12: ; preds = %5, %12
%13 = phi double [ %20, %12 ], [ 1.000000e+00, %5 ]
%14 = phi i32 [ %19, %12 ], [ 1, %5 ]
%15 = phi double [ %18, %12 ], [ 0.000000e+00, %5 ]
%16 = tail call double @llvm.fmuladd.f64(double %13, double %4, double %2)
%17 = tail call double @fu(i32 %0, double %16)
%18 = fadd double %15, %17
%19 = add nuw nsw i32 %14, 1
%20 = sitofp i32 %19 to double
%21 = fcmp olt double %20, %1
br i1 %21, label %12, label %7
22: ; preds = %10, %22
%23 = phi double [ 0.000000e+00, %10 ], [ %31, %22 ]
%24 = phi i32 [ 0, %10 ], [ %30, %22 ]
%25 = phi double [ 0.000000e+00, %10 ], [ %29, %22 ]
%26 = tail call double @llvm.fmuladd.f64(double %23, double %4, double %2)
%27 = fadd double %11, %26
%28 = tail call double @fu(i32 %0, double %27)
%29 = fadd double %25, %28
%30 = add nuw nsw i32 %24, 1
%31 = sitofp i32 %30 to double
%32 = fcmp olt double %31, %1
br i1 %32, label %22, label %33
33: ; preds = %22
%34 = fmul double %29, 4.000000e+00
br label %35
35: ; preds = %33, %7
%36 = phi double [ 0.000000e+00, %7 ], [ %34, %33 ]
%37 = fsub double %3, %2
%38 = fmul double %1, 6.000000e+00
%39 = fdiv double %37, %38
%40 = tail call double @fu(i32 %0, double %2)
%41 = tail call double @fu(i32 %0, double %3)
%42 = fadd double %40, %41
%43 = tail call double @llvm.fmuladd.f64(double %8, double 2.000000e+00, double %36)
%44 = fadd double %43, %42
%45 = tail call double @llvm.fmuladd.f64(double %39, double %44, double -1.000000e+00)
%46 = tail call double @llvm.fabs.f64(double %45)
ret double %46
}