#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 cos(double);
int drnd();
int log(int);
double sin(double);
double sqrt(int);
double norm(void) {
  static int s = 0;
  static double r, th;
  if (s == 0) {
    r = sqrt(-2 * log(drnd()));
    th = 2 * (3.1415926535897932384) * drnd();
    s = 1;
    return r * cos(th);
  }
  s = 0;
  return r * sin(th);
}


x86 assembly (clang, -O0):
<norm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2ef1(%rip)
jne    11df <norm+0x8f>
mov    $0x0,%al
call   1030 <drnd@plt>
mov    %eax,%edi
call   1060 <log@plt>
imul   $0xfffffffe,%eax,%edi
call   1070 <sqrt@plt>
movsd  %xmm0,0x2ed2(%rip)
mov    $0x0,%al
call   1030 <drnd@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe67(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2ebb(%rip)
movl   $0x1,0x2ea1(%rip)
movsd  0x2ea1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0x2e9c(%rip),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1214 <norm+0xc4>
movl   $0x0,0x2e67(%rip)
movsd  0x2e67(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0x2e62(%rip),%xmm0
call   1040 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<norm>:
push   %rax
cmpb   $0x0,0x2ef8(%rip)
je     117d <norm+0x2d>
movb   $0x0,0x2eef(%rip)
movsd  0x2eef(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x2eea(%rip),%xmm0
call   1040 <sin@plt>
jmp    11d4 <norm+0x84>
xor    %eax,%eax
call   1030 <drnd@plt>
mov    %eax,%edi
call   1060 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1070 <sqrt@plt>
movsd  %xmm0,0x2ebb(%rip)
xor    %eax,%eax
call   1030 <drnd@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe4d(%rip),%xmm0
movsd  %xmm0,0x2ea5(%rip)
movb   $0x1,0x2e8e(%rip)
movsd  0x2e8e(%rip),%xmm1
movsd  %xmm1,(%rsp)
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@norm.s = internal global i32 0
@norm.r = internal global double 0.000000e+00
@norm.th = internal global double 0.000000e+00
define double @norm() {
%1 = alloca double
%2 = load i32, i32* @norm.s
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %0
%5 = call i32 (...) @drnd()
%6 = call i32 @log(i32 %5)
%7 = mul nsw i32 -2, %6
%8 = call double @sqrt(i32 %7)
store double %8, double* @norm.r
%9 = call i32 (...) @drnd()
%10 = sitofp i32 %9 to double
%11 = fmul double 0x401921FB54442D18, %10
store double %11, double* @norm.th
store i32 1, i32* @norm.s
%12 = load double, double* @norm.r
%13 = load double, double* @norm.th
%14 = call double @cos(double %13)
%15 = fmul double %12, %14
store double %15, double* %1
br label %21
16: ; preds = %0
store i32 0, i32* @norm.s
%17 = load double, double* @norm.r
%18 = load double, double* @norm.th
%19 = call double @sin(double %18)
%20 = fmul double %17, %19
store double %20, double* %1
br label %21
21: ; preds = %16, %4
%22 = load double, double* %1
ret double %22
}

LLVM IR (-O2):
@norm.s = internal unnamed_addr global i1 false
@norm.r = internal unnamed_addr global double 0.000000e+00
@norm.th = internal unnamed_addr global double 0.000000e+00
define double @norm() {
%1 = load i1, i1* @norm.s
br i1 %1, label %13, label %2
2: ; preds = %0
%3 = tail call i32 (...) @drnd()
%4 = tail call i32 @log(i32 %3)
%5 = mul nsw i32 %4, -2
%6 = tail call double @sqrt(i32 %5)
store double %6, double* @norm.r
%7 = tail call i32 (...) @drnd()
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 0x401921FB54442D18
store double %9, double* @norm.th
store i1 true, i1* @norm.s
%10 = load double, double* @norm.r
%11 = tail call double @cos(double %9)
%12 = fmul double %10, %11
br label %18
13: ; preds = %0
store i1 false, i1* @norm.s
%14 = load double, double* @norm.r
%15 = load double, double* @norm.th
%16 = tail call double @sin(double %15)
%17 = fmul double %14, %16
br label %18
18: ; preds = %13, %2
%19 = phi double [ %12, %2 ], [ %17, %13 ]
ret double %19
}