void dstrb_beta_parameter_estimation(const double m, const double v,
                                     double *const a, double *const b,
                                     int *const err) {
  assert(m > 0. && m < 1.);
  assert(v > 0.);
  assert(a);
  assert(b);
  const double r = m * (1.0 - m);
  if (v > r) {
    if (err)
      *err = 1;
    return;
  }
  const double q = (r / v) - 1.0;
  *a = m * q;
  *b = (1.0 - m) * q;
  if (err)
    *err = 0;
  return;
}


x86 assembly (clang, -O0):
<dstrb_beta_parameter_estimation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x39(%rbp)
jbe    1158 <dstrb_beta_parameter_estimation+0x48>
movsd  0xeb3(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
seta   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
movsd  -0x8(%rbp),%xmm0
movsd  0xe5b(%rip),%xmm1
subsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    11dd <dstrb_beta_parameter_estimation+0xcd>
cmpq   $0x0,-0x28(%rbp)
je     11d8 <dstrb_beta_parameter_estimation+0xc8>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    123e <dstrb_beta_parameter_estimation+0x12e>
movsd  -0x30(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  0xdee(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1239 <dstrb_beta_parameter_estimation+0x129>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
jmp    123e <dstrb_beta_parameter_estimation+0x12e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dstrb_beta_parameter_estimation>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
seta   %al
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movsd  %xmm1,0x8(%rsp)
movsd  0xebe(%rip),%xmm1
ucomisd %xmm0,%xmm1
seta   %cl
and    %al,%cl
movzbl %cl,%edi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
movsd  0x8(%rsp),%xmm0
ucomisd 0xea9(%rip),%xmm0
seta   %dil
xor    %eax,%eax
call   1030 <assert@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <assert@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <assert@plt>
movsd  0x8(%rsp),%xmm3
movsd  0xe6c(%rip),%xmm2
movsd  0x10(%rsp),%xmm1
subsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
mulsd  %xmm1,%xmm0
ucomisd %xmm0,%xmm3
jbe    11b8 <dstrb_beta_parameter_estimation+0xa8>
mov    $0x1,%ebp
test   %r14,%r14
jne    11da <dstrb_beta_parameter_estimation+0xca>
jmp    11dd <dstrb_beta_parameter_estimation+0xcd>
divsd  %xmm3,%xmm0
addsd  0xe44(%rip),%xmm0
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
mulsd  %xmm0,%xmm2
movsd  %xmm2,(%r15)
test   %r14,%r14
je     11dd <dstrb_beta_parameter_estimation+0xcd>
mov    %ebp,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dstrb_beta_parameter_estimation(double %0, double %1, double* %2, double* %3, i32* %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32*
%11 = alloca double
%12 = alloca double
store double %0, double* %6
store double %1, double* %7
store double* %2, double** %8
store double* %3, double** %9
store i32* %4, i32** %10
%13 = load double, double* %6
%14 = fcmp ogt double %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load double, double* %6
%17 = fcmp olt double %16, 1.000000e+00
br label %18
18: ; preds = %15, %5
%19 = phi i1 [ false, %5 ], [ %17, %15 ]
%20 = zext i1 %19 to i32
%21 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %20)
%22 = load double, double* %7
%23 = fcmp ogt double %22, 0.000000e+00
%24 = zext i1 %23 to i32
%25 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %24)
%26 = load double*, double** %8
%27 = call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %26)
%28 = load double*, double** %9
%29 = call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %28)
%30 = load double, double* %6
%31 = load double, double* %6
%32 = fsub double 1.000000e+00, %31
%33 = fmul double %30, %32
store double %33, double* %11
%34 = load double, double* %7
%35 = load double, double* %11
%36 = fcmp ogt double %34, %35
br i1 %36, label %37, label %43
37: ; preds = %18
%38 = load i32*, i32** %10
%39 = icmp ne i32* %38, null
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = load i32*, i32** %10
store i32 1, i32* %41
br label %42
42: ; preds = %40, %37
br label %62
43: ; preds = %18
%44 = load double, double* %11
%45 = load double, double* %7
%46 = fdiv double %44, %45
%47 = fsub double %46, 1.000000e+00
store double %47, double* %12
%48 = load double, double* %6
%49 = load double, double* %12
%50 = fmul double %48, %49
%51 = load double*, double** %8
store double %50, double* %51
%52 = load double, double* %6
%53 = fsub double 1.000000e+00, %52
%54 = load double, double* %12
%55 = fmul double %53, %54
%56 = load double*, double** %9
store double %55, double* %56
%57 = load i32*, i32** %10
%58 = icmp ne i32* %57, null
br i1 %58, label %59, label %61
59: ; preds = %43
%60 = load i32*, i32** %10
store i32 0, i32* %60
br label %61
61: ; preds = %59, %43
br label %62
62: ; preds = %61, %42
ret void
}

LLVM IR (-O2):
define void @dstrb_beta_parameter_estimation(double %0, double %1, double* %2, double* %3, i32* writeonly %4) {
%6 = fcmp ogt double %0, 0.000000e+00
%7 = fcmp olt double %0, 1.000000e+00
%8 = and i1 %6, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %9)
%11 = fcmp ogt double %1, 0.000000e+00
%12 = zext i1 %11 to i32
%13 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %12)
%14 = tail call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %2)
%15 = tail call i32 (double*, ...) bitcast (i32 (...)* @assert to i32 (double*, ...)*)(double* %3)
%16 = fsub double 1.000000e+00, %0
%17 = fmul double %16, %0
%18 = fcmp olt double %17, %1
br i1 %18, label %19, label %21
19: ; preds = %5
%20 = icmp eq i32* %4, null
br i1 %20, label %29, label %27
21: ; preds = %5
%22 = fdiv double %17, %1
%23 = fadd double %22, -1.000000e+00
%24 = fmul double %23, %0
store double %24, double* %2
%25 = fmul double %16, %23
store double %25, double* %3
%26 = icmp eq i32* %4, null
br i1 %26, label %29, label %27
27: ; preds = %21, %19
%28 = phi i32 [ 1, %19 ], [ 0, %21 ]
store i32 %28, i32* %4
br label %29
29: ; preds = %27, %21, %19
ret void
}