#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 log(float);
double ran1();
float sqrt(double);
void _gaussdev(float *xmv, long n) {
  static int iset = 0;
  static float gset;
  float fac, rsq, v1, v2;
  long i;
  for (i = 0; i < n; i++) {
    if (iset == 0) {
      do {
        v1 = 2.0 * ran1() - 1.0;
        v2 = 2.0 * ran1() - 1.0;
        rsq = v1 * v1 + v2 * v2;
      } while (rsq >= 1.0 || rsq == 0.0);
      fac = sqrt(-2.0 * log(rsq) / rsq);
      gset = v1 * fac;
      iset = 1;
      xmv[i] = v2 * fac;
    } else {
      iset = 0;
      xmv[i] = gset;
    }
  }
}


x86 assembly (clang, -O0):
<_gaussdev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    12ac <_gaussdev+0x17c>
cmpl   $0x0,0x2edf(%rip)
jne    1277 <_gaussdev+0x147>
jmp    1168 <_gaussdev+0x38>
mov    $0x0,%al
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe85(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe65(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x1c(%rbp),%xmm2
movss  -0x20(%rbp),%xmm1
mulss  -0x20(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mov    $0x1,%al
movsd  0xe2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x29(%rbp)
jae    1204 <_gaussdev+0xd4>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1168 <_gaussdev+0x38>
movss  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movaps %xmm0,%xmm1
movsd  0xdec(%rip),%xmm0
mulsd  %xmm1,%xmm0
movss  -0x18(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
movss  %xmm0,0x2def(%rip)
movl   $0x1,0x2de1(%rip)
movss  -0x20(%rbp),%xmm0
mulss  -0x14(%rbp),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    1296 <_gaussdev+0x166>
movl   $0x0,0x2dbb(%rip)
movss  0x2db7(%rip),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
jmp    129b <_gaussdev+0x16b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1148 <_gaussdev+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_gaussdev>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %rsi,%rsi
jle    1247 <_gaussdev+0x117>
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2eec(%rip),%bpl
xor    %ebx,%ebx
jmp    1186 <_gaussdev+0x56>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x0,0x2ed5(%rip)
movss  0x2ed1(%rip),%xmm2
movss  %xmm2,(%r14,%rbx,4)
xor    $0x1,%bpl
add    $0x1,%rbx
cmp    %r15,%rbx
je     1247 <_gaussdev+0x117>
test   $0x1,%bpl
jne    1160 <_gaussdev+0x30>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
movsd  0xe5d(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <ran1@plt>
addsd  %xmm0,%xmm0
addsd  0xe3c(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsd2ss %xmm0,%xmm2
movaps %xmm2,%xmm1
mulss  %xmm2,%xmm1
movss  0x8(%rsp),%xmm0
mulss  %xmm0,%xmm0
addss  %xmm1,%xmm0
ucomiss 0xe29(%rip),%xmm0
jae    1190 <_gaussdev+0x60>
ucomiss 0xe24(%rip),%xmm0
jne    11f4 <_gaussdev+0xc4>
jnp    1190 <_gaussdev+0x60>
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
call   1040 <log@plt>
mulsd  0xdf4(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <sqrt@plt>
movss  0xc(%rsp),%xmm2
movss  0x8(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x2e09(%rip)
movb   $0x1,0x2dfe(%rip)
mulss  %xmm0,%xmm2
jmp    116f <_gaussdev+0x3f>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@_gaussdev.iset = internal global i32 0
@_gaussdev.gset = internal global float 0.000000e+00
define void @_gaussdev(float* %0, i64 %1) {
%3 = alloca float*
%4 = alloca i64
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i64
store float* %0, float** %3
store i64 %1, i64* %4
store i64 0, i64* %9
br label %10
10: ; preds = %64, %2
%11 = load i64, i64* %9
%12 = load i64, i64* %4
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %67
14: ; preds = %10
%15 = load i32, i32* @_gaussdev.iset
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %58
17: ; preds = %14
br label %18
18: ; preds = %39, %17
%19 = call double (...) @ran1()
%20 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %19, double -1.000000e+00)
%21 = fptrunc double %20 to float
store float %21, float* %7
%22 = call double (...) @ran1()
%23 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %22, double -1.000000e+00)
%24 = fptrunc double %23 to float
store float %24, float* %8
%25 = load float, float* %7
%26 = load float, float* %7
%27 = load float, float* %8
%28 = load float, float* %8
%29 = fmul float %27, %28
%30 = call float @llvm.fmuladd.f32(float %25, float %26, float %29)
store float %30, float* %6
br label %31
31: ; preds = %18
%32 = load float, float* %6
%33 = fpext float %32 to double
%34 = fcmp oge double %33, 1.000000e+00
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load float, float* %6
%37 = fpext float %36 to double
%38 = fcmp oeq double %37, 0.000000e+00
br label %39
39: ; preds = %35, %31
%40 = phi i1 [ true, %31 ], [ %38, %35 ]
br i1 %40, label %18, label %41
41: ; preds = %39
%42 = load float, float* %6
%43 = call double @log(float %42)
%44 = fmul double -2.000000e+00, %43
%45 = load float, float* %6
%46 = fpext float %45 to double
%47 = fdiv double %44, %46
%48 = call float @sqrt(double %47)
store float %48, float* %5
%49 = load float, float* %7
%50 = load float, float* %5
%51 = fmul float %49, %50
store float %51, float* @_gaussdev.gset
store i32 1, i32* @_gaussdev.iset
%52 = load float, float* %8
%53 = load float, float* %5
%54 = fmul float %52, %53
%55 = load float*, float** %3
%56 = load i64, i64* %9
%57 = getelementptr inbounds float, float* %55, i64 %56
store float %54, float* %57
br label %63
58: ; preds = %14
store i32 0, i32* @_gaussdev.iset
%59 = load float, float* @_gaussdev.gset
%60 = load float*, float** %3
%61 = load i64, i64* %9
%62 = getelementptr inbounds float, float* %60, i64 %61
store float %59, float* %62
br label %63
63: ; preds = %58, %41
br label %64
64: ; preds = %63
%65 = load i64, i64* %9
%66 = add nsw i64 %65, 1
store i64 %66, i64* %9
br label %10
67: ; preds = %10
ret void
}

LLVM IR (-O2):
@_gaussdev.iset = internal unnamed_addr global i1 false
@_gaussdev.gset = internal unnamed_addr global float 0.000000e+00
define void @_gaussdev(float* nocapture writeonly %0, i64 %1) {
%3 = icmp sgt i64 %1, 0
br i1 %3, label %4, label %37
4: ; preds = %2
%5 = load i1, i1* @_gaussdev.iset
br label %6
6: ; preds = %4, %31
%7 = phi i1 [ %34, %31 ], [ %5, %4 ]
%8 = phi i64 [ %35, %31 ], [ 0, %4 ]
br i1 %7, label %29, label %9
9: ; preds = %6, %9
%10 = tail call double (...) @ran1()
%11 = tail call double @llvm.fmuladd.f64(double %10, double 2.000000e+00, double -1.000000e+00)
%12 = fptrunc double %11 to float
%13 = tail call double (...) @ran1()
%14 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+00, double -1.000000e+00)
%15 = fptrunc double %14 to float
%16 = fmul float %15, %15
%17 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %16)
%18 = fcmp oge float %17, 1.000000e+00
%19 = fcmp oeq float %17, 0.000000e+00
%20 = or i1 %18, %19
br i1 %20, label %9, label %21
21: ; preds = %9
%22 = fpext float %17 to double
%23 = tail call double @log(float %17)
%24 = fmul double %23, -2.000000e+00
%25 = fdiv double %24, %22
%26 = tail call float @sqrt(double %25)
%27 = fmul float %26, %12
store float %27, float* @_gaussdev.gset
store i1 true, i1* @_gaussdev.iset
%28 = fmul float %26, %15
br label %31
29: ; preds = %6
store i1 false, i1* @_gaussdev.iset
%30 = load float, float* @_gaussdev.gset
br label %31
31: ; preds = %21, %29
%32 = phi float [ %28, %21 ], [ %30, %29 ]
%33 = getelementptr inbounds float, float* %0, i64 %8
store float %32, float* %33
%34 = xor i1 %7, true
%35 = add nuw nsw i64 %8, 1
%36 = icmp eq i64 %35, %1
br i1 %36, label %37, label %6
37: ; preds = %31, %2
ret void
}