#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 comb_trap(double, double, double);
double sim_13(double, int, double *);
double sim_38(double, double, double, double, double);
double sim_int(double a, double b, int n, double *f) {
  double h = (b - a) / n;
  double f0, f1, f01, f11, f2, f3, sum;
  if (n == 1) {
    f0 = f[n - 1];
    f1 = f[n];
    return comb_trap(h, f0, f1);
  } else {
    int m = n;
    double odd, s38;
    odd = n / 2;
    sum = 0;
    if (odd > 0 && n > 1) {
      f01 = f[n - 3];
      f11 = f[n - 2];
      f2 = f[n - 1];
      f3 = f[n];
      s38 = sim_38(h, f01, f11, f2, f3);
      sum = sum + s38;
      m = n - 3;
    }
    if (m > 1) {
      double s13;
      s13 = sim_13(h, m, f);
      sum = sum + s13;
    }
    return sum;
  }
}


x86 assembly (clang, -O0):
<sim_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
mov    %rsi,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11b5 <sim_int+0x85>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
call   1050 <comb_trap@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12c4 <sim_int+0x194>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x78(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1285 <sim_int+0x155>
cmpl   $0x1,-0x1c(%rbp)
jle    1285 <sim_int+0x155>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x3,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm3
movsd  -0x60(%rbp),%xmm4
call   1040 <sim_38@plt>
movsd  %xmm0,-0x80(%rbp)
movsd  -0x68(%rbp),%xmm0
addsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0x1,-0x6c(%rbp)
jle    12ba <sim_int+0x18a>
movsd  -0x30(%rbp),%xmm0
mov    -0x6c(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <sim_13@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x68(%rbp),%xmm0
addsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x68(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sim_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movapd %xmm1,%xmm5
subsd  %xmm0,%xmm5
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm5
cmp    $0x1,%edi
jne    116a <sim_int+0x3a>
movsd  (%r14),%xmm1
movsd  0x8(%r14),%xmm2
movapd %xmm5,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <comb_trap@plt>
xorpd  %xmm1,%xmm1
jle    11d1 <sim_int+0xa1>
mov    %edi,%ebx
movslq %edi,%rax
movsd  -0x18(%r14,%rax,8),%xmm1
lea    -0x2(%rbx),%eax
movsd  (%r14,%rax,8),%xmm2
lea    -0x1(%rbx),%eax
movsd  (%r14,%rax,8),%xmm3
mov    %edi,%eax
movsd  (%r14,%rax,8),%xmm4
movapd %xmm5,%xmm0
movsd  %xmm5,(%rsp)
call   1040 <sim_38@plt>
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
cmp    $0x5,%ebx
jb     11d1 <sim_int+0xa1>
add    $0xfffffffd,%ebx
movsd  (%rsp),%xmm0
mov    %ebx,%edi
mov    %r14,%rsi
movsd  %xmm1,(%rsp)
call   1030 <sim_13@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @sim_int(double %0, double %1, i32 %2, double* %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca double
%20 = alloca double
%21 = alloca double
store double %0, double* %6
store double %1, double* %7
store i32 %2, i32* %8
store double* %3, double** %9
%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* %10
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %46
30: ; preds = %4
%31 = load double*, double** %9
%32 = load i32, i32* %8
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %31, i64 %34
%36 = load double, double* %35
store double %36, double* %11
%37 = load double*, double** %9
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
store double %41, double* %12
%42 = load double, double* %10
%43 = load double, double* %11
%44 = load double, double* %12
%45 = call double @comb_trap(double %42, double %43, double %44)
store double %45, double* %5
br label %104
46: ; preds = %4
%47 = load i32, i32* %8
store i32 %47, i32* %18
%48 = load i32, i32* %8
%49 = sdiv i32 %48, 2
%50 = sitofp i32 %49 to double
store double %50, double* %19
store double 0.000000e+00, double* %17
%51 = load double, double* %19
%52 = fcmp ogt double %51, 0.000000e+00
br i1 %52, label %53, label %91
53: ; preds = %46
%54 = load i32, i32* %8
%55 = icmp sgt i32 %54, 1
br i1 %55, label %56, label %91
56: ; preds = %53
%57 = load double*, double** %9
%58 = load i32, i32* %8
%59 = sub nsw i32 %58, 3
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %57, i64 %60
%62 = load double, double* %61
store double %62, double* %13
%63 = load double*, double** %9
%64 = load i32, i32* %8
%65 = sub nsw i32 %64, 2
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %63, i64 %66
%68 = load double, double* %67
store double %68, double* %14
%69 = load double*, double** %9
%70 = load i32, i32* %8
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %69, i64 %72
%74 = load double, double* %73
store double %74, double* %15
%75 = load double*, double** %9
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
store double %79, double* %16
%80 = load double, double* %10
%81 = load double, double* %13
%82 = load double, double* %14
%83 = load double, double* %15
%84 = load double, double* %16
%85 = call double @sim_38(double %80, double %81, double %82, double %83, double %84)
store double %85, double* %20
%86 = load double, double* %17
%87 = load double, double* %20
%88 = fadd double %86, %87
store double %88, double* %17
%89 = load i32, i32* %8
%90 = sub nsw i32 %89, 3
store i32 %90, i32* %18
br label %91
91: ; preds = %56, %53, %46
%92 = load i32, i32* %18
%93 = icmp sgt i32 %92, 1
br i1 %93, label %94, label %102
94: ; preds = %91
%95 = load double, double* %10
%96 = load i32, i32* %18
%97 = load double*, double** %9
%98 = call double @sim_13(double %95, i32 %96, double* %97)
store double %98, double* %21
%99 = load double, double* %17
%100 = load double, double* %21
%101 = fadd double %99, %100
store double %101, double* %17
br label %102
102: ; preds = %94, %91
%103 = load double, double* %17
store double %103, double* %5
br label %104
104: ; preds = %102, %30
%105 = load double, double* %5
ret double %105
}

LLVM IR (-O2):
define double @sim_int(double %0, double %1, i32 %2, double* %3) {
%5 = fsub double %1, %0
%6 = sitofp i32 %2 to double
%7 = fdiv double %5, %6
%8 = icmp eq i32 %2, 1
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = load double, double* %3
%11 = getelementptr inbounds double, double* %3, i64 1
%12 = load double, double* %11
%13 = tail call double @comb_trap(double %7, double %10, double %12)
br label %38
14: ; preds = %4
%15 = icmp sgt i32 %2, 1
br i1 %15, label %16, label %38
16: ; preds = %14
%17 = add nsw i32 %2, -3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %3, i64 %18
%20 = load double, double* %19
%21 = add nsw i32 %2, -2
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds double, double* %3, i64 %22
%24 = load double, double* %23
%25 = add nsw i32 %2, -1
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds double, double* %3, i64 %26
%28 = load double, double* %27
%29 = zext i32 %2 to i64
%30 = getelementptr inbounds double, double* %3, i64 %29
%31 = load double, double* %30
%32 = tail call double @sim_38(double %7, double %20, double %24, double %28, double %31)
%33 = fadd double %32, 0.000000e+00
%34 = icmp ugt i32 %2, 4
br i1 %34, label %35, label %38
35: ; preds = %16
%36 = tail call double @sim_13(double %7, i32 %17, double* %3)
%37 = fadd double %33, %36
br label %38
38: ; preds = %14, %16, %35, %9
%39 = phi double [ %13, %9 ], [ %37, %35 ], [ %33, %16 ], [ 0.000000e+00, %14 ]
ret double %39
}