#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 /*<<< orphan*/ ranlxd(double *, int);
double sqrt(int);
void rnormal(double *r, const int n) {
  double u[2], s, l;
  int i;
  for (i = 0; i < n; i += 2) {
    ranlxd(u, 2);
    u[0] = 2. * u[0] - 1.;
    u[1] = 2. * u[1] - 1.;
    s = u[0] * u[0] + u[1] * u[1];
    while (s == 0. || s > 1.) {
      ranlxd(u, 2);
      u[0] = 2. * u[0] - 1.;
      u[1] = 2. * u[1] - 1.;
      s = u[0] * u[0] + u[1] * u[1];
    }
    l = sqrt(-2. * log(s) / s);
    r[i] = u[0] * l;
    r[i + 1] = u[1] * l;
  }
  return;
}


x86 assembly (clang, -O0):
<rnormal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12d4 <rnormal+0x1a4>
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1030 <ranlxd@plt>
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe8f(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe75(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    $0x1,%al
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x35(%rbp)
jne    11d7 <rnormal+0xa7>
jp     11d7 <rnormal+0xa7>
jmp    11ee <rnormal+0xbe>
movsd  -0x28(%rbp),%xmm0
movsd  0xe24(%rip),%xmm1
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    11fe <rnormal+0xce>
jmp    1266 <rnormal+0x136>
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
call   1030 <ranlxd@plt>
movsd  -0x20(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xde3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xdc9(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11b5 <rnormal+0x85>
movsd  -0x28(%rbp),%xmm0
call   1040 <log@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd94(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x28(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x18(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
jmp    1146 <rnormal+0x16>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rnormal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
test   %esi,%esi
jle    11e2 <rnormal+0xb2>
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %rsp,%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <ranlxd@plt>
movapd (%rsp),%xmm0
addpd  %xmm0,%xmm0
addpd  0xe92(%rip),%xmm0
movapd %xmm0,(%rsp)
movapd %xmm0,%xmm1
mulpd  %xmm0,%xmm1
unpckhpd %xmm1,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
ucomisd 0xe91(%rip),%xmm0
jne    1193 <rnormal+0x63>
jnp    1150 <rnormal+0x20>
ucomisd 0xe75(%rip),%xmm0
ja     1150 <rnormal+0x20>
movapd %xmm0,0x10(%rsp)
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe61(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
unpcklpd %xmm0,%xmm0
mulpd  (%rsp),%xmm0
movupd %xmm0,(%r14,%rbp,8)
add    $0x2,%rbp
cmp    %r15d,%ebp
jl     1150 <rnormal+0x20>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @rnormal(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca [2 x double]
%6 = alloca double
%7 = alloca double
%8 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %8
br label %9
9: ; preds = %89, %2
%10 = load i32, i32* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %92
13: ; preds = %9
%14 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%15 = call i32 @ranlxd(double* %14, i32 2)
%16 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%17 = load double, double* %16
%18 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %17, double -1.000000e+00)
%19 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
store double %18, double* %19
%20 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%21 = load double, double* %20
%22 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %21, double -1.000000e+00)
%23 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
store double %22, double* %23
%24 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%25 = load double, double* %24
%26 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%27 = load double, double* %26
%28 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%29 = load double, double* %28
%30 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%31 = load double, double* %30
%32 = fmul double %29, %31
%33 = call double @llvm.fmuladd.f64(double %25, double %27, double %32)
store double %33, double* %6
br label %34
34: ; preds = %42, %13
%35 = load double, double* %6
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load double, double* %6
%39 = fcmp ogt double %38, 1.000000e+00
br label %40
40: ; preds = %37, %34
%41 = phi i1 [ true, %34 ], [ %39, %37 ]
br i1 %41, label %42, label %63
42: ; preds = %40
%43 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%44 = call i32 @ranlxd(double* %43, i32 2)
%45 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%46 = load double, double* %45
%47 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %46, double -1.000000e+00)
%48 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
store double %47, double* %48
%49 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%50 = load double, double* %49
%51 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %50, double -1.000000e+00)
%52 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
store double %51, double* %52
%53 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%54 = load double, double* %53
%55 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%56 = load double, double* %55
%57 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%58 = load double, double* %57
%59 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%60 = load double, double* %59
%61 = fmul double %58, %60
%62 = call double @llvm.fmuladd.f64(double %54, double %56, double %61)
store double %62, double* %6
br label %34
63: ; preds = %40
%64 = load double, double* %6
%65 = call i32 @log(double %64)
%66 = sitofp i32 %65 to double
%67 = fmul double -2.000000e+00, %66
%68 = load double, double* %6
%69 = fdiv double %67, %68
%70 = fptosi double %69 to i32
%71 = call double @sqrt(i32 %70)
store double %71, double* %7
%72 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%73 = load double, double* %72
%74 = load double, double* %7
%75 = fmul double %73, %74
%76 = load double*, double** %3
%77 = load i32, i32* %8
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds double, double* %76, i64 %78
store double %75, double* %79
%80 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 1
%81 = load double, double* %80
%82 = load double, double* %7
%83 = fmul double %81, %82
%84 = load double*, double** %3
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds double, double* %84, i64 %87
store double %83, double* %88
br label %89
89: ; preds = %63
%90 = load i32, i32* %8
%91 = add nsw i32 %90, 2
store i32 %91, i32* %8
br label %9
92: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @rnormal(double* nocapture writeonly %0, i32 %1) {
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %48
6: ; preds = %2
%7 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 0
br label %8
8: ; preds = %6, %31
%9 = phi i64 [ 0, %6 ], [ %45, %31 ]
%10 = call i32 @ranlxd(double* %7, i32 2)
%11 = load <2 x double>, <2 x double>* %3
%12 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %11, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>)
store <2 x double> %12, <2 x double>* %3
%13 = fmul <2 x double> %12, %12
%14 = extractelement <2 x double> %13, i64 1
%15 = extractelement <2 x double> %12, i64 0
%16 = call double @llvm.fmuladd.f64(double %15, double %15, double %14)
%17 = fcmp oeq double %16, 0.000000e+00
%18 = fcmp ogt double %16, 1.000000e+00
%19 = or i1 %17, %18
br i1 %19, label %20, label %31
20: ; preds = %8, %20
%21 = call i32 @ranlxd(double* %7, i32 2)
%22 = load <2 x double>, <2 x double>* %3
%23 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> <double -1.000000e+00, double -1.000000e+00>)
store <2 x double> %23, <2 x double>* %3
%24 = fmul <2 x double> %23, %23
%25 = extractelement <2 x double> %24, i64 1
%26 = extractelement <2 x double> %23, i64 0
%27 = call double @llvm.fmuladd.f64(double %26, double %26, double %25)
%28 = fcmp oeq double %27, 0.000000e+00
%29 = fcmp ogt double %27, 1.000000e+00
%30 = or i1 %28, %29
br i1 %30, label %20, label %31
31: ; preds = %20, %8
%32 = phi double [ %16, %8 ], [ %27, %20 ]
%33 = call i32 @log(double %32)
%34 = sitofp i32 %33 to double
%35 = fmul double %34, -2.000000e+00
%36 = fdiv double %35, %32
%37 = fptosi double %36 to i32
%38 = call double @sqrt(i32 %37)
%39 = getelementptr inbounds double, double* %0, i64 %9
%40 = load <2 x double>, <2 x double>* %3
%41 = insertelement <2 x double> poison, double %38, i64 0
%42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> zeroinitializer
%43 = fmul <2 x double> %42, %40
%44 = bitcast double* %39 to <2 x double>*
store <2 x double> %43, <2 x double>* %44
%45 = add nuw i64 %9, 2
%46 = trunc i64 %45 to i32
%47 = icmp slt i32 %46, %1
br i1 %47, label %8, label %48
48: ; preds = %31, %2
ret void
}