#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 GenRandomPercentage();
int exp(double);
double GenRandomGaussian(double mean, double sigma) {
  double rand, dist, step;
  double normalization;
  double totdist;
  double renorm;
  double nbins, excursion, signz;
  int i;
  nbins = 100;
  step = 3 * sigma / nbins;
  i = 0;
  totdist = 0.0;
  for (i = 0; i < nbins; i++) {
    totdist = totdist + exp(-(step * i) * (step * i) / 2 / sigma / sigma);
  }
  rand = GenRandomPercentage();
  i = 0;
  dist = 0.0;
  while (dist < rand) {
    dist = dist +
           (1 / totdist) * exp(-(step * i) * (step * i) / 2 / sigma / sigma);
    i++;
  }
  excursion = step * i;
  rand = GenRandomPercentage();
  if (rand > 0.5)
    signz = 1;
  else
    signz = -1;
  return mean + signz * excursion;
}


x86 assembly (clang, -O0):
<GenRandomGaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xecb(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xeb6(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x5c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x5c(%rbp)
cvtsi2sdl -0x5c(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ff <GenRandomGaussian+0xdf>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x5c(%rbp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5c(%rip),%xmm1
divsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  -0x68(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    116f <GenRandomGaussian+0x4f>
mov    $0x0,%al
call   1040 <GenRandomPercentage@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x5c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12c5 <GenRandomGaussian+0x1a5>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xde0(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x5c(%rbp),%xmm2
mulsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9f(%rip),%xmm1
divsd  %xmm1,%xmm0
divsd  -0x10(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  -0x78(%rbp),%xmm0
movsd  -0x70(%rbp),%xmm1
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    121a <GenRandomGaussian+0xfa>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x5c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    $0x0,%al
call   1040 <GenRandomPercentage@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xd1f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    130d <GenRandomGaussian+0x1ed>
movsd  0xd1d(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    131a <GenRandomGaussian+0x1fa>
movsd  0xd03(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenRandomGaussian>:
push   %rbx
sub    $0x30,%rsp
movsd  %xmm0,0x20(%rsp)
movsd  0xecd(%rip),%xmm0
movsd  %xmm1,0x18(%rsp)
mulsd  %xmm1,%xmm0
divsd  0xec3(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm1,%xmm1
mov    $0x64,%ebx
xorpd  %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm0,%xmm0
mulsd  0xe8f(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
movsd  (%rsp),%xmm0
addsd  0xe5c(%rip),%xmm1
add    $0xffffffff,%ebx
jne    1160 <GenRandomGaussian+0x40>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <GenRandomPercentage@plt>
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jbe    1261 <GenRandomGaussian+0x141>
movsd  0xe34(%rip),%xmm1
divsd  (%rsp),%xmm1
xorpd  %xmm3,%xmm3
movsd  %xmm1,0x10(%rsp)
movsd  %xmm2,0x28(%rsp)
nopl   0x0(%rax)
movsd  %xmm3,(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  0x8(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0xdf2(%rip),%xmm0
movsd  0x18(%rsp),%xmm1
divsd  %xmm1,%xmm0
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  (%rsp),%xmm3
movsd  0x28(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
addsd  %xmm0,%xmm3
add    $0x1,%ebx
ucomisd %xmm3,%xmm2
ja     1200 <GenRandomGaussian+0xe0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <GenRandomPercentage@plt>
xor    %eax,%eax
ucomisd 0xda9(%rip),%xmm0
seta   %al
movsd  0x8(%rsp),%xmm0
mulsd  (%rsp),%xmm0
lea    0xd9c(%rip),%rcx
mulsd  (%rcx,%rax,8),%xmm0
addsd  0x20(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @GenRandomGaussian(double %0, double %1) {
%3 = fmul double %1, 3.000000e+00
%4 = fdiv double %3, 1.000000e+02
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 0, %2 ], [ %18, %5 ]
%7 = phi double [ 0.000000e+00, %2 ], [ %17, %5 ]
%8 = sitofp i32 %6 to double
%9 = fmul double %4, %8
%10 = fneg double %9
%11 = fmul double %9, %10
%12 = fmul double %11, 5.000000e-01
%13 = fdiv double %12, %1
%14 = fdiv double %13, %1
%15 = tail call i32 @exp(double %14)
%16 = sitofp i32 %15 to double
%17 = fadd double %7, %16
%18 = add nuw nsw i32 %6, 1
%19 = icmp eq i32 %18, 100
br i1 %19, label %20, label %5
20: ; preds = %5
%21 = tail call double (...) @GenRandomPercentage()
%22 = fcmp ogt double %21, 0.000000e+00
br i1 %22, label %23, label %42
23: ; preds = %20
%24 = fdiv double 1.000000e+00, %17
br label %25
25: ; preds = %23, %25
%26 = phi i32 [ 0, %23 ], [ %38, %25 ]
%27 = phi double [ 0.000000e+00, %23 ], [ %37, %25 ]
%28 = sitofp i32 %26 to double
%29 = fmul double %4, %28
%30 = fneg double %29
%31 = fmul double %29, %30
%32 = fmul double %31, 5.000000e-01
%33 = fdiv double %32, %1
%34 = fdiv double %33, %1
%35 = tail call i32 @exp(double %34)
%36 = sitofp i32 %35 to double
%37 = tail call double @llvm.fmuladd.f64(double %24, double %36, double %27)
%38 = add nuw nsw i32 %26, 1
%39 = fcmp olt double %37, %21
br i1 %39, label %25, label %40
40: ; preds = %25
%41 = sitofp i32 %38 to double
br label %42
42: ; preds = %40, %20
%43 = phi double [ 0.000000e+00, %20 ], [ %41, %40 ]
%44 = tail call double (...) @GenRandomPercentage()
%45 = fcmp ogt double %44, 5.000000e-01
%46 = select i1 %45, double 1.000000e+00, double -1.000000e+00
%47 = fmul double %4, %43
%48 = tail call double @llvm.fmuladd.f64(double %46, double %47, double %0)
ret double %48
}