#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double log(double);
scalar_t__ rand();
int main() {
  double temp, x;
  int i;
  FILE *f = fopen("rand_exp.dat", "w");
  for (i = 0; i < 100000; i++) {
    temp = ((double)rand() / (double)RAND_MAX) * (1.0 / 3.0);
    x = -3.0 * log(3.0 * temp);
    fprintf(f, "%.12e\n", x);
  }
  fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb2(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x186a0,-0x1c(%rbp)
jge    1200 <main+0xb0>
mov    $0x0,%al
call   1070 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e4b(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe62(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe49(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  0xe2c(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
movsd  -0x18(%rbp),%xmm0
lea    0xe3a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <main+0x2d>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeba(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    $0x186a0,%ebp
mov    0x2e6f(%rip),%r15
lea    0xea7(%rip),%r14
xor    %eax,%eax
call   1070 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xe5d(%rip),%xmm0
mulsd  0xe5d(%rip),%xmm0
call   1050 <log@plt>
mulsd  0xe58(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"rand_exp.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global i64 0
@.str.2 = [7 x i8] c"%.12e\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
store i32 0, i32* %4
br label %7
7: ; preds = %24, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 100000
br i1 %9, label %10, label %27
10: ; preds = %7
%11 = call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load i64, i64* @RAND_MAX
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
%16 = fmul double %15, 0x3FD5555555555555
store double %16, double* %2
%17 = load double, double* %2
%18 = fmul double 3.000000e+00, %17
%19 = call double @log(double %18)
%20 = fmul double -3.000000e+00, %19
store double %20, double* %3
%21 = load i32*, i32** %5
%22 = load double, double* %3
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %22)
br label %24
24: ; preds = %10
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %7
27: ; preds = %7
%28 = load i32*, i32** %5
%29 = call i32 @fclose(i32* %28)
ret i32 -1
}

LLVM IR (-O2):
@.str = [13 x i8] c"rand_exp.dat\00"
@.str.1 = [2 x i8] c"w\00"
@RAND_MAX = global i64 0
@.str.2 = [7 x i8] c"%.12e\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %14, %2 ]
%4 = tail call i64 (...) @rand()
%5 = sitofp i64 %4 to double
%6 = load i64, i64* @RAND_MAX
%7 = sitofp i64 %6 to double
%8 = fdiv double %5, %7
%9 = fmul double %8, 0x3FD5555555555555
%10 = fmul double %9, 3.000000e+00
%11 = tail call double @log(double %10)
%12 = fmul double %11, -3.000000e+00
%13 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %12)
%14 = add nuw nsw i32 %3, 1
%15 = icmp eq i32 %14, 100000
br i1 %15, label %16, label %2
16: ; preds = %2
%17 = tail call i32 @fclose(i32* %1)
ret i32 -1
}