#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 trap(int n, double a, double b) {
  int i = 0;
  double h = (b - a) / n;
  double integral = 0;
  integral += f(a) / 2;
  integral += f(b) / 2;
  for (i = 1; i < n; i++) {
    integral += f(a + i * h);
  }
  integral *= h;
  return integral;
}


x86 assembly (clang, -O0):
<trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <f@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <f@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d7 <trap+0xc7>
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <f@plt>
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <trap+0x83>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trap>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
mov    %edi,%ebx
movapd %xmm1,%xmm3
subsd  %xmm0,%xmm3
cvtsi2sd %edi,%xmm2
divsd  %xmm2,%xmm3
movsd  %xmm3,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
call   1030 <f@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
movsd  0x8(%rsp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
add    %ebp,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
cmp    $0x2,%ebx
jl     11d3 <trap+0xc3>
add    $0xffffffff,%ebx
movsd  0xe8b(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
call   1030 <f@plt>
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  0xe32(%rip),%xmm0
add    $0xffffffff,%ebx
jne    1180 <trap+0x70>
movsd  0x10(%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @trap(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %7
%10 = load double, double* %6
%11 = load double, double* %5
%12 = fsub double %10, %11
%13 = load i32, i32* %4
%14 = sitofp i32 %13 to double
%15 = fdiv double %12, %14
store double %15, double* %8
store double 0.000000e+00, double* %9
%16 = load double, double* %5
%17 = call i32 @f(double %16)
%18 = sdiv i32 %17, 2
%19 = sitofp i32 %18 to double
%20 = load double, double* %9
%21 = fadd double %20, %19
store double %21, double* %9
%22 = load double, double* %6
%23 = call i32 @f(double %22)
%24 = sdiv i32 %23, 2
%25 = sitofp i32 %24 to double
%26 = load double, double* %9
%27 = fadd double %26, %25
store double %27, double* %9
store i32 1, i32* %7
br label %28
28: ; preds = %42, %3
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load double, double* %5
%34 = load i32, i32* %7
%35 = sitofp i32 %34 to double
%36 = load double, double* %8
%37 = call double @llvm.fmuladd.f64(double %35, double %36, double %33)
%38 = call i32 @f(double %37)
%39 = sitofp i32 %38 to double
%40 = load double, double* %9
%41 = fadd double %40, %39
store double %41, double* %9
br label %42
42: ; preds = %32
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %28
45: ; preds = %28
%46 = load double, double* %8
%47 = load double, double* %9
%48 = fmul double %47, %46
store double %48, double* %9
%49 = load double, double* %9
ret double %49
}

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