#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 */
int /*<<< orphan*/ THArgCheck(int, int, char *);
int /*<<< orphan*/ THRandom_normal(double, double);
double exp(int /*<<< orphan*/);
double log(double);
double sqrt(double);
double THRandom_logNormal(double mean, double stdv) {
  double zm = mean * mean;
  double zs = stdv * stdv;
  THArgCheck(stdv > 0, 2, "standard deviation must be strictly positive");
  return (
      exp(THRandom_normal(log(zm / sqrt(zs + zm)), sqrt(log(zs / zm + 1)))));
}


x86 assembly (clang, -O0):
<THRandom_logNormal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x2,%esi
lea    0xe68(%rip),%rdx
call   1070 <THArgCheck@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  0xe1a(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <log@plt>
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
call   1030 <THRandom_normal@plt>
mov    %eax,%edi
call   1040 <exp@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<THRandom_logNormal>:
sub    $0x18,%rsp
xorpd  %xmm2,%xmm2
xor    %edi,%edi
ucomisd %xmm2,%xmm1
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mulsd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
seta   %dil
lea    0xe94(%rip),%rdx
mov    $0x2,%esi
call   1070 <THArgCheck@plt>
movsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
ucomisd 0xe6f(%rip),%xmm0
jb     11a1 <THRandom_logNormal+0x51>
sqrtsd %xmm0,%xmm0
jmp    11a6 <THRandom_logNormal+0x56>
call   1060 <sqrt@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
divsd  (%rsp),%xmm0
addsd  0xe2f(%rip),%xmm0
call   1050 <log@plt>
ucomisd 0xe2a(%rip),%xmm0
jb     11e9 <THRandom_logNormal+0x99>
xorps  %xmm1,%xmm1
sqrtsd %xmm0,%xmm1
jmp    11f2 <THRandom_logNormal+0xa2>
call   1060 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
call   1030 <THRandom_normal@plt>
mov    %eax,%edi
add    $0x18,%rsp
jmp    1040 <exp@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"standard deviation must be strictly positive\00"
define double @THRandom_logNormal(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
store double %0, double* %3
store double %1, double* %4
%7 = load double, double* %3
%8 = load double, double* %3
%9 = fmul double %7, %8
store double %9, double* %5
%10 = load double, double* %4
%11 = load double, double* %4
%12 = fmul double %10, %11
store double %12, double* %6
%13 = load double, double* %4
%14 = fcmp ogt double %13, 0.000000e+00
%15 = zext i1 %14 to i32
%16 = call i32 @THArgCheck(i32 %15, i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%17 = load double, double* %5
%18 = load double, double* %6
%19 = load double, double* %5
%20 = fadd double %18, %19
%21 = call double @sqrt(double %20)
%22 = fdiv double %17, %21
%23 = call double @log(double %22)
%24 = load double, double* %6
%25 = load double, double* %5
%26 = fdiv double %24, %25
%27 = fadd double %26, 1.000000e+00
%28 = call double @log(double %27)
%29 = call double @sqrt(double %28)
%30 = call i32 @THRandom_normal(double %23, double %29)
%31 = call double @exp(i32 %30)
ret double %31
}

LLVM IR (-O2):
@.str = [45 x i8] c"standard deviation must be strictly positive\00"
define double @THRandom_logNormal(double %0, double %1) {
%3 = fmul double %0, %0
%4 = fmul double %1, %1
%5 = fcmp ogt double %1, 0.000000e+00
%6 = zext i1 %5 to i32
%7 = tail call i32 @THArgCheck(i32 %6, i32 2, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%8 = fadd double %3, %4
%9 = tail call double @sqrt(double %8)
%10 = fdiv double %3, %9
%11 = tail call double @log(double %10)
%12 = fdiv double %4, %3
%13 = fadd double %12, 1.000000e+00
%14 = tail call double @log(double %13)
%15 = tail call double @sqrt(double %14)
%16 = tail call i32 @THRandom_normal(double %11, double %15)
%17 = tail call double @exp(i32 %16)
ret double %17
}