#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);
double m_product_cf(float, float);
long double pow(int, float);
int /*<<< orphan*/ printf(char *, double);
float chance_calc_single(float min, float max, float amount,
                         float desired_result) {
  printf("%f\n", desired_result);
  float range = (max - min) + 1;
  float series = ceil((desired_result - amount) / range);
  float i;
  --amount;
  long double chances = 0.0;
  printf("range=%f", range);
  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;
    printf("\nm_product(desired_result)=%E\n",
           m_product_cf(desired_result - (range * i) - 1, amount));
  }
  return chances;
}


x86 assembly (clang, -O0):
<chance_calc_single>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
movss  -0x8(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  0xe79(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
subss  %xmm1,%xmm0
movss  -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
call   1030 <ceil@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0xc(%rbp),%xmm0
movss  0xe46(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0xc(%rbp)
fldz
fstpt  -0x30(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm1
movss  -0x18(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     12ce <chance_calc_single+0x18e>
movss  -0x1c(%rbp),%xmm0
mov    $0xffffffff,%edi
call   1060 <pow@plt>
fstpt  -0x60(%rbp)
movss  -0xc(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm1
call   1050 <m_product_cf@plt>
fldt   -0x60(%rbp)
movsd  %xmm0,-0x40(%rbp)
fldl   -0x40(%rbp)
fmulp  %st,%st(1)
fstpt  -0x54(%rbp)
movss  -0x10(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm2
mulss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  0xdb8(%rip),%xmm1
addss  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
call   1050 <m_product_cf@plt>
fldt   -0x54(%rbp)
movsd  %xmm0,-0x48(%rbp)
fldl   -0x48(%rbp)
fldt   -0x30(%rbp)
fxch   %st(2)
fmulp  %st,%st(1)
faddp  %st,%st(1)
fstpt  -0x30(%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  0xd63(%rip),%xmm1
subss  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
call   1050 <m_product_cf@plt>
lea    0xd63(%rip),%rdi
call   1040 <printf@plt>
movss  0xd41(%rip),%xmm0
addss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    11e9 <chance_calc_single+0xa9>
fldt   -0x30(%rbp)
fstps  -0x34(%rbp)
movss  -0x34(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chance_calc_single>:
push   %rbx
sub    $0x60,%rsp
movss  %xmm3,0x14(%rsp)
movss  %xmm2,0x8(%rsp)
movaps %xmm1,0x20(%rsp)
movss  %xmm0,0xc(%rsp)
xorps  %xmm0,%xmm0
cvtss2sd %xmm3,%xmm0
lea    0xeb6(%rip),%rdi
call   1030 <printf@plt>
movaps 0x20(%rsp),%xmm1
subss  0xc(%rsp),%xmm1
addss  0xe7e(%rip),%xmm1
movaps %xmm1,0x20(%rsp)
movss  0x14(%rsp),%xmm0
subss  0x8(%rsp),%xmm0
divss  %xmm1,%xmm0
call   1050 <ceilf@plt>
movss  %xmm0,0x10(%rsp)
movaps 0x20(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movss  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
jb     12c3 <chance_calc_single+0x183>
movss  0x8(%rsp),%xmm0
addss  0xe2d(%rip),%xmm0
movss  %xmm0,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
xorps  0xe27(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
fldz
fstpt  0x44(%rsp)
lea    0xe2f(%rip),%rbx
xchg   %ax,%ax
movss  %xmm0,0xc(%rsp)
mov    $0xffffffff,%edi
movss  0xc(%rsp),%xmm0
call   1060 <pow@plt>
fstpt  0x38(%rsp)
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1040 <m_product_cf@plt>
movsd  %xmm0,0x58(%rsp)
fldt   0x38(%rsp)
fmull  0x58(%rsp)
fstpt  0x38(%rsp)
movaps 0x20(%rsp),%xmm0
mulss  0xc(%rsp),%xmm0
addss  0x14(%rsp),%xmm0
addss  0xdae(%rip),%xmm0
movss  %xmm0,0x18(%rsp)
movss  0x8(%rsp),%xmm1
call   1040 <m_product_cf@plt>
movsd  %xmm0,0x50(%rsp)
fldt   0x38(%rsp)
fmull  0x50(%rsp)
fldt   0x44(%rsp)
faddp  %st,%st(1)
fstpt  0x44(%rsp)
movss  0x18(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
call   1040 <m_product_cf@plt>
mov    %rbx,%rdi
call   1030 <printf@plt>
movss  0xc(%rsp),%xmm0
movss  0x10(%rsp),%xmm1
addss  0xd54(%rip),%xmm0
ucomiss %xmm0,%xmm1
jae    1200 <chance_calc_single+0xc0>
fldt   0x44(%rsp)
fstps  0x1c(%rsp)
movss  0x1c(%rsp),%xmm0
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%f\0A\00"
@.str.1 = [9 x i8] c"range=%f\00"
@.str.2 = [31 x i8] c"\0Am_product(desired_result)=%E\0A\00"
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 x86_fp80
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%13 = load float, float* %8
%14 = fpext float %13 to double
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %14)
%16 = load float, float* %6
%17 = load float, float* %5
%18 = fsub float %16, %17
%19 = fadd float %18, 1.000000e+00
store float %19, float* %9
%20 = load float, float* %8
%21 = load float, float* %7
%22 = fsub float %20, %21
%23 = load float, float* %9
%24 = fdiv float %22, %23
%25 = call float @ceil(float %24)
store float %25, float* %10
%26 = load float, float* %7
%27 = fadd float %26, -1.000000e+00
store float %27, float* %7
store x86_fp80 0xK00000000000000000000, x86_fp80* %12
%28 = load float, float* %9
%29 = fpext float %28 to double
%30 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %29)
store float 0.000000e+00, float* %11
br label %31
31: ; preds = %63, %4
%32 = load float, float* %11
%33 = load float, float* %10
%34 = fcmp ole float %32, %33
br i1 %34, label %35, label %66
35: ; preds = %31
%36 = load float, float* %11
%37 = call x86_fp80 @pow(i32 -1, float %36)
%38 = load float, float* %7
%39 = load float, float* %11
%40 = call double @m_product_cf(float %38, float %39)
%41 = fpext double %40 to x86_fp80
%42 = fmul x86_fp80 %37, %41
%43 = load float, float* %8
%44 = load float, float* %9
%45 = load float, float* %11
%46 = fneg float %44
%47 = call float @llvm.fmuladd.f32(float %46, float %45, float %43)
%48 = fsub float %47, 1.000000e+00
%49 = load float, float* %7
%50 = call double @m_product_cf(float %48, float %49)
%51 = fpext double %50 to x86_fp80
%52 = load x86_fp80, x86_fp80* %12
%53 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %42, x86_fp80 %51, x86_fp80 %52)
store x86_fp80 %53, x86_fp80* %12
%54 = load float, float* %8
%55 = load float, float* %9
%56 = load float, float* %11
%57 = fneg float %55
%58 = call float @llvm.fmuladd.f32(float %57, float %56, float %54)
%59 = fsub float %58, 1.000000e+00
%60 = load float, float* %7
%61 = call double @m_product_cf(float %59, float %60)
%62 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), double %61)
br label %63
63: ; preds = %35
%64 = load float, float* %11
%65 = fadd float %64, 1.000000e+00
store float %65, float* %11
br label %31
66: ; preds = %31
%67 = load x86_fp80, x86_fp80* %12
%68 = fptrunc x86_fp80 %67 to float
ret float %68
}

LLVM IR (-O2):
@.str = [4 x i8] c"%f\0A\00"
@.str.1 = [9 x i8] c"range=%f\00"
@.str.2 = [31 x i8] c"\0Am_product(desired_result)=%E\0A\00"
define float @chance_calc_single(float %0, float %1, float %2, float %3) {
%5 = fpext float %3 to double
%6 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double %5)
%7 = fsub float %1, %0
%8 = fadd float %7, 1.000000e+00
%9 = fsub float %3, %2
%10 = fdiv float %9, %8
%11 = tail call float @llvm.ceil.f32(float %10)
%12 = fadd float %2, -1.000000e+00
%13 = fpext float %8 to double
%14 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), double %13)
%15 = fcmp ult float %11, 0.000000e+00
br i1 %15, label %36, label %16
16: ; preds = %4
%17 = fneg float %8
br label %18
18: ; preds = %16, %18
%19 = phi x86_fp80 [ 0xK00000000000000000000, %16 ], [ %29, %18 ]
%20 = phi float [ 0.000000e+00, %16 ], [ %32, %18 ]
%21 = tail call x86_fp80 @pow(i32 -1, float %20)
%22 = tail call double @m_product_cf(float %12, float %20)
%23 = fpext double %22 to x86_fp80
%24 = fmul x86_fp80 %21, %23
%25 = tail call float @llvm.fmuladd.f32(float %17, float %20, float %3)
%26 = fadd float %25, -1.000000e+00
%27 = tail call double @m_product_cf(float %26, float %12)
%28 = fpext double %27 to x86_fp80
%29 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %24, x86_fp80 %28, x86_fp80 %19)
%30 = tail call double @m_product_cf(float %26, float %12)
%31 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), double %30)
%32 = fadd float %20, 1.000000e+00
%33 = fcmp ugt float %32, %11
br i1 %33, label %34, label %18
34: ; preds = %18
%35 = fptrunc x86_fp80 %29 to float
br label %36
36: ; preds = %34, %4
%37 = phi float [ 0.000000e+00, %4 ], [ %35, %34 ]
ret float %37
}