#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 RAND_MAX;
double log(double);
double rand();
double sqrt(double);
void norm_dist(double *vec_of_nums, int length_of_vec, double mean, double sd) {
  double x1, x2, w;
  int ii;
  x1 = 2.0 * rand() / RAND_MAX - 1.0;
  x2 = 2.0 * rand() / RAND_MAX - 1.0;
  w = x1 * x1 + x2 * x2;
  for (ii = 0; ii <= length_of_vec; ii += 2) {
    while (w >= 1.0) {
      x1 = 2.0 * (double)rand() / RAND_MAX - 1.0;
      x2 = 2.0 * (double)rand() / RAND_MAX - 1.0;
      w = x1 * x1 + x2 * x2;
    }
    w = sqrt((-2.0 * log(w)) / w);
    vec_of_nums[ii] = (x1 * w) * sd + mean;
    if (ii < length_of_vec) {
      vec_of_nums[ii + 1] = (x2 * w) * sd + mean;
    }
  }
}


x86 assembly (clang, -O0):
<norm_dist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xead(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e82(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe8e(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xe7b(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2e50(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe5c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1325 <norm_dist+0x1f5>
jmp    11e6 <norm_dist+0xb6>
movsd  -0x38(%rbp),%xmm0
movsd  0xe0d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1287 <norm_dist+0x157>
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xdf9(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2dce(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xdda(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
movaps %xmm0,%xmm1
movsd  0xdc7(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    0x2d9c(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xda8(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11e6 <norm_dist+0xb6>
movsd  -0x38(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  0xd74(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x38(%rbp),%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1312 <norm_dist+0x1e2>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1317 <norm_dist+0x1e7>
mov    -0x3c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d5 <norm_dist+0xa5>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<norm_dist>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x20(%rsp)
mov    %esi,%r14d
mov    %rdi,%r12
xor    %eax,%eax
call   1050 <rand@plt>
movaps %xmm0,(%rsp)
mov    0x2e88(%rip),%rbp
movsd  0x0(%rbp),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
movapd (%rsp),%xmm1
test   %r14d,%r14d
js     12d2 <norm_dist+0x1a2>
unpcklpd %xmm0,%xmm1
addpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm0
movhpd 0x0(%rbp),%xmm0
divpd  %xmm0,%xmm1
addpd  0xe61(%rip),%xmm1
movapd %xmm1,%xmm2
mulpd  %xmm1,%xmm2
unpckhpd %xmm2,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
mov    %r14d,%r15d
movsd  0xe4e(%rip),%xmm2
xor    %ebx,%ebx
jmp    1236 <norm_dist+0x106>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
movapd %xmm0,(%rsp)
movsd  0x0(%rbp),%xmm0
movapd %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1050 <rand@plt>
movapd 0xe0a(%rip),%xmm2
movapd (%rsp),%xmm1
unpcklpd %xmm0,%xmm1
addpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm0
movhpd 0x0(%rbp),%xmm0
divpd  %xmm0,%xmm1
addpd  %xmm2,%xmm1
movapd %xmm1,%xmm2
mulpd  %xmm1,%xmm2
unpckhpd %xmm2,%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  0xdda(%rip),%xmm2
ucomisd %xmm2,%xmm0
jae    11d0 <norm_dist+0xa0>
movapd %xmm0,0x10(%rsp)
movapd %xmm1,(%rsp)
call   1030 <log@plt>
mulsd  0xdc4(%rip),%xmm0
divsd  0x10(%rsp),%xmm0
ucomisd 0xdbe(%rip),%xmm0
jb     126a <norm_dist+0x13a>
sqrtsd %xmm0,%xmm0
jmp    126f <norm_dist+0x13f>
call   1040 <sqrt@plt>
movapd (%rsp),%xmm1
movsd  0xd94(%rip),%xmm2
movapd %xmm1,%xmm4
mulsd  %xmm0,%xmm4
mulsd  0x28(%rsp),%xmm4
addsd  0x20(%rsp),%xmm4
movsd  %xmm4,(%r12,%rbx,8)
cmp    %r15,%rbx
jge    12c5 <norm_dist+0x195>
movapd %xmm1,%xmm4
unpckhpd %xmm1,%xmm4
mulsd  %xmm0,%xmm4
mulsd  0x28(%rsp),%xmm4
addsd  0x20(%rsp),%xmm4
lea    0x0(,%rbx,8),%rax
or     $0x8,%rax
movsd  %xmm4,(%r12,%rax,1)
add    $0x2,%rbx
cmp    %r14d,%ebx
jle    1236 <norm_dist+0x106>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @norm_dist(double* nocapture writeonly %0, i32 %1, double %2, double %3) {
%5 = tail call double (...) @rand()
%6 = load double, double* @RAND_MAX
%7 = tail call double (...) @rand()
%8 = insertelement <2 x double> poison, double %5, i64 0
%9 = insertelement <2 x double> %8, double %7, i64 1
%10 = fmul <2 x double> %9, <double 2.000000e+00, double 2.000000e+00>
%11 = load double, double* @RAND_MAX
%12 = insertelement <2 x double> poison, double %6, i64 0
%13 = insertelement <2 x double> %12, double %11, i64 1
%14 = fdiv <2 x double> %10, %13
%15 = fadd <2 x double> %14, <double -1.000000e+00, double -1.000000e+00>
%16 = icmp slt i32 %1, 0
br i1 %16, label %67, label %17
17: ; preds = %4
%18 = fmul <2 x double> %15, %15
%19 = extractelement <2 x double> %18, i64 1
%20 = extractelement <2 x double> %15, i64 0
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %19)
%22 = zext i32 %1 to i64
br label %23
23: ; preds = %17, %63
%24 = phi i64 [ 0, %17 ], [ %64, %63 ]
%25 = phi double [ %21, %17 ], [ %51, %63 ]
%26 = phi <2 x double> [ %15, %17 ], [ %47, %63 ]
%27 = fcmp ult double %25, 1.000000e+00
br i1 %27, label %45, label %28
28: ; preds = %23, %28
%29 = tail call double (...) @rand()
%30 = load double, double* @RAND_MAX
%31 = tail call double (...) @rand()
%32 = insertelement <2 x double> poison, double %29, i64 0
%33 = insertelement <2 x double> %32, double %31, i64 1
%34 = fmul <2 x double> %33, <double 2.000000e+00, double 2.000000e+00>
%35 = load double, double* @RAND_MAX
%36 = insertelement <2 x double> poison, double %30, i64 0
%37 = insertelement <2 x double> %36, double %35, i64 1
%38 = fdiv <2 x double> %34, %37
%39 = fadd <2 x double> %38, <double -1.000000e+00, double -1.000000e+00>
%40 = fmul <2 x double> %39, %39
%41 = extractelement <2 x double> %40, i64 1
%42 = extractelement <2 x double> %39, i64 0
%43 = tail call double @llvm.fmuladd.f64(double %42, double %42, double %41)
%44 = fcmp ult double %43, 1.000000e+00
br i1 %44, label %45, label %28
45: ; preds = %28, %23
%46 = phi double [ %25, %23 ], [ %43, %28 ]
%47 = phi <2 x double> [ %26, %23 ], [ %39, %28 ]
%48 = tail call double @log(double %46)
%49 = fmul double %48, -2.000000e+00
%50 = fdiv double %49, %46
%51 = tail call double @sqrt(double %50)
%52 = extractelement <2 x double> %47, i64 0
%53 = fmul double %52, %51
%54 = tail call double @llvm.fmuladd.f64(double %53, double %3, double %2)
%55 = getelementptr inbounds double, double* %0, i64 %24
store double %54, double* %55
%56 = icmp slt i64 %24, %22
br i1 %56, label %57, label %63
57: ; preds = %45
%58 = extractelement <2 x double> %47, i64 1
%59 = fmul double %58, %51
%60 = tail call double @llvm.fmuladd.f64(double %59, double %3, double %2)
%61 = or i64 %24, 1
%62 = getelementptr inbounds double, double* %0, i64 %61
store double %60, double* %62
br label %63
63: ; preds = %45, %57
%64 = add nuw i64 %24, 2
%65 = trunc i64 %64 to i32
%66 = icmp sgt i32 %65, %1
br i1 %66, label %67, label %23
67: ; preds = %63, %4
ret void
}