#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 log(double);
int rndu();
double sqrt(int);
double rndnorm(void) {
  double u1, u2, sumsquare = 0;
  for (;;) {
    u1 = 2 * rndu() - 1;
    u2 = 2 * rndu() - 1;
    sumsquare = u1 * u1 + u2 * u2;
    if (sumsquare >= 0 && sumsquare <= 1)
      break;
  }
  return (u1 * sqrt(-2 * log(sumsquare) / sumsquare));
}


x86 assembly (clang, -O0):
<rndnorm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rndu@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <rndu@plt>
shl    $0x1,%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b7 <rndnorm+0x87>
movsd  0xe59(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11b7 <rndnorm+0x87>
jmp    11bc <rndnorm+0x8c>
jmp    1140 <rndnorm+0x10>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
imul   $0xfffffffe,%eax,%eax
cvtsi2sd %eax,%xmm0
divsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndnorm>:
sub    $0x18,%rsp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <rndu@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <rndu@plt>
add    %eax,%eax
add    $0xffffffff,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
ucomisd 0xe82(%rip),%xmm1
jb     1140 <rndnorm+0x10>
movsd  0xe70(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1140 <rndnorm+0x10>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
call   1040 <log@plt>
add    %eax,%eax
neg    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
mulsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @rndnorm() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
store double 0.000000e+00, double* %3
br label %4
4: ; preds = %25, %0
%5 = call i32 (...) @rndu()
%6 = mul nsw i32 2, %5
%7 = sub nsw i32 %6, 1
%8 = sitofp i32 %7 to double
store double %8, double* %1
%9 = call i32 (...) @rndu()
%10 = mul nsw i32 2, %9
%11 = sub nsw i32 %10, 1
%12 = sitofp i32 %11 to double
store double %12, double* %2
%13 = load double, double* %1
%14 = load double, double* %1
%15 = load double, double* %2
%16 = load double, double* %2
%17 = fmul double %15, %16
%18 = call double @llvm.fmuladd.f64(double %13, double %14, double %17)
store double %18, double* %3
%19 = load double, double* %3
%20 = fcmp oge double %19, 0.000000e+00
br i1 %20, label %21, label %25
21: ; preds = %4
%22 = load double, double* %3
%23 = fcmp ole double %22, 1.000000e+00
br i1 %23, label %24, label %25
24: ; preds = %21
br label %26
25: ; preds = %21, %4
br label %4
26: ; preds = %24
%27 = load double, double* %1
%28 = load double, double* %3
%29 = call i32 @log(double %28)
%30 = mul nsw i32 -2, %29
%31 = sitofp i32 %30 to double
%32 = load double, double* %3
%33 = fdiv double %31, %32
%34 = fptosi double %33 to i32
%35 = call double @sqrt(i32 %34)
%36 = fmul double %27, %35
ret double %36
}

LLVM IR (-O2):
define double @rndnorm() {
br label %1
1: ; preds = %1, %0
%2 = tail call i32 (...) @rndu()
%3 = shl nsw i32 %2, 1
%4 = add nsw i32 %3, -1
%5 = sitofp i32 %4 to double
%6 = tail call i32 (...) @rndu()
%7 = shl nsw i32 %6, 1
%8 = add nsw i32 %7, -1
%9 = sitofp i32 %8 to double
%10 = fmul double %9, %9
%11 = tail call double @llvm.fmuladd.f64(double %5, double %5, double %10)
%12 = fcmp oge double %11, 0.000000e+00
%13 = fcmp ole double %11, 1.000000e+00
%14 = and i1 %12, %13
br i1 %14, label %15, label %1
15: ; preds = %1
%16 = tail call i32 @log(double %11)
%17 = mul nsw i32 %16, -2
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, %11
%20 = fptosi double %19 to i32
%21 = tail call double @sqrt(i32 %20)
%22 = fmul double %21, %5
ret double %22
}