#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);
scalar_t__ rand();
int main() {
  double temp;
  int i;
  FILE *f = fopen("rand_uniform.dat", "w");
  for (i = 0; i < 100000; i++) {
    temp = (((double)rand() / (double)RAND_MAX) * 10.0) - 5.0;
    fprintf(f, "%.12e\n", temp);
  }
  fclose(f);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xec4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x186a0,-0x14(%rbp)
jge    11d6 <main+0x96>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e5b(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe62(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe5e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x2d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
lea    0xecc(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    $0x186a0,%ebp
mov    0x2e7f(%rip),%r15
lea    0xeb3(%rip),%r14
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%r15),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xe6d(%rip),%xmm0
addsd  0xe6d(%rip),%xmm0
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1170 <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 = [17 x i8] c"rand_uniform.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 i32
%4 = alloca i32*
store i32 0, i32* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
store i32 0, i32* %3
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 100000
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = call i64 (...) @rand()
%11 = sitofp i64 %10 to double
%12 = load i64, i64* @RAND_MAX
%13 = sitofp i64 %12 to double
%14 = fdiv double %11, %13
%15 = call double @llvm.fmuladd.f64(double %14, double 1.000000e+01, double -5.000000e+00)
store double %15, double* %2
%16 = load i32*, i32** %4
%17 = load double, double* %2
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %17)
br label %19
19: ; preds = %9
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
%23 = load i32*, i32** %4
%24 = call i32 @fclose(i32* %23)
ret i32 -1
}

LLVM IR (-O2):
@.str = [17 x i8] c"rand_uniform.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 ([17 x i8], [17 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 ], [ %11, %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 = tail call double @llvm.fmuladd.f64(double %8, double 1.000000e+01, double -5.000000e+00)
%10 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %9)
%11 = add nuw nsw i32 %3, 1
%12 = icmp eq i32 %11, 100000
br i1 %12, label %13, label %2
13: ; preds = %2
%14 = tail call i32 @fclose(i32* %1)
ret i32 -1
}