// File: Altius[P]hotspot2/src/hotspot2_part1.cpp
// Function: nextProbBinomial(int const&, long double const&, std::vector<long double, std::allocator<long double>> const&)
long double nextProbBinomial(const int& k, const long double& prevVal, const vector<long double>& params)
{
  if (params.size() < 3)
    {
      cerr << "Error:  nextProbBinomial() received an incorrect parameter vector; expected m, v, n."
           << endl
           << endl;
      exit(1);
    }
  if (0 == k)
    {
      cerr << "Error:  nextProbBinomial() received k = 0, which is invalid (require k > 0)."
           << endl
           << endl;
      exit(1);
    }
  const long double &m(params[0]), &v(params[1]), &nn(params[2]), kk(static_cast<long double>(k));
  if (kk > nn + 0.5) // really "if kk > nn," but we could have "kk == nn" with nn=15.99999 and kk=16.000001, hence the 0.5
    return 0.;
  if (v < 1.0e-8)
    {
      cerr << "Error:  nextProbBinomial() received v = 0, which is invalid (require variance > 0)."
           << endl
           << endl;
      exit(1);
    }
  return prevVal * (m - v) * (nn + 1. - kk) / (v * kk);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xa330
cmpq $0x3, %rax
jae 0x3a4e
movq 0x175d6(%rip), %rdi     # 0x1aff0
leaq 0xf76e(%rip), %rsi      # 0x1318f
callq 0x3240
movq %rax, %rdi
movq 0x17578(%rip), %rsi     # 0x1afa8
callq 0x3280
movq %rax, %rdi
movq 0x17569(%rip), %rsi     # 0x1afa8
callq 0x3280
movl $0x1, %edi
callq 0x3330
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpl (%rcx), %eax
jne 0x3a93
movq 0x17591(%rip), %rdi     # 0x1aff0
leaq 0xf77e(%rip), %rsi      # 0x131e4
callq 0x3240
movq %rax, %rdi
movq 0x17533(%rip), %rsi     # 0x1afa8
callq 0x3280
movq %rax, %rdi
movq 0x17524(%rip), %rsi     # 0x1afa8
callq 0x3280
movl $0x1, %edi
callq 0x3330
movq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa350
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0xa350
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0xa350
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
fildl -0x54(%rbp)
fstpt -0x50(%rbp)
fldt -0x50(%rbp)
movq -0x40(%rbp), %rax
fldt (%rax)
flds 0xf51e(%rip)            # 0x13004
faddp %st, %st(1)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x3afc
jmp 0x3af2
fldz
fstpt -0x10(%rbp)
jmp 0x3b7f
movq -0x38(%rbp), %rax
fldt (%rax)
fldl 0xf508(%rip)            # 0x13010
fucompi %st(1), %st
fstp %st(0)
jbe 0x3b4b
jmp 0x3b10
movq 0x174d9(%rip), %rdi     # 0x1aff0
leaq 0xf713(%rip), %rsi      # 0x13231
callq 0x3240
movq %rax, %rdi
movq 0x1747b(%rip), %rsi     # 0x1afa8
callq 0x3280
movq %rax, %rdi
movq 0x1746c(%rip), %rsi     # 0x1afa8
callq 0x3280
movl $0x1, %edi
callq 0x3330
movq -0x20(%rbp), %rax
fldt (%rax)
movq -0x30(%rbp), %rax
fldt (%rax)
movq -0x38(%rbp), %rax
fldt (%rax)
fsubr %st, %st(1)
fxch %st(2)
fmulp %st, %st(1)
movq -0x40(%rbp), %rax
fldt (%rax)
fld1
faddp %st, %st(1)
fldt -0x50(%rbp)
fsubr %st, %st(1)
fxch %st(2)
fmulp %st, %st(1)
fxch %st(2)
fmulp %st, %st(1)
fdivrp %st, %st(1)
fstpt -0x10(%rbp)
fldt -0x10(%rbp)
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)