#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 gauss_density(double);
double gauss_integral(double);
double rand_area();
double rand_gauss_normalized(void) {
  double xi, yi, area, slope;
  double limit = 0.00001;
  int n;
  area = rand_area();
  n = 0;
  xi = 0;
  do {
    yi = gauss_integral(xi) - area;
    slope = gauss_density(xi);
    xi = xi - yi / slope;
    n++;
  } while (n < 100 && (yi > limit || yi < -limit));
  return xi;
}


x86 assembly (clang, -O0):
<rand_gauss_normalized>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <rand_area@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <gauss_integral@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <gauss_density@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
cmpl   $0x64,-0x2c(%rbp)
mov    %al,-0x2d(%rbp)
jge    11f9 <rand_gauss_normalized+0xc9>
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%al
ucomisd -0x28(%rbp),%xmm0
mov    %al,-0x2e(%rbp)
ja     11f3 <rand_gauss_normalized+0xc3>
movsd  -0x10(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x2e(%rbp)
mov    -0x2e(%rbp),%al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1160 <rand_gauss_normalized+0x30>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_gauss_normalized>:
push   %rbx
sub    $0x20,%rsp
xor    %eax,%eax
call   1040 <rand_area@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
mov    $0x64,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <gauss_integral@plt>
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <gauss_density@plt>
movsd  0x18(%rsp),%xmm2
movapd %xmm2,%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0xffffffff,%ebx
je     11ad <rand_gauss_normalized+0x7d>
ucomisd 0xe63(%rip),%xmm2
ja     1150 <rand_gauss_normalized+0x20>
movsd  0xe61(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     1150 <rand_gauss_normalized+0x20>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @rand_gauss_normalized() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store double 1.000000e-05, double* %5
%7 = call double (...) @rand_area()
store double %7, double* %3
store i32 0, i32* %6
store double 0.000000e+00, double* %1
br label %8
8: ; preds = %36, %0
%9 = load double, double* %1
%10 = call double @gauss_integral(double %9)
%11 = load double, double* %3
%12 = fsub double %10, %11
store double %12, double* %2
%13 = load double, double* %1
%14 = call double @gauss_density(double %13)
store double %14, double* %4
%15 = load double, double* %1
%16 = load double, double* %2
%17 = load double, double* %4
%18 = fdiv double %16, %17
%19 = fsub double %15, %18
store double %19, double* %1
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
br label %22
22: ; preds = %8
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 100
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = load double, double* %2
%27 = load double, double* %5
%28 = fcmp ogt double %26, %27
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = load double, double* %2
%31 = load double, double* %5
%32 = fneg double %31
%33 = fcmp olt double %30, %32
br label %34
34: ; preds = %29, %25
%35 = phi i1 [ true, %25 ], [ %33, %29 ]
br label %36
36: ; preds = %34, %22
%37 = phi i1 [ false, %22 ], [ %35, %34 ]
br i1 %37, label %8, label %38
38: ; preds = %36
%39 = load double, double* %1
ret double %39
}

LLVM IR (-O2):
define double @rand_gauss_normalized() {
%1 = tail call double (...) @rand_area()
br label %2
2: ; preds = %11, %0
%3 = phi double [ 0.000000e+00, %0 ], [ %9, %11 ]
%4 = phi i32 [ 0, %0 ], [ %12, %11 ]
%5 = tail call double @gauss_integral(double %3)
%6 = fsub double %5, %1
%7 = tail call double @gauss_density(double %3)
%8 = fdiv double %6, %7
%9 = fsub double %3, %8
%10 = icmp eq i32 %4, 99
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = add nuw nsw i32 %4, 1
%13 = fcmp ogt double %6, 1.000000e-05
%14 = fcmp olt double %6, -1.000000e-05
%15 = or i1 %13, %14
br i1 %15, label %2, label %16
16: ; preds = %2, %11
ret double %9
}