#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 */
struct polynomial_function {
  int dummy;
};

/* Variables and functions */
float get_value(struct polynomial_function *, float);
float calculate_integral(struct polynomial_function *f, float a, float b,
                         float h) {
  float result = 0;
  for (float i = a; i < b; i += h) {
    result += get_value(f, i) * h;
  }
  return result;
}


x86 assembly (clang, -O0):
<calculate_integral>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x10(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1189 <calculate_integral+0x79>
mov    -0x8(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
call   1030 <get_value@plt>
movss  -0x14(%rbp),%xmm2
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x14(%rbp),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    113d <calculate_integral+0x2d>
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_integral>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm3,%xmm3
ucomiss %xmm0,%xmm1
jbe    1170 <calculate_integral+0x60>
mov    %rdi,%rbx
xorps  %xmm3,%xmm3
movss  %xmm2,0x8(%rsp)
movss  %xmm1,0x4(%rsp)
nop
movss  %xmm3,0xc(%rsp)
movss  %xmm0,(%rsp)
mov    %rbx,%rdi
movss  (%rsp),%xmm0
call   1030 <get_value@plt>
movss  0xc(%rsp),%xmm3
movss  0x4(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm0,%xmm3
movss  (%rsp),%xmm0
addss  %xmm2,%xmm0
ucomiss %xmm0,%xmm1
ja     1130 <calculate_integral+0x20>
movaps %xmm3,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.polynomial_function = type { i32 }
define float @calculate_integral(%struct.polynomial_function* %0, float %1, float %2, float %3) {
%5 = alloca %struct.polynomial_function*
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
store %struct.polynomial_function* %0, %struct.polynomial_function** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
store float 0.000000e+00, float* %9
%11 = load float, float* %6
store float %11, float* %10
br label %12
12: ; preds = %23, %4
%13 = load float, float* %10
%14 = load float, float* %7
%15 = fcmp olt float %13, %14
br i1 %15, label %16, label %27
16: ; preds = %12
%17 = load %struct.polynomial_function*, %struct.polynomial_function** %5
%18 = load float, float* %10
%19 = call float @get_value(%struct.polynomial_function* %17, float %18)
%20 = load float, float* %8
%21 = load float, float* %9
%22 = call float @llvm.fmuladd.f32(float %19, float %20, float %21)
store float %22, float* %9
br label %23
23: ; preds = %16
%24 = load float, float* %8
%25 = load float, float* %10
%26 = fadd float %25, %24
store float %26, float* %10
br label %12
27: ; preds = %12
%28 = load float, float* %9
ret float %28
}

LLVM IR (-O2):
%struct.polynomial_function = type { i32 }
define float @calculate_integral(%struct.polynomial_function* %0, float %1, float %2, float %3) {
%5 = fcmp olt float %1, %2
br i1 %5, label %8, label %6
6: ; preds = %8, %4
%7 = phi float [ 0.000000e+00, %4 ], [ %12, %8 ]
ret float %7
8: ; preds = %4, %8
%9 = phi float [ %13, %8 ], [ %1, %4 ]
%10 = phi float [ %12, %8 ], [ 0.000000e+00, %4 ]
%11 = tail call float @get_value(%struct.polynomial_function* %0, float %9)
%12 = tail call float @llvm.fmuladd.f32(float %11, float %3, float %10)
%13 = fadd float %9, %3
%14 = fcmp olt float %13, %2
br i1 %14, label %8, label %6
}