#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 */
float length(float, float, int);
float stub1(float);
float stub2(float);
float stub3(float);
float trap(float a, float b, int n, float (*f)(float)) {
  float f_xi, width_h, xi;
  int i;
  f_xi = 0;
  xi = a;
  width_h = length(a, b, n);
  for (i = 1; i <= n - 1; i++)
    f_xi += (*f)(xi += width_h);
  return ((width_h / 2) * ((*f)(a) + (*f)(b) + 2 * f_xi));
}


x86 assembly (clang, -O0):
<trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x4(%rbp),%xmm0
movss  -0x8(%rbp),%xmm1
mov    -0xc(%rbp),%edi
call   1030 <length@plt>
movss  %xmm0,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1197 <trap+0x87>
mov    -0x18(%rbp),%rax
movss  -0x20(%rbp),%xmm0
addss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
call   *%rax
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1159 <trap+0x49>
movss  -0x20(%rbp),%xmm0
movss  0xe5c(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movss  -0x4(%rbp),%xmm0
call   *%rax
movss  %xmm0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movss  -0x8(%rbp),%xmm0
call   *%rax
movss  -0x30(%rbp),%xmm2
movaps %xmm0,%xmm1
movss  -0x2c(%rbp),%xmm0
addss  %xmm1,%xmm2
movss  -0x1c(%rbp),%xmm1
addss  %xmm1,%xmm1
addss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trap>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movss  %xmm0,0x10(%rsp)
movss  %xmm1,0x14(%rsp)
call   1030 <length@plt>
xorps  %xmm1,%xmm1
cmp    $0x2,%ebp
jl     1180 <trap+0x70>
add    $0xffffffff,%ebp
xorps  %xmm1,%xmm1
movss  0x10(%rsp),%xmm2
movss  %xmm0,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
movss  %xmm1,0xc(%rsp)
addss  %xmm0,%xmm2
movss  %xmm2,0x8(%rsp)
movaps %xmm2,%xmm0
call   *%rbx
movss  0x8(%rsp),%xmm2
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  0x4(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    1150 <trap+0x40>
movss  %xmm1,0xc(%rsp)
mulss  0xe72(%rip),%xmm0
movss  %xmm0,0x4(%rsp)
movss  0x10(%rsp),%xmm0
call   *%rbx
movss  %xmm0,0x8(%rsp)
movss  0x14(%rsp),%xmm0
call   *%rbx
addss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
addss  %xmm1,%xmm1
addss  %xmm1,%xmm0
mulss  0x4(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define float @trap(float %0, float %1, i32 %2, float (float)* nocapture %3) {
%5 = tail call float @length(float %0, float %1, i32 %2)
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %16
7: ; preds = %4, %7
%8 = phi i32 [ %14, %7 ], [ 1, %4 ]
%9 = phi float [ %11, %7 ], [ %0, %4 ]
%10 = phi float [ %13, %7 ], [ 0.000000e+00, %4 ]
%11 = fadd float %5, %9
%12 = tail call float %3(float %11)
%13 = fadd float %10, %12
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, %2
br i1 %15, label %16, label %7
16: ; preds = %7, %4
%17 = phi float [ 0.000000e+00, %4 ], [ %13, %7 ]
%18 = fmul float %5, 5.000000e-01
%19 = tail call float %3(float %0)
%20 = tail call float %3(float %1)
%21 = fadd float %19, %20
%22 = tail call float @llvm.fmuladd.f32(float %17, float 2.000000e+00, float %21)
%23 = fmul float %18, %22
ret float %23
}