#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(float);
float trap(float left, float right, int n, float h) {
  float sum, x;
  int i;
  sum = (f(left) + f(right)) / 2;
  x = left;
  for (i = 1; i < n; i++) {
    x = x + h;
    sum += f(x);
  }
  sum *= h;
  return sum;
}


x86 assembly (clang, -O0):
<trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,-0x20(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <f@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ab <trap+0x9b>
movss  -0x18(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
call   1030 <f@plt>
cvtsi2ss %eax,%xmm0
addss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116a <trap+0x5a>
movss  -0x10(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trap>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm2,0x14(%rsp)
mov    %edi,%ebx
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x10(%rsp)
call   1030 <f@plt>
mov    %eax,%ebp
movss  0xc(%rsp),%xmm0
call   1030 <f@plt>
add    %ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2ss %ecx,%xmm0
cmp    $0x2,%ebx
jl     11a2 <trap+0x92>
add    $0xffffffff,%ebx
movss  0x10(%rsp),%xmm1
nopl   0x0(%rax)
movss  %xmm0,0xc(%rsp)
addss  0x14(%rsp),%xmm1
movss  %xmm1,0x10(%rsp)
movaps %xmm1,%xmm0
call   1030 <f@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0xc(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0xc(%rsp)
movss  0x10(%rsp),%xmm1
movss  0xc(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1160 <trap+0x50>
mulss  0x14(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define float @trap(float %0, float %1, i32 %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca i32
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca i32
store float %0, float* %5
store float %1, float* %6
store i32 %2, i32* %7
store float %3, float* %8
%12 = load float, float* %5
%13 = call i32 @f(float %12)
%14 = load float, float* %6
%15 = call i32 @f(float %14)
%16 = add nsw i32 %13, %15
%17 = sdiv i32 %16, 2
%18 = sitofp i32 %17 to float
store float %18, float* %9
%19 = load float, float* %5
store float %19, float* %10
store i32 1, i32* %11
br label %20
20: ; preds = %33, %4
%21 = load i32, i32* %11
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load float, float* %10
%26 = load float, float* %8
%27 = fadd float %25, %26
store float %27, float* %10
%28 = load float, float* %10
%29 = call i32 @f(float %28)
%30 = sitofp i32 %29 to float
%31 = load float, float* %9
%32 = fadd float %31, %30
store float %32, float* %9
br label %33
33: ; preds = %24
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %20
36: ; preds = %20
%37 = load float, float* %8
%38 = load float, float* %9
%39 = fmul float %38, %37
store float %39, float* %9
%40 = load float, float* %9
ret float %40
}

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