#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 gaussrand();
int /*<<< orphan*/ printf(char *, double, double, double);
double sqrt(double);
int main(void) {
  double randx;
  double randy;
  double randz;
  double norm;
  for (int i = 0; i <= 5000; i++) {
    randx = gaussrand();
    randy = gaussrand();
    randz = gaussrand();
    norm = sqrt(randx * randx + randy * randy + randz * randz);
    randx = randx / norm;
    randy = randy / norm;
    randz = randz / norm;
    printf("%f,%f,%f\n", randx, randy, randz);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1388,-0x2c(%rbp)
jg     1205 <main+0xd5>
mov    $0x0,%al
call   1040 <gaussrand@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <gaussrand@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <gaussrand@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
lea    0xe0e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x1389,%ebp
lea    0xec6(%rip),%rbx
jmp    118d <main+0x5d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm3,0x10(%rsp)
call   1050 <sqrt@plt>
movsd  0x10(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
divsd  %xmm0,%xmm2
divsd  %xmm0,%xmm1
divsd  %xmm0,%xmm3
mov    %rbx,%rdi
movapd %xmm2,%xmm0
movapd %xmm3,%xmm2
call   1030 <printf@plt>
add    $0xffffffff,%ebp
je     11ef <main+0xbf>
xor    %eax,%eax
call   1040 <gaussrand@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1040 <gaussrand@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <gaussrand@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm3
movapd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movsd  (%rsp),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd 0xe20(%rip),%xmm0
jb     1150 <main+0x20>
sqrtsd %xmm0,%xmm0
jmp    1167 <main+0x37>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%f,%f,%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
br label %7
7: ; preds = %37, %0
%8 = load i32, i32* %6
%9 = icmp sle i32 %8, 5000
br i1 %9, label %10, label %40
10: ; preds = %7
%11 = call double (...) @gaussrand()
store double %11, double* %2
%12 = call double (...) @gaussrand()
store double %12, double* %3
%13 = call double (...) @gaussrand()
store double %13, double* %4
%14 = load double, double* %2
%15 = load double, double* %2
%16 = load double, double* %3
%17 = load double, double* %3
%18 = fmul double %16, %17
%19 = call double @llvm.fmuladd.f64(double %14, double %15, double %18)
%20 = load double, double* %4
%21 = load double, double* %4
%22 = call double @llvm.fmuladd.f64(double %20, double %21, double %19)
%23 = call double @sqrt(double %22)
store double %23, double* %5
%24 = load double, double* %2
%25 = load double, double* %5
%26 = fdiv double %24, %25
store double %26, double* %2
%27 = load double, double* %3
%28 = load double, double* %5
%29 = fdiv double %27, %28
store double %29, double* %3
%30 = load double, double* %4
%31 = load double, double* %5
%32 = fdiv double %30, %31
store double %32, double* %4
%33 = load double, double* %2
%34 = load double, double* %3
%35 = load double, double* %4
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %33, double %34, double %35)
br label %37
37: ; preds = %10
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %7
40: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"%f,%f,%f\0A\00"
define i32 @main() {
br label %2
1: ; preds = %2
ret i32 0
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %15, %2 ]
%4 = tail call double (...) @gaussrand()
%5 = tail call double (...) @gaussrand()
%6 = tail call double (...) @gaussrand()
%7 = fmul double %5, %5
%8 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %7)
%9 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %8)
%10 = tail call double @sqrt(double %9)
%11 = fdiv double %4, %10
%12 = fdiv double %5, %10
%13 = fdiv double %6, %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %11, double %12, double %13)
%15 = add nuw nsw i32 %3, 1
%16 = icmp eq i32 %15, 5001
br i1 %16, label %1, label %2
}