#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 trapezes(int f, double n, double a, double b, double h) {
  double s = 0.0;
  int token = 1.0;
  while (token < n) {
    s += fu(f, (a + (token * h)));
    token++;
  }
  return fabs((((b - a) / (2.0 * n)) * (fu(f, a) + fu(f, b) + (2.0 * s))) -
              1.0);
}


x86 assembly (clang, -O0):
<trapezes>:
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)
movl   $0x1,-0x34(%rbp)
cvtsi2sdl -0x34(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1189 <trapezes+0x79>
mov    -0x4(%rbp),%edi
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x34(%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    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113e <trapezes+0x2e>
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe7d(%rip),%xmm1
mulsd  -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
call   1030 <fu@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x4(%rbp),%edi
movsd  -0x20(%rbp),%xmm0
call   1030 <fu@plt>
movsd  -0x48(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
addsd  %xmm1,%xmm2
movsd  -0x30(%rbp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe1e(%rip),%xmm1
addsd  %xmm1,%xmm0
movaps 0xe03(%rip),%xmm1
pand   %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trapezes>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
movsd  %xmm2,0x18(%rsp)
movapd %xmm1,%xmm2
movapd %xmm0,%xmm4
mov    %edi,%ebx
xorpd  %xmm1,%xmm1
ucomisd 0xece(%rip),%xmm0
jbe    11ad <trapezes+0x9d>
xorpd  %xmm1,%xmm1
movsd  0xec0(%rip),%xmm0
mov    $0x2,%ebp
movsd  %xmm2,0x10(%rsp)
movsd  %xmm4,0x8(%rsp)
movsd  %xmm3,0x20(%rsp)
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
mov    %ebx,%edi
call   1030 <fu@plt>
movsd  0x20(%rsp),%xmm3
movsd  0x8(%rsp),%xmm4
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rsp)
movsd  0x10(%rsp),%xmm2
movsd  (%rsp),%xmm1
add    $0x1,%ebp
ucomisd %xmm0,%xmm4
ja     1160 <trapezes+0x50>
movsd  %xmm1,(%rsp)
movsd  0x18(%rsp),%xmm0
subsd  %xmm2,%xmm0
addsd  %xmm4,%xmm4
divsd  %xmm4,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebx,%edi
movapd %xmm2,%xmm0
call   1030 <fu@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
movsd  0x18(%rsp),%xmm0
call   1030 <fu@plt>
addsd  0x10(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0xdff(%rip),%xmm0
andpd  0xdff(%rip),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @trapezes(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 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 i32 1, i32* %12
br label %13
13: ; preds = %18, %5
%14 = load i32, i32* %12
%15 = sitofp i32 %14 to double
%16 = load double, double* %7
%17 = fcmp olt double %15, %16
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = load i32, i32* %6
%20 = load double, double* %8
%21 = load i32, i32* %12
%22 = sitofp i32 %21 to double
%23 = load double, double* %10
%24 = call double @llvm.fmuladd.f64(double %22, double %23, double %20)
%25 = call double @fu(i32 %19, double %24)
%26 = load double, double* %11
%27 = fadd double %26, %25
store double %27, double* %11
%28 = load i32, i32* %12
%29 = add nsw i32 %28, 1
store i32 %29, i32* %12
br label %13
30: ; preds = %13
%31 = load double, double* %9
%32 = load double, double* %8
%33 = fsub double %31, %32
%34 = load double, double* %7
%35 = fmul double 2.000000e+00, %34
%36 = fdiv double %33, %35
%37 = load i32, i32* %6
%38 = load double, double* %8
%39 = call double @fu(i32 %37, double %38)
%40 = load i32, i32* %6
%41 = load double, double* %9
%42 = call double @fu(i32 %40, double %41)
%43 = fadd double %39, %42
%44 = load double, double* %11
%45 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %44, double %43)
%46 = call double @llvm.fmuladd.f64(double %36, double %45, double -1.000000e+00)
%47 = call double @llvm.fabs.f64(double %46)
ret double %47
}

LLVM IR (-O2):
define double @trapezes(i32 %0, double %1, double %2, double %3, double %4) {
%6 = fcmp ogt double %1, 1.000000e+00
br i1 %6, label %7, label %17
7: ; preds = %5, %7
%8 = phi double [ %15, %7 ], [ 1.000000e+00, %5 ]
%9 = phi i32 [ %14, %7 ], [ 1, %5 ]
%10 = phi double [ %13, %7 ], [ 0.000000e+00, %5 ]
%11 = tail call double @llvm.fmuladd.f64(double %8, double %4, double %2)
%12 = tail call double @fu(i32 %0, double %11)
%13 = fadd double %10, %12
%14 = add nuw nsw i32 %9, 1
%15 = sitofp i32 %14 to double
%16 = fcmp olt double %15, %1
br i1 %16, label %7, label %17
17: ; preds = %7, %5
%18 = phi double [ 0.000000e+00, %5 ], [ %13, %7 ]
%19 = fsub double %3, %2
%20 = fmul double %1, 2.000000e+00
%21 = fdiv double %19, %20
%22 = tail call double @fu(i32 %0, double %2)
%23 = tail call double @fu(i32 %0, double %3)
%24 = fadd double %22, %23
%25 = tail call double @llvm.fmuladd.f64(double %18, double 2.000000e+00, double %24)
%26 = tail call double @llvm.fmuladd.f64(double %21, double %25, double -1.000000e+00)
%27 = tail call double @llvm.fabs.f64(double %26)
ret double %27
}