#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 gammacdf(double, double);
double log(double);
double lognormalcdf(double x, double a, double b) {
  double z = (log(x) - a) / b;
  if (x == 0)
    return 0;
  if (z >= 0)
    return 0.5 + 0.5 * gammacdf(z * z / 2, 0.5);
  else
    return 0.5 - 0.5 * gammacdf(z * z / 2, 0.5);
}


x86 assembly (clang, -O0):
<lognormalcdf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
subsd  -0x18(%rbp),%xmm0
divsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1175 <lognormalcdf+0x55>
jp     1175 <lognormalcdf+0x55>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1204 <lognormalcdf+0xe4>
movsd  -0x28(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c4 <lognormalcdf+0xa4>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe63(%rip),%xmm1
call   1030 <gammacdf@plt>
movsd  0xe56(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1204 <lognormalcdf+0xe4>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe26(%rip),%xmm1
call   1030 <gammacdf@plt>
movsd  0xe11(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0d(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lognormalcdf>:
sub    $0x18,%rsp
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
call   1040 <log@plt>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm2
ucomisd %xmm1,%xmm2
jne    1154 <lognormalcdf+0x34>
jp     1154 <lognormalcdf+0x34>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
ret
subsd  0x8(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mulsd  %xmm0,%xmm0
movsd  0xe8f(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1030 <gammacdf@plt>
movsd  (%rsp),%xmm1
ucomisd 0xe89(%rip),%xmm1
jae    119e <lognormalcdf+0x7e>
mulsd  0xe77(%rip),%xmm0
addsd  0xe67(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  0xe5a(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @lognormalcdf(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%9 = load double, double* %5
%10 = call double @log(double %9)
%11 = load double, double* %6
%12 = fsub double %10, %11
%13 = load double, double* %7
%14 = fdiv double %12, %13
store double %14, double* %8
%15 = load double, double* %5
%16 = fcmp oeq double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %3
store double 0.000000e+00, double* %4
br label %35
18: ; preds = %3
%19 = load double, double* %8
%20 = fcmp oge double %19, 0.000000e+00
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load double, double* %8
%23 = load double, double* %8
%24 = fmul double %22, %23
%25 = fdiv double %24, 2.000000e+00
%26 = call double @gammacdf(double %25, double 5.000000e-01)
%27 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %26, double 5.000000e-01)
store double %27, double* %4
br label %35
28: ; preds = %18
%29 = load double, double* %8
%30 = load double, double* %8
%31 = fmul double %29, %30
%32 = fdiv double %31, 2.000000e+00
%33 = call double @gammacdf(double %32, double 5.000000e-01)
%34 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %33, double 5.000000e-01)
store double %34, double* %4
br label %35
35: ; preds = %28, %21, %17
%36 = load double, double* %4
ret double %36
}

LLVM IR (-O2):
define double @lognormalcdf(double %0, double %1, double %2) {
%4 = tail call double @log(double %0)
%5 = fsub double %4, %1
%6 = fdiv double %5, %2
%7 = fcmp oeq double %0, 0.000000e+00
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = fcmp ult double %6, 0.000000e+00
%10 = fmul double %6, %6
%11 = fmul double %10, 5.000000e-01
%12 = tail call double @gammacdf(double %11, double 5.000000e-01)
br i1 %9, label %15, label %13
13: ; preds = %8
%14 = tail call double @llvm.fmuladd.f64(double %12, double 5.000000e-01, double 5.000000e-01)
br label %17
15: ; preds = %8
%16 = tail call double @llvm.fmuladd.f64(double %12, double -5.000000e-01, double 5.000000e-01)
br label %17
17: ; preds = %3, %15, %13
%18 = phi double [ %14, %13 ], [ %16, %15 ], [ 0.000000e+00, %3 ]
ret double %18
}