#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 */
scalar_t__ RAND_MAX;
double cos(double);
double log(double);
double rand();
double sqrt(double);
double AWGN_generator() {
  double temp1;
  double temp2;
  double result;
  int p;
  p = 1;
  while (p > 0) {
    temp2 = (rand() / ((double)RAND_MAX));
    if (temp2 == 0) {
      p = 1;
    } else {
      p = -1;
    }
  }
  temp1 = cos((2.0 * (double)3.1415926536) * rand() / ((double)RAND_MAX));
  result = sqrt(-2.0 * log(temp2)) * temp1;
  return result;
}


x86 assembly (clang, -O0):
<AWGN_generator>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11a5 <AWGN_generator+0x65>
mov    $0x0,%al
call   1060 <rand@plt>
mov    0x2e81(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1199 <AWGN_generator+0x59>
jp     1199 <AWGN_generator+0x59>
movl   $0x1,-0x1c(%rbp)
jmp    11a0 <AWGN_generator+0x60>
movl   $0xffffffff,-0x1c(%rbp)
jmp    114f <AWGN_generator+0xf>
mov    $0x0,%al
call   1060 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe51(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e26(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe16(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AWGN_generator>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm0
ucomisd 0xea5(%rip),%xmm0
jne    116f <AWGN_generator+0x2f>
jnp    1150 <AWGN_generator+0x10>
xor    %eax,%eax
movsd  %xmm0,(%rsp)
call   1060 <rand@plt>
mulsd  0xe7d(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1040 <log@plt>
mulsd  0xe5c(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11bc <AWGN_generator+0x7c>
sqrtsd %xmm0,%xmm0
jmp    11c1 <AWGN_generator+0x81>
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define double @AWGN_generator() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store i32 1, i32* %4
br label %5
5: ; preds = %17, %0
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = call double (...) @rand()
%10 = load i64, i64* @RAND_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
store double %12, double* %2
%13 = load double, double* %2
%14 = fcmp oeq double %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %8
store i32 1, i32* %4
br label %17
16: ; preds = %8
store i32 -1, i32* %4
br label %17
17: ; preds = %16, %15
br label %5
18: ; preds = %5
%19 = call double (...) @rand()
%20 = fmul double 0x401921FB544486E0, %19
%21 = load i64, i64* @RAND_MAX
%22 = sitofp i64 %21 to double
%23 = fdiv double %20, %22
%24 = call double @cos(double %23)
store double %24, double* %1
%25 = load double, double* %2
%26 = call double @log(double %25)
%27 = fmul double -2.000000e+00, %26
%28 = call double @sqrt(double %27)
%29 = load double, double* %1
%30 = fmul double %28, %29
store double %30, double* %3
%31 = load double, double* %3
ret double %31
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define double @AWGN_generator() {
br label %1
1: ; preds = %0, %1
%2 = tail call double (...) @rand()
%3 = load i64, i64* @RAND_MAX
%4 = sitofp i64 %3 to double
%5 = fdiv double %2, %4
%6 = fcmp oeq double %5, 0.000000e+00
br i1 %6, label %1, label %7
7: ; preds = %1
%8 = tail call double (...) @rand()
%9 = fmul double %8, 0x401921FB544486E0
%10 = load i64, i64* @RAND_MAX
%11 = sitofp i64 %10 to double
%12 = fdiv double %9, %11
%13 = tail call double @cos(double %12)
%14 = tail call double @log(double %5)
%15 = fmul double %14, -2.000000e+00
%16 = tail call double @sqrt(double %15)
%17 = fmul double %13, %16
ret double %17
}