#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 calculate_integral(struct polynomial_function *, float, float, float);
float sum_of_diffs(struct polynomial_function *, float, float, float);
float integrate_function(struct polynomial_function *f, float epsilon, float a,
                         float b) {
  float d = b - a;
  while (sum_of_diffs(f, a, b, d) > epsilon) {
    d = d / 2.0;
  }
  return calculate_integral(f, a, b, d);
}


x86 assembly (clang, -O0):
<integrate_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0x10(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
call   1030 <sum_of_diffs@plt>
ucomiss -0xc(%rbp),%xmm0
jbe    118f <integrate_function+0x6f>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe83(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    114a <integrate_function+0x2a>
mov    -0x8(%rbp),%rdi
movss  -0x10(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
movss  -0x18(%rbp),%xmm2
call   1040 <calculate_integral@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<integrate_function>:
push   %rbx
sub    $0x10,%rsp
movaps %xmm2,%xmm3
movss  %xmm0,0x4(%rsp)
mov    %rdi,%rbx
subss  %xmm1,%xmm2
movss  %xmm1,0x8(%rsp)
movaps %xmm1,%xmm0
movss  %xmm3,0xc(%rsp)
movaps %xmm3,%xmm1
movss  %xmm2,(%rsp)
call   1030 <sum_of_diffs@plt>
movss  0x4(%rsp),%xmm1
ucomiss %xmm1,%xmm0
jbe    11a4 <integrate_function+0x84>
movss  (%rsp),%xmm2
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mulss  0xe88(%rip),%xmm2
movss  %xmm2,(%rsp)
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
movss  (%rsp),%xmm2
call   1030 <sum_of_diffs@plt>
movss  (%rsp),%xmm2
ucomiss 0x4(%rsp),%xmm0
ja     1170 <integrate_function+0x50>
jmp    11a9 <integrate_function+0x89>
movss  (%rsp),%xmm2
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
add    $0x10,%rsp
pop    %rbx
jmp    1040 <calculate_integral@plt>

LLVM IR (-O0):
%struct.polynomial_function = type { i32 }
define float @integrate_function(%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
store %struct.polynomial_function* %0, %struct.polynomial_function** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%10 = load float, float* %8
%11 = load float, float* %7
%12 = fsub float %10, %11
store float %12, float* %9
br label %13
13: ; preds = %21, %4
%14 = load %struct.polynomial_function*, %struct.polynomial_function** %5
%15 = load float, float* %7
%16 = load float, float* %8
%17 = load float, float* %9
%18 = call float @sum_of_diffs(%struct.polynomial_function* %14, float %15, float %16, float %17)
%19 = load float, float* %6
%20 = fcmp ogt float %18, %19
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load float, float* %9
%23 = fpext float %22 to double
%24 = fdiv double %23, 2.000000e+00
%25 = fptrunc double %24 to float
store float %25, float* %9
br label %13
26: ; preds = %13
%27 = load %struct.polynomial_function*, %struct.polynomial_function** %5
%28 = load float, float* %7
%29 = load float, float* %8
%30 = load float, float* %9
%31 = call float @calculate_integral(%struct.polynomial_function* %27, float %28, float %29, float %30)
ret float %31
}

LLVM IR (-O2):
%struct.polynomial_function = type { i32 }
define float @integrate_function(%struct.polynomial_function* %0, float %1, float %2, float %3) {
%5 = fsub float %3, %2
%6 = tail call float @sum_of_diffs(%struct.polynomial_function* %0, float %2, float %3, float %5)
%7 = fcmp ogt float %6, %1
br i1 %7, label %8, label %13
8: ; preds = %4, %8
%9 = phi float [ %10, %8 ], [ %5, %4 ]
%10 = fmul float %9, 5.000000e-01
%11 = tail call float @sum_of_diffs(%struct.polynomial_function* %0, float %2, float %3, float %10)
%12 = fcmp ogt float %11, %1
br i1 %12, label %8, label %13
13: ; preds = %8, %4
%14 = phi float [ %5, %4 ], [ %10, %8 ]
%15 = tail call float @calculate_integral(%struct.polynomial_function* %0, float %2, float %3, float %14)
ret float %15
}