#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 fx(double, double);
double simp(double a, double b, int n, double tm) {
  int i;
  double sum1 = 0.0;
  double sum2 = 0.0;
  double sum3 = 0.0;
  double h, x, val;
  h = (b - a) / (double)n;
  for (i = 1; i <= n - 2; i = (i + 3)) {
    x = a + (double)i * h;
    sum1 += fx(tm, x);
  }
  for (i = 2; i <= n - 1; i = (i + 3)) {
    x = a + (double)i * h;
    sum2 += fx(tm, x);
  }
  for (i = 3; i <= n - 3; i = (i + 3)) {
    x = a + (double)i * h;
    sum3 += fx(tm, x);
  }
  val = (3.0 * h / 8.0) *
        (fx(tm, a) + fx(tm, b) + 3.0 * sum1 + 3.0 * sum2 + 2.0 * sum3);
  return val;
}


x86 assembly (clang, -O0):
<simp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  %xmm2,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     11b5 <simp+0xa5>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1030 <fx@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    1161 <simp+0x51>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1210 <simp+0x100>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1030 <fx@plt>
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    11bc <simp+0xac>
movl   $0x3,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jg     126b <simp+0x15b>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1030 <fx@plt>
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    1217 <simp+0x107>
movsd  0xd8d(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  0xd88(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
call   1030 <fx@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <fx@plt>
movsd  -0x68(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm2
movsd  -0x30(%rbp),%xmm1
movsd  0xd36(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
movsd  -0x38(%rbp),%xmm2
movsd  0xd21(%rip),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  -0x40(%rbp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simp>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
movapd %xmm2,%xmm3
movapd %xmm0,%xmm4
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
divsd  %xmm0,%xmm2
xorpd  %xmm6,%xmm6
xorpd  %xmm0,%xmm0
xorpd  %xmm5,%xmm5
cmp    $0x3,%edi
movsd  %xmm3,0x28(%rsp)
movsd  %xmm1,0x38(%rsp)
jl     128e <simp+0x17e>
mov    %edi,%r14d
lea    -0x2(%r14),%ebp
xorpd  %xmm0,%xmm0
mov    $0x1,%ebx
movsd  %xmm2,0x20(%rsp)
movsd  %xmm4,0x18(%rsp)
movsd  %xmm0,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
movapd %xmm3,%xmm0
call   1030 <fx@plt>
movsd  0x18(%rsp),%xmm4
movsd  0x28(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x3,%ebx
cmp    %ebp,%ebx
jle    1170 <simp+0x60>
xorpd  %xmm6,%xmm6
cmp    $0x3,%r14d
jl     1224 <simp+0x114>
xorpd  %xmm6,%xmm6
mov    $0x2,%ebx
movsd  %xmm6,0x10(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
movapd %xmm3,%xmm0
call   1030 <fx@plt>
movsd  0x10(%rsp),%xmm6
movsd  0x18(%rsp),%xmm4
movsd  0x28(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
addsd  %xmm0,%xmm6
add    $0x3,%ebx
cmp    %r14d,%ebx
jl     11d0 <simp+0xc0>
xorpd  %xmm5,%xmm5
cmp    $0x6,%r14d
jge    122a <simp+0x11a>
movsd  0x8(%rsp),%xmm0
jmp    128e <simp+0x17e>
xorpd  %xmm5,%xmm5
jmp    128e <simp+0x17e>
movsd  %xmm6,0x10(%rsp)
add    $0xfffffffd,%r14d
xorpd  %xmm5,%xmm5
mov    $0x3,%ebx
nopl   (%rax)
movsd  %xmm5,0x30(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm4,%xmm1
movapd %xmm3,%xmm0
call   1030 <fx@plt>
movsd  0x30(%rsp),%xmm5
movsd  0x18(%rsp),%xmm4
movsd  0x28(%rsp),%xmm3
movsd  0x20(%rsp),%xmm2
addsd  %xmm0,%xmm5
add    $0x3,%ebx
cmp    %r14d,%ebx
jle    1240 <simp+0x130>
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm6
movsd  %xmm0,0x8(%rsp)
movsd  %xmm6,0x10(%rsp)
movsd  %xmm5,0x30(%rsp)
mulsd  0xd58(%rip),%xmm2
mulsd  0xd58(%rip),%xmm2
movsd  %xmm2,0x20(%rsp)
movapd %xmm3,%xmm0
movapd %xmm4,%xmm1
call   1030 <fx@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x28(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
call   1030 <fx@plt>
addsd  0x18(%rsp),%xmm0
movsd  0xd18(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm2,%xmm0
movsd  0x30(%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mulsd  0x20(%rsp),%xmm0
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @simp(double %0, double %1, i32 %2, double %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double %3, double* %8
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
%16 = load double, double* %6
%17 = load double, double* %5
%18 = fsub double %16, %17
%19 = load i32, i32* %7
%20 = sitofp i32 %19 to double
%21 = fdiv double %18, %20
store double %21, double* %13
store i32 1, i32* %9
br label %22
22: ; preds = %38, %4
%23 = load i32, i32* %9
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 2
%26 = icmp sle i32 %23, %25
br i1 %26, label %27, label %41
27: ; preds = %22
%28 = load double, double* %5
%29 = load i32, i32* %9
%30 = sitofp i32 %29 to double
%31 = load double, double* %13
%32 = call double @llvm.fmuladd.f64(double %30, double %31, double %28)
store double %32, double* %14
%33 = load double, double* %8
%34 = load double, double* %14
%35 = call double @fx(double %33, double %34)
%36 = load double, double* %10
%37 = fadd double %36, %35
store double %37, double* %10
br label %38
38: ; preds = %27
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 3
store i32 %40, i32* %9
br label %22
41: ; preds = %22
store i32 2, i32* %9
br label %42
42: ; preds = %58, %41
%43 = load i32, i32* %9
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
%46 = icmp sle i32 %43, %45
br i1 %46, label %47, label %61
47: ; preds = %42
%48 = load double, double* %5
%49 = load i32, i32* %9
%50 = sitofp i32 %49 to double
%51 = load double, double* %13
%52 = call double @llvm.fmuladd.f64(double %50, double %51, double %48)
store double %52, double* %14
%53 = load double, double* %8
%54 = load double, double* %14
%55 = call double @fx(double %53, double %54)
%56 = load double, double* %11
%57 = fadd double %56, %55
store double %57, double* %11
br label %58
58: ; preds = %47
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 3
store i32 %60, i32* %9
br label %42
61: ; preds = %42
store i32 3, i32* %9
br label %62
62: ; preds = %78, %61
%63 = load i32, i32* %9
%64 = load i32, i32* %7
%65 = sub nsw i32 %64, 3
%66 = icmp sle i32 %63, %65
br i1 %66, label %67, label %81
67: ; preds = %62
%68 = load double, double* %5
%69 = load i32, i32* %9
%70 = sitofp i32 %69 to double
%71 = load double, double* %13
%72 = call double @llvm.fmuladd.f64(double %70, double %71, double %68)
store double %72, double* %14
%73 = load double, double* %8
%74 = load double, double* %14
%75 = call double @fx(double %73, double %74)
%76 = load double, double* %12
%77 = fadd double %76, %75
store double %77, double* %12
br label %78
78: ; preds = %67
%79 = load i32, i32* %9
%80 = add nsw i32 %79, 3
store i32 %80, i32* %9
br label %62
81: ; preds = %62
%82 = load double, double* %13
%83 = fmul double 3.000000e+00, %82
%84 = fdiv double %83, 8.000000e+00
%85 = load double, double* %8
%86 = load double, double* %5
%87 = call double @fx(double %85, double %86)
%88 = load double, double* %8
%89 = load double, double* %6
%90 = call double @fx(double %88, double %89)
%91 = fadd double %87, %90
%92 = load double, double* %10
%93 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %92, double %91)
%94 = load double, double* %11
%95 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %94, double %93)
%96 = load double, double* %12
%97 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %96, double %95)
%98 = fmul double %84, %97
store double %98, double* %15
%99 = load double, double* %15
ret double %99
}

LLVM IR (-O2):
define double @simp(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 = add nsw i32 %2, -2
%9 = icmp slt i32 %2, 3
br i1 %9, label %42, label %12
10: ; preds = %12
%11 = icmp sgt i32 %2, 2
br i1 %11, label %24, label %42
12: ; preds = %4, %12
%13 = phi i32 [ %19, %12 ], [ 1, %4 ]
%14 = phi double [ %18, %12 ], [ 0.000000e+00, %4 ]
%15 = sitofp i32 %13 to double
%16 = tail call double @llvm.fmuladd.f64(double %15, double %7, double %0)
%17 = tail call double @fx(double %3, double %16)
%18 = fadd double %14, %17
%19 = add nuw nsw i32 %13, 3
%20 = icmp sgt i32 %19, %8
br i1 %20, label %10, label %12
21: ; preds = %24
%22 = add nsw i32 %2, -3
%23 = icmp slt i32 %2, 6
br i1 %23, label %42, label %33
24: ; preds = %10, %24
%25 = phi i32 [ %31, %24 ], [ 2, %10 ]
%26 = phi double [ %30, %24 ], [ 0.000000e+00, %10 ]
%27 = sitofp i32 %25 to double
%28 = tail call double @llvm.fmuladd.f64(double %27, double %7, double %0)
%29 = tail call double @fx(double %3, double %28)
%30 = fadd double %26, %29
%31 = add nuw nsw i32 %25, 3
%32 = icmp slt i32 %31, %2
br i1 %32, label %24, label %21
33: ; preds = %21, %33
%34 = phi i32 [ %40, %33 ], [ 3, %21 ]
%35 = phi double [ %39, %33 ], [ 0.000000e+00, %21 ]
%36 = sitofp i32 %34 to double
%37 = tail call double @llvm.fmuladd.f64(double %36, double %7, double %0)
%38 = tail call double @fx(double %3, double %37)
%39 = fadd double %35, %38
%40 = add nuw nsw i32 %34, 3
%41 = icmp sgt i32 %40, %22
br i1 %41, label %42, label %33
42: ; preds = %33, %4, %10, %21
%43 = phi double [ %30, %21 ], [ 0.000000e+00, %10 ], [ 0.000000e+00, %4 ], [ %30, %33 ]
%44 = phi double [ %18, %21 ], [ %18, %10 ], [ 0.000000e+00, %4 ], [ %18, %33 ]
%45 = phi double [ 0.000000e+00, %21 ], [ 0.000000e+00, %10 ], [ 0.000000e+00, %4 ], [ %39, %33 ]
%46 = fmul double %7, 3.000000e+00
%47 = fmul double %46, 1.250000e-01
%48 = tail call double @fx(double %3, double %0)
%49 = tail call double @fx(double %3, double %1)
%50 = fadd double %48, %49
%51 = tail call double @llvm.fmuladd.f64(double %44, double 3.000000e+00, double %50)
%52 = tail call double @llvm.fmuladd.f64(double %43, double 3.000000e+00, double %51)
%53 = tail call double @llvm.fmuladd.f64(double %45, double 2.000000e+00, double %52)
%54 = fmul double %47, %53
ret double %54
}