#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*/ assert(int);
double sqrt(double);
double unitrand(double (*)());
double normrand(double randfn(void), double mean, double var) {
  assert(var >= 0);
  if (var == 1)
    return mean + unitrand(randfn);
  return mean + unitrand(randfn) * sqrt(var);
}


x86 assembly (clang, -O0):
<normrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movsd  -0x20(%rbp),%xmm0
movsd  0xe94(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a5 <normrand+0x75>
jp     11a5 <normrand+0x75>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <unitrand@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e1 <normrand+0xb1>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <unitrand@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normrand>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
xorpd  %xmm0,%xmm0
xor    %edi,%edi
ucomisd %xmm0,%xmm1
setae  %dil
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1050 <unitrand@plt>
movsd  (%rsp),%xmm1
movapd %xmm0,%xmm2
ucomisd 0xe91(%rip),%xmm1
jne    117b <normrand+0x4b>
jp     117b <normrand+0x4b>
addsd  0x8(%rsp),%xmm2
jmp    11af <normrand+0x7f>
ucomisd 0xe85(%rip),%xmm1
jb     118e <normrand+0x5e>
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
jmp    11a1 <normrand+0x71>
movapd %xmm1,%xmm0
movsd  %xmm2,(%rsp)
call   1040 <sqrt@plt>
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
movapd %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @normrand(double ()* %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double ()*
%6 = alloca double
%7 = alloca double
store double ()* %0, double ()** %5
store double %1, double* %6
store double %2, double* %7
%8 = load double, double* %7
%9 = fcmp oge double %8, 0.000000e+00
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load double, double* %7
%13 = fcmp oeq double %12, 1.000000e+00
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = load double, double* %6
%16 = load double ()*, double ()** %5
%17 = bitcast double ()* %16 to double (...)*
%18 = call double @unitrand(double (...)* %17)
%19 = fadd double %15, %18
store double %19, double* %4
br label %28
20: ; preds = %3
%21 = load double, double* %6
%22 = load double ()*, double ()** %5
%23 = bitcast double ()* %22 to double (...)*
%24 = call double @unitrand(double (...)* %23)
%25 = load double, double* %7
%26 = call double @sqrt(double %25)
%27 = call double @llvm.fmuladd.f64(double %24, double %26, double %21)
store double %27, double* %4
br label %28
28: ; preds = %20, %14
%29 = load double, double* %4
ret double %29
}

LLVM IR (-O2):
define double @normrand(double ()* %0, double %1, double %2) {
%4 = fcmp oge double %2, 0.000000e+00
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = fcmp oeq double %2, 1.000000e+00
%8 = bitcast double ()* %0 to double (...)*
%9 = tail call double @unitrand(double (...)* %8)
br i1 %7, label %10, label %12
10: ; preds = %3
%11 = fadd double %9, %1
br label %15
12: ; preds = %3
%13 = tail call double @sqrt(double %2)
%14 = tail call double @llvm.fmuladd.f64(double %9, double %13, double %1)
br label %15
15: ; preds = %12, %10
%16 = phi double [ %11, %10 ], [ %14, %12 ]
ret double %16
}