#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 M_PI;
double cos(double);
double drand48();
scalar_t__ isnan(double);
int log(double);
double sin(double);
double sqrt(int);
double dnormal() {
  static int odd = 1;
  static double r, theta;
  if (odd) {
    do {
      r = sqrt(-2. * log(drand48()));
    } while (isnan(r));
    theta = 2. * M_PI * (drand48() - .5);
    odd = 0;
    return r * cos(theta);
  } else {
    odd++;
    return r * sin(theta);
  }
}


x86 assembly (clang, -O0):
<dnormal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2ee1(%rip)
je     123b <dnormal+0xdb>
jmp    117a <dnormal+0x1a>
mov    $0x0,%al
call   1080 <drand48@plt>
call   1060 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe6e(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <sqrt@plt>
movsd  %xmm0,0x2eb9(%rip)
movsd  0x2eb1(%rip),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
jne    117a <dnormal+0x1a>
mov    0x2e23(%rip),%rax
cvtsi2sdl (%rax),%xmm1
movsd  0xe3f(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1080 <drand48@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
movsd  0xe17(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,0x2e67(%rip)
movl   $0x0,0x2e45(%rip)
movsd  0x2e4d(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0x2e48(%rip),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1275 <dnormal+0x115>
mov    0x2e0f(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e06(%rip)
movsd  0x2e0e(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0x2e09(%rip),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dnormal>:
push   %rax
cmpb   $0x0,0x2ef0(%rip)
je     1190 <dnormal+0x30>
movb   $0x0,0x2ee7(%rip)
movsd  0x2ee7(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x2ee2(%rip),%xmm0
call   1030 <sin@plt>
jmp    1204 <dnormal+0xa4>
nopl   (%rax)
xor    %eax,%eax
call   1080 <drand48@plt>
call   1060 <log@plt>
lea    (%rax,%rax,1),%edi
neg    %edi
call   1070 <sqrt@plt>
movsd  %xmm0,0x2eb2(%rip)
call   1040 <isnan@plt>
test   %rax,%rax
jne    1190 <dnormal+0x30>
mov    0x2e29(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sdl (%rax),%xmm0
addsd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <drand48@plt>
addsd  0xe22(%rip),%xmm0
mulsd  (%rsp),%xmm0
movsd  %xmm0,0x2e7d(%rip)
movb   $0x1,0x2e66(%rip)
movsd  0x2e66(%rip),%xmm1
movsd  %xmm1,(%rsp)
call   1050 <cos@plt>
mulsd  (%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@dnormal.odd = internal global i32 1
@dnormal.r = internal global double 0.000000e+00
@dnormal.theta = internal global double 0.000000e+00
@M_PI = global i32 0
define double @dnormal() {
%1 = alloca double
%2 = load i32, i32* @dnormal.odd
%3 = icmp ne i32 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %0
br label %5
5: ; preds = %12, %4
%6 = call double (...) @drand48()
%7 = call i32 @log(double %6)
%8 = sitofp i32 %7 to double
%9 = fmul double -2.000000e+00, %8
%10 = fptosi double %9 to i32
%11 = call double @sqrt(i32 %10)
store double %11, double* @dnormal.r
br label %12
12: ; preds = %5
%13 = load double, double* @dnormal.r
%14 = call i64 @isnan(double %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %5, label %16
16: ; preds = %12
%17 = load i32, i32* @M_PI
%18 = sitofp i32 %17 to double
%19 = fmul double 2.000000e+00, %18
%20 = call double (...) @drand48()
%21 = fsub double %20, 5.000000e-01
%22 = fmul double %19, %21
store double %22, double* @dnormal.theta
store i32 0, i32* @dnormal.odd
%23 = load double, double* @dnormal.r
%24 = load double, double* @dnormal.theta
%25 = call double @cos(double %24)
%26 = fmul double %23, %25
store double %26, double* %1
br label %34
27: ; preds = %0
%28 = load i32, i32* @dnormal.odd
%29 = add nsw i32 %28, 1
store i32 %29, i32* @dnormal.odd
%30 = load double, double* @dnormal.r
%31 = load double, double* @dnormal.theta
%32 = call double @sin(double %31)
%33 = fmul double %30, %32
store double %33, double* %1
br label %34
34: ; preds = %27, %16
%35 = load double, double* %1
ret double %35
}

LLVM IR (-O2):
@dnormal.odd = internal unnamed_addr global i1 false
@dnormal.r = internal unnamed_addr global double 0.000000e+00
@dnormal.theta = internal unnamed_addr global double 0.000000e+00
@M_PI = global i32 0
define double @dnormal() {
%1 = load i1, i1* @dnormal.odd
br i1 %1, label %19, label %2
2: ; preds = %0, %2
%3 = tail call double (...) @drand48()
%4 = tail call i32 @log(double %3)
%5 = mul i32 %4, -2
%6 = tail call double @sqrt(i32 %5)
store double %6, double* @dnormal.r
%7 = tail call i64 @isnan(double %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %2
9: ; preds = %2
%10 = load i32, i32* @M_PI
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 2.000000e+00
%13 = tail call double (...) @drand48()
%14 = fadd double %13, -5.000000e-01
%15 = fmul double %12, %14
store double %15, double* @dnormal.theta
store i1 true, i1* @dnormal.odd
%16 = load double, double* @dnormal.r
%17 = tail call double @cos(double %15)
%18 = fmul double %16, %17
br label %24
19: ; preds = %0
store i1 false, i1* @dnormal.odd
%20 = load double, double* @dnormal.r
%21 = load double, double* @dnormal.theta
%22 = tail call double @sin(double %21)
%23 = fmul double %20, %22
br label %24
24: ; preds = %19, %9
%25 = phi double [ %18, %9 ], [ %23, %19 ]
ret double %25
}