#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 */
int f(double);
double Simp(double a, double b, int n, double h) {
  double area;
  double x;
  int i;
  area = f(a) + f(b);
  for (i = 1; i <= n - 1; i++) {
    x = a + i * h;
    if (i % 2 == 0) {
      area = area + (2 * f(x));
    } else {
      area = area + (4 * f(x));
    }
  }
  area = area * (h / 3);
  return area;
}


x86 assembly (clang, -O0):
<Simp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1203 <Simp+0xf3>
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c7 <Simp+0xb7>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x40(%rbp),%xmm0
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11f0 <Simp+0xe0>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <f@plt>
movsd  -0x48(%rbp),%xmm0
shl    $0x2,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11f5 <Simp+0xe5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1158 <Simp+0x48>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xdeb(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Simp>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  %xmm2,0x10(%rsp)
mov    %edi,%ebx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1030 <f@plt>
mov    %eax,%ebp
movsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
add    %ebp,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
cmp    $0x2,%ebx
jl     11bf <Simp+0xaf>
mov    $0x1,%ebp
movsd  0xea9(%rip),%xmm0
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
call   1030 <f@plt>
mov    %ebp,%ecx
and    $0x1,%cl
add    $0x1,%cl
shl    %cl,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  0xe48(%rip),%xmm0
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1160 <Simp+0x50>
movsd  0x10(%rsp),%xmm0
divsd  0xe3b(%rip),%xmm0
mulsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
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 double
%10 = alloca double
%11 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double %3, double* %8
%12 = load double, double* %5
%13 = call i32 @f(double %12)
%14 = load double, double* %6
%15 = call i32 @f(double %14)
%16 = add nsw i32 %13, %15
%17 = sitofp i32 %16 to double
store double %17, double* %9
store i32 1, i32* %11
br label %18
18: ; preds = %47, %4
%19 = load i32, i32* %11
%20 = load i32, i32* %7
%21 = sub nsw i32 %20, 1
%22 = icmp sle i32 %19, %21
br i1 %22, label %23, label %50
23: ; preds = %18
%24 = load double, double* %5
%25 = load i32, i32* %11
%26 = sitofp i32 %25 to double
%27 = load double, double* %8
%28 = call double @llvm.fmuladd.f64(double %26, double %27, double %24)
store double %28, double* %10
%29 = load i32, i32* %11
%30 = srem i32 %29, 2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %23
%33 = load double, double* %9
%34 = load double, double* %10
%35 = call i32 @f(double %34)
%36 = mul nsw i32 2, %35
%37 = sitofp i32 %36 to double
%38 = fadd double %33, %37
store double %38, double* %9
br label %46
39: ; preds = %23
%40 = load double, double* %9
%41 = load double, double* %10
%42 = call i32 @f(double %41)
%43 = mul nsw i32 4, %42
%44 = sitofp i32 %43 to double
%45 = fadd double %40, %44
store double %45, double* %9
br label %46
46: ; preds = %39, %32
br label %47
47: ; preds = %46
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %18
50: ; preds = %18
%51 = load double, double* %9
%52 = load double, double* %8
%53 = fdiv double %52, 3.000000e+00
%54 = fmul double %51, %53
store double %54, double* %9
%55 = load double, double* %9
ret double %55
}

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