#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 ceil(float);
float m_product_cf(float, float);
float pow(int, float);
float chance_calc_single(float min, float max, float amount,
                         float desired_result) {
  float range = (max - min) + 1;
  float series = ceil((desired_result - amount) / range);
  float i;
  --amount;
  float chances = 0.0;
  for (i = 0; i <= series; ++i) {
    chances = pow((-1), i) * m_product_cf(amount, i) *
                  m_product_cf(desired_result - (range * i) - 1, amount) +
              chances;
  }
  return chances;
}


x86 assembly (clang, -O0):
<chance_calc_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
movss  0xea6(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
divss  -0x14(%rbp),%xmm0
call   1030 <ceil@plt>
movss  %xmm0,-0x18(%rbp)
movss  0xe78(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1254 <chance_calc_single+0x124>
movss  -0x1c(%rbp),%xmm0
mov    $0xffffffff,%edi
call   1050 <pow@plt>
movss  %xmm0,-0x28(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1040 <m_product_cf@plt>
movaps %xmm0,%xmm1
movss  -0x28(%rbp),%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  0xdef(%rip),%xmm1
subss  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
call   1040 <m_product_cf@plt>
movaps %xmm0,%xmm2
movss  -0x24(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  0xdbf(%rip),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11a2 <chance_calc_single+0x72>
movss  -0x20(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chance_calc_single>:
sub    $0x38,%rsp
subss  %xmm0,%xmm1
addss  0xec0(%rip),%xmm1
movss  %xmm3,0x1c(%rsp)
movaps %xmm3,%xmm0
movss  %xmm2,0x8(%rsp)
subss  %xmm2,%xmm0
movaps %xmm1,0x20(%rsp)
divss  %xmm1,%xmm0
call   1040 <ceilf@plt>
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jb     1249 <chance_calc_single+0x119>
movss  0x8(%rsp),%xmm0
addss  0xe86(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
xorps  0xe80(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
xorps  %xmm2,%xmm2
movss  %xmm1,0x18(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  %xmm2,0x10(%rsp)
movss  %xmm0,0x14(%rsp)
mov    $0xffffffff,%edi
movaps %xmm2,%xmm0
call   1050 <pow@plt>
movss  %xmm0,0xc(%rsp)
movss  0x8(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
call   1030 <m_product_cf@plt>
mulss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
movaps 0x20(%rsp),%xmm0
mulss  0x10(%rsp),%xmm0
addss  0x1c(%rsp),%xmm0
addss  0xdff(%rip),%xmm0
movss  0x8(%rsp),%xmm1
call   1030 <m_product_cf@plt>
movss  0x18(%rsp),%xmm1
mulss  0xc(%rsp),%xmm0
movss  0x14(%rsp),%xmm2
addss  %xmm0,%xmm2
movss  %xmm2,0x14(%rsp)
movss  0x10(%rsp),%xmm2
movss  0x14(%rsp),%xmm0
addss  0xdc0(%rip),%xmm2
ucomiss %xmm2,%xmm1
jae    11b0 <chance_calc_single+0x80>
add    $0x38,%rsp
ret

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

LLVM IR (-O2):
define float @chance_calc_single(float %0, float %1, float %2, float %3) {
%5 = fsub float %1, %0
%6 = fadd float %5, 1.000000e+00
%7 = fsub float %3, %2
%8 = fdiv float %7, %6
%9 = tail call float @llvm.ceil.f32(float %8)
%10 = fadd float %2, -1.000000e+00
%11 = fcmp ult float %9, 0.000000e+00
br i1 %11, label %26, label %12
12: ; preds = %4
%13 = fneg float %6
br label %14
14: ; preds = %12, %14
%15 = phi float [ 0.000000e+00, %12 ], [ %23, %14 ]
%16 = phi float [ 0.000000e+00, %12 ], [ %24, %14 ]
%17 = tail call float @pow(i32 -1, float %16)
%18 = tail call float @m_product_cf(float %10, float %16)
%19 = fmul float %17, %18
%20 = tail call float @llvm.fmuladd.f32(float %13, float %16, float %3)
%21 = fadd float %20, -1.000000e+00
%22 = tail call float @m_product_cf(float %21, float %10)
%23 = tail call float @llvm.fmuladd.f32(float %19, float %22, float %15)
%24 = fadd float %16, 1.000000e+00
%25 = fcmp ugt float %24, %9
br i1 %25, label %26, label %14
26: ; preds = %14, %4
%27 = phi float [ 0.000000e+00, %4 ], [ %23, %14 ]
ret float %27
}