#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 cos(int);
double log(int);
double sqrt(double);
int tcdrand();
double tcdrandnd(double avg, double sd) {
  assert(sd >= 0.0);
  return sqrt(-2.0 * log(tcdrand())) * cos(2 * 3.141592653589793 * tcdrand()) *
             sd +
         avg;
}


x86 assembly (clang, -O0):
<tcdrandnd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    $0x0,%al
call   1040 <tcdrand@plt>
mov    %eax,%edi
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe74(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <tcdrand@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe4b(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  -0x10(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcdrandnd>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
xor    %edi,%edi
movsd  %xmm1,0x8(%rsp)
ucomisd %xmm0,%xmm1
setae  %dil
call   1030 <assert@plt>
xor    %eax,%eax
call   1040 <tcdrand@plt>
mov    %eax,%edi
call   1060 <log@plt>
mulsd  0xe77(%rip),%xmm0
ucomisd 0xe7f(%rip),%xmm0
jb     1199 <tcdrandnd+0x49>
sqrtsd %xmm0,%xmm0
jmp    119e <tcdrandnd+0x4e>
call   1070 <sqrt@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <tcdrand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe4f(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @tcdrandnd(double %0, double %1) {
%3 = alloca double
%4 = alloca double
store double %0, double* %3
store double %1, double* %4
%5 = load double, double* %4
%6 = fcmp oge double %5, 0.000000e+00
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = call i32 (...) @tcdrand()
%10 = call double @log(i32 %9)
%11 = fmul double -2.000000e+00, %10
%12 = call double @sqrt(double %11)
%13 = call i32 (...) @tcdrand()
%14 = sitofp i32 %13 to double
%15 = fmul double 0x401921FB54442D18, %14
%16 = fptosi double %15 to i32
%17 = call double @cos(i32 %16)
%18 = fmul double %12, %17
%19 = load double, double* %4
%20 = load double, double* %3
%21 = call double @llvm.fmuladd.f64(double %18, double %19, double %20)
ret double %21
}

LLVM IR (-O2):
define double @tcdrandnd(double %0, double %1) {
%3 = fcmp oge double %1, 0.000000e+00
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 (...) @tcdrand()
%7 = tail call double @log(i32 %6)
%8 = fmul double %7, -2.000000e+00
%9 = tail call double @sqrt(double %8)
%10 = tail call i32 (...) @tcdrand()
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 0x401921FB54442D18
%13 = fptosi double %12 to i32
%14 = tail call double @cos(i32 %13)
%15 = fmul double %9, %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double %1, double %0)
ret double %16
}