#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 exp(float const);
float factorial(int);
float pow(float const, int);
int calculate_maxhits(const float coverage) {
  if (coverage > 19) {
    return 2 * coverage + 1;
  }
  float total = 0;
  float probability;
  int maxhits = 0;
  while (total < 0.9999) {
    probability = pow(coverage, maxhits) * exp(-coverage) / factorial(maxhits);
    total += probability;
    maxhits++;
  }
  return maxhits + 1;
}


x86 assembly (clang, -O0):
<calculate_maxhits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  0xeb6(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    1174 <calculate_maxhits+0x44>
movss  -0x8(%rbp),%xmm0
addss  %xmm0,%xmm0
movss  0xea0(%rip),%xmm1
addss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    1217 <calculate_maxhits+0xe7>
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe74(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    120e <calculate_maxhits+0xde>
movss  -0x8(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1050 <pow@plt>
movss  %xmm0,-0x1c(%rbp)
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movss  -0x1c(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <factorial@plt>
movaps %xmm0,%xmm1
movss  -0x18(%rbp),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1183 <calculate_maxhits+0x53>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_maxhits>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movaps %xmm0,0x10(%rsp)
ucomiss 0xebe(%rip),%xmm0
jbe    115e <calculate_maxhits+0x2e>
movaps 0x10(%rsp),%xmm0
addss  %xmm0,%xmm0
addss  0xeaf(%rip),%xmm0
cvttss2si %xmm0,%ebx
jmp    11e4 <calculate_maxhits+0xb4>
movaps 0xeab(%rip),%xmm0
xorps  0x10(%rsp),%xmm0
movaps %xmm0,0x20(%rsp)
xorps  %xmm1,%xmm1
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movss  %xmm1,0xc(%rsp)
lea    -0x1(%rbx),%ebp
movaps 0x10(%rsp),%xmm0
mov    %ebp,%edi
call   1050 <pow@plt>
movss  %xmm0,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
call   1040 <exp@plt>
mulss  0x8(%rsp),%xmm0
movss  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <factorial@plt>
movss  0xc(%rsp),%xmm1
movss  0x8(%rsp),%xmm2
divss  %xmm0,%xmm2
addss  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtss2sd %xmm1,%xmm0
add    $0x1,%ebx
movsd  0xe42(%rip),%xmm2
ucomisd %xmm0,%xmm2
ja     1180 <calculate_maxhits+0x50>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calculate_maxhits(float %0) {
%2 = alloca i32
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i32
store float %0, float* %3
%7 = load float, float* %3
%8 = fcmp ogt float %7, 1.900000e+01
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load float, float* %3
%11 = call float @llvm.fmuladd.f32(float 2.000000e+00, float %10, float 1.000000e+00)
%12 = fptosi float %11 to i32
store i32 %12, i32* %2
br label %37
13: ; preds = %1
store float 0.000000e+00, float* %4
store i32 0, i32* %6
br label %14
14: ; preds = %18, %13
%15 = load float, float* %4
%16 = fpext float %15 to double
%17 = fcmp olt double %16, 9.999000e-01
br i1 %17, label %18, label %34
18: ; preds = %14
%19 = load float, float* %3
%20 = load i32, i32* %6
%21 = call float @pow(float %19, i32 %20)
%22 = load float, float* %3
%23 = fneg float %22
%24 = call float @exp(float %23)
%25 = fmul float %21, %24
%26 = load i32, i32* %6
%27 = call float @factorial(i32 %26)
%28 = fdiv float %25, %27
store float %28, float* %5
%29 = load float, float* %5
%30 = load float, float* %4
%31 = fadd float %30, %29
store float %31, float* %4
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %14
34: ; preds = %14
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %37
37: ; preds = %34, %9
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @calculate_maxhits(float %0) {
%2 = fcmp ogt float %0, 1.900000e+01
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = fneg float %0
br label %8
5: ; preds = %1
%6 = tail call float @llvm.fmuladd.f32(float %0, float 2.000000e+00, float 1.000000e+00)
%7 = fptosi float %6 to i32
br label %22
8: ; preds = %3, %8
%9 = phi i32 [ 0, %3 ], [ %17, %8 ]
%10 = phi float [ 0.000000e+00, %3 ], [ %16, %8 ]
%11 = tail call float @pow(float %0, i32 %9)
%12 = tail call float @exp(float %4)
%13 = fmul float %11, %12
%14 = tail call float @factorial(i32 %9)
%15 = fdiv float %13, %14
%16 = fadd float %10, %15
%17 = add nuw nsw i32 %9, 1
%18 = fpext float %16 to double
%19 = fcmp olt double %18, 9.999000e-01
br i1 %19, label %8, label %20
20: ; preds = %8
%21 = add nuw nsw i32 %9, 2
br label %22
22: ; preds = %20, %5
%23 = phi i32 [ %7, %5 ], [ %21, %20 ]
ret i32 %23
}