#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 */
double choose(double, double);
int floor(double);
int pow(double, double);
double calculate_probability(double value, double left, double right) {
  double total = 0;
  int max = floor((value - left) / right);
  for (int i = 0; i <= max; i++) {
    double neg = (double)1 + (-2 * (i & 1));
    double choose1 = choose(left, i);
    double choose2 = choose(value - (right * i) - 1, left - 1);
    total += neg * choose1 * choose2;
  }
  return (1 / pow(right, left)) * total;
}


x86 assembly (clang, -O0):
<calculate_probability>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1050 <floor@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1232 <calculate_probability+0x102>
mov    -0x28(%rbp),%eax
and    $0x1,%eax
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm1
movsd  0xe6f(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
call   1030 <choose@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe1c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe0b(%rip),%xmm2
subsd  %xmm2,%xmm1
call   1030 <choose@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    116d <calculate_probability+0x3d>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1040 <pow@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
mulsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_probability>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
movsd  %xmm0,0x20(%rsp)
movsd  %xmm1,0x10(%rsp)
subsd  %xmm1,%xmm0
movapd %xmm2,0x40(%rsp)
divsd  %xmm2,%xmm0
call   1050 <floor@plt>
test   %eax,%eax
js     122f <calculate_probability+0xff>
mov    %eax,%ebx
movaps 0xe9a(%rip),%xmm0
xorps  0x40(%rsp),%xmm0
movaps %xmm0,0x50(%rsp)
movsd  0xe98(%rip),%xmm0
movsd  0x10(%rsp),%xmm3
addsd  %xmm3,%xmm0
movsd  %xmm0,0x18(%rsp)
add    $0x1,%ebx
xor    %ebp,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
and    $0x1,%eax
add    %eax,%eax
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  %xmm0,0x38(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
movsd  %xmm1,0x28(%rsp)
movapd %xmm3,%xmm0
call   1030 <choose@plt>
movsd  %xmm0,0x30(%rsp)
movsd  0x28(%rsp),%xmm0
mulsd  0x50(%rsp),%xmm0
addsd  0x20(%rsp),%xmm0
addsd  0xe1f(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
call   1030 <choose@plt>
movsd  0x10(%rsp),%xmm3
movsd  0x30(%rsp),%xmm2
mulsd  0x38(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    11a0 <calculate_probability+0x70>
jmp    123f <calculate_probability+0x10f>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm3
movaps 0x40(%rsp),%xmm0
movapd %xmm3,%xmm1
call   1040 <pow@plt>
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    $0x3,%ecx
cmovb  %eax,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
mulsd  0x8(%rsp),%xmm0
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @calculate_probability(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double %0, double* %4
store double %1, double* %5
store double %2, double* %6
store double 0.000000e+00, double* %7
%13 = load double, double* %4
%14 = load double, double* %5
%15 = fsub double %13, %14
%16 = load double, double* %6
%17 = fdiv double %15, %16
%18 = call i32 @floor(double %17)
store i32 %18, i32* %8
store i32 0, i32* %9
br label %19
19: ; preds = %49, %3
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = icmp sle i32 %20, %21
br i1 %22, label %23, label %52
23: ; preds = %19
%24 = load i32, i32* %9
%25 = and i32 %24, 1
%26 = mul nsw i32 -2, %25
%27 = sitofp i32 %26 to double
%28 = fadd double 1.000000e+00, %27
store double %28, double* %10
%29 = load double, double* %5
%30 = load i32, i32* %9
%31 = sitofp i32 %30 to double
%32 = call double @choose(double %29, double %31)
store double %32, double* %11
%33 = load double, double* %4
%34 = load double, double* %6
%35 = load i32, i32* %9
%36 = sitofp i32 %35 to double
%37 = fneg double %34
%38 = call double @llvm.fmuladd.f64(double %37, double %36, double %33)
%39 = fsub double %38, 1.000000e+00
%40 = load double, double* %5
%41 = fsub double %40, 1.000000e+00
%42 = call double @choose(double %39, double %41)
store double %42, double* %12
%43 = load double, double* %10
%44 = load double, double* %11
%45 = fmul double %43, %44
%46 = load double, double* %12
%47 = load double, double* %7
%48 = call double @llvm.fmuladd.f64(double %45, double %46, double %47)
store double %48, double* %7
br label %49
49: ; preds = %23
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %19
52: ; preds = %19
%53 = load double, double* %6
%54 = load double, double* %5
%55 = call i32 @pow(double %53, double %54)
%56 = sdiv i32 1, %55
%57 = sitofp i32 %56 to double
%58 = load double, double* %7
%59 = fmul double %57, %58
ret double %59
}

LLVM IR (-O2):
define double @calculate_probability(double %0, double %1, double %2) {
%4 = fsub double %0, %1
%5 = fdiv double %4, %2
%6 = tail call i32 @floor(double %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = fneg double %2
%10 = fadd double %1, -1.000000e+00
br label %19
11: ; preds = %19, %3
%12 = phi double [ 0.000000e+00, %3 ], [ %32, %19 ]
%13 = tail call i32 @pow(double %2, double %1)
%14 = add i32 %13, 1
%15 = icmp ult i32 %14, 3
%16 = select i1 %15, i32 %13, i32 0
%17 = sitofp i32 %16 to double
%18 = fmul double %12, %17
ret double %18
19: ; preds = %8, %19
%20 = phi double [ 0.000000e+00, %8 ], [ %32, %19 ]
%21 = phi i32 [ 0, %8 ], [ %33, %19 ]
%22 = and i32 %21, 1
%23 = mul nuw nsw i32 %22, -2
%24 = or i32 %23, 1
%25 = sitofp i32 %24 to double
%26 = sitofp i32 %21 to double
%27 = tail call double @choose(double %1, double %26)
%28 = tail call double @llvm.fmuladd.f64(double %9, double %26, double %0)
%29 = fadd double %28, -1.000000e+00
%30 = tail call double @choose(double %29, double %10)
%31 = fmul double %27, %25
%32 = tail call double @llvm.fmuladd.f64(double %31, double %30, double %20)
%33 = add nuw i32 %21, 1
%34 = icmp eq i32 %21, %6
br i1 %34, label %11, label %19
}