#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 */
int CHAR_MAX;
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ LLONG_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ fwrite(int *, int, int const, int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ srand(int);
int main(void) {
  const int CHARS_IN_DOUBLE = sizeof(double) / sizeof(char);
  const int N = 10e6 / CHARS_IN_DOUBLE;
  FILE *fileDoubleNorm = fopen("randomDoubleNorm.txt", "wb");
  FILE *fileDoubleFull = fopen("randomDoubleFull.txt", "wb");
  FILE *fileLongLong = fopen("randomLongLong.txt", "wb");
  FILE *fileBinary = fopen("randomBinary.dat", "wb");
  union {
    char chars[CHARS_IN_DOUBLE];
    long long as_llong;
    double as_double;
  } r;
  srand(666);
  for (long n = 0; n < N; n++) {
    for (int c = 0; c < CHARS_IN_DOUBLE; c++) {
      r.chars[c] = rand() % CHAR_MAX;
    }
    fprintf(fileDoubleNorm, "%.17lg\n", (double)r.as_llong / (double)LLONG_MAX);
    fprintf(fileDoubleFull, "%.17lg\n", r.as_double);
    fprintf(fileLongLong, "%lld\n", r.as_llong);
    fwrite(r.chars, sizeof(char), CHARS_IN_DOUBLE, fileBinary);
  }
  fclose(fileDoubleNorm);
  fclose(fileDoubleFull);
  fclose(fileLongLong);
  fclose(fileBinary);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x8,-0x8(%rbp)
movl   $0x1312d0,-0xc(%rbp)
lea    0xe6c(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe6d(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe6b(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe35(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x29a,%edi
call   1040 <srand@plt>
movq   $0x0,-0x40(%rbp)
cmpq   $0x1312d0,-0x40(%rbp)
jge    12bc <main+0x14c>
movl   $0x0,-0x44(%rbp)
cmpl   $0x8,-0x44(%rbp)
jge    1243 <main+0xd3>
mov    $0x0,%al
call   1090 <rand@plt>
mov    0x2dc0(%rip),%rcx
cltd
idivl  (%rcx)
mov    %dl,%cl
movslq -0x44(%rbp),%rax
mov    %cl,-0x38(%rbp,%rax,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1210 <main+0xa0>
mov    -0x18(%rbp),%rdi
cvtsi2sdq -0x38(%rbp),%xmm0
mov    0x2d8c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xded(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
movsd  -0x38(%rbp),%xmm0
lea    0xdd8(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
cvtsi2sdq -0x38(%rbp),%xmm0
lea    0xdca(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x8,%edx
call   1080 <fwrite@plt>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11fb <main+0x8b>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe89(%rip),%rbx
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,0x18(%rsp)
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,0x10(%rsp)
lea    0xe79(%rip),%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
call   1060 <fopen@plt>
mov    %rax,%r13
mov    $0x29a,%edi
call   1040 <srand@plt>
mov    $0x1312d0,%ebp
mov    0x2e01(%rip),%r14
lea    0xe63(%rip),%rbx
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0x8(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0x9(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0xa(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0xb(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0xc(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0xd(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0xe(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idivl  (%r14)
mov    %dl,0xf(%rsp)
mov    0x8(%rsp),%r15
xorps  %xmm0,%xmm0
cvtsi2sd %r15,%xmm0
movsd  %xmm0,0x20(%rsp)
mov    0x2d5e(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    0x18(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fprintf@plt>
movq   %r15,%xmm0
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <fprintf@plt>
mov    %r12,%rdi
lea    0xda5(%rip),%rsi
movsd  0x20(%rsp),%xmm0
call   1050 <fprintf@plt>
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %r13,%rcx
call   1080 <fwrite@plt>
add    $0xffffffffffffffff,%rbp
jne    11f0 <main+0x80>
mov    0x18(%rsp),%rdi
call   1030 <fclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%union.anon = type { i64 }
@.str = [21 x i8] c"randomDoubleNorm.txt\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [21 x i8] c"randomDoubleFull.txt\00"
@.str.3 = [19 x i8] c"randomLongLong.txt\00"
@.str.4 = [17 x i8] c"randomBinary.dat\00"
@CHAR_MAX = global i32 0
@.str.5 = [8 x i8] c"%.17lg\0A\00"
@LLONG_MAX = global i64 0
@.str.6 = [6 x i8] c"%lld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %union.anon
%9 = alloca i64
%10 = alloca i32
store i32 0, i32* %1
store i32 8, i32* %2
store i32 1250000, i32* %3
%11 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %6
%14 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = call i32 @srand(i32 666)
store i64 0, i64* %9
br label %16
16: ; preds = %58, %0
%17 = load i64, i64* %9
%18 = icmp slt i64 %17, 1250000
br i1 %18, label %19, label %61
19: ; preds = %16
store i32 0, i32* %10
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 8
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = call i32 (...) @rand()
%25 = load i32, i32* @CHAR_MAX
%26 = srem i32 %24, %25
%27 = trunc i32 %26 to i8
%28 = bitcast %union.anon* %8 to [8 x i8]*
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [8 x i8], [8 x i8]* %28, i64 0, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %23
%33 = load i32, i32* %10
%34 = add nsw i32 %33, 1
store i32 %34, i32* %10
br label %20
35: ; preds = %20
%36 = load i32*, i32** %4
%37 = bitcast %union.anon* %8 to i64*
%38 = load i64, i64* %37
%39 = sitofp i64 %38 to double
%40 = load i64, i64* @LLONG_MAX
%41 = sitofp i64 %40 to double
%42 = fdiv double %39, %41
%43 = call i32 @fprintf(i32* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %42)
%44 = load i32*, i32** %5
%45 = bitcast %union.anon* %8 to double*
%46 = load double, double* %45
%47 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %46)
%48 = load i32*, i32** %6
%49 = bitcast %union.anon* %8 to i64*
%50 = load i64, i64* %49
%51 = sitofp i64 %50 to double
%52 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), double %51)
%53 = bitcast %union.anon* %8 to [8 x i8]*
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %53, i64 0, i64 0
%55 = bitcast i8* %54 to i32*
%56 = load i32*, i32** %7
%57 = call i32 @fwrite(i32* %55, i32 1, i32 8, i32* %56)
br label %58
58: ; preds = %35
%59 = load i64, i64* %9
%60 = add nsw i64 %59, 1
store i64 %60, i64* %9
br label %16
61: ; preds = %16
%62 = load i32*, i32** %4
%63 = call i32 @fclose(i32* %62)
%64 = load i32*, i32** %5
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
%70 = load i32, i32* @EXIT_SUCCESS
%71 = call i32 @exit(i32 %70)
unreachable
}

LLVM IR (-O2):
%union.anon = type { i64 }
@.str = [21 x i8] c"randomDoubleNorm.txt\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [21 x i8] c"randomDoubleFull.txt\00"
@.str.3 = [19 x i8] c"randomLongLong.txt\00"
@.str.4 = [17 x i8] c"randomBinary.dat\00"
@CHAR_MAX = global i32 0
@.str.5 = [8 x i8] c"%.17lg\0A\00"
@LLONG_MAX = global i64 0
@.str.6 = [6 x i8] c"%lld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %union.anon
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = bitcast %union.anon* %1 to i8*
%7 = tail call i32 @srand(i32 666)
%8 = bitcast %union.anon* %1 to [8 x i8]*
%9 = getelementptr inbounds %union.anon, %union.anon* %1, i64 0, i32 0
%10 = bitcast %union.anon* %1 to i32*
%11 = bitcast %union.anon* %1 to i8*
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 1
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 2
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 3
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 4
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 5
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 6
%18 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 7
br label %19
19: ; preds = %0, %19
%20 = phi i64 [ 0, %0 ], [ %63, %19 ]
%21 = tail call i32 (...) @rand()
%22 = load i32, i32* @CHAR_MAX
%23 = srem i32 %21, %22
%24 = trunc i32 %23 to i8
store i8 %24, i8* %11
%25 = tail call i32 (...) @rand()
%26 = load i32, i32* @CHAR_MAX
%27 = srem i32 %25, %26
%28 = trunc i32 %27 to i8
store i8 %28, i8* %12
%29 = tail call i32 (...) @rand()
%30 = load i32, i32* @CHAR_MAX
%31 = srem i32 %29, %30
%32 = trunc i32 %31 to i8
store i8 %32, i8* %13
%33 = tail call i32 (...) @rand()
%34 = load i32, i32* @CHAR_MAX
%35 = srem i32 %33, %34
%36 = trunc i32 %35 to i8
store i8 %36, i8* %14
%37 = tail call i32 (...) @rand()
%38 = load i32, i32* @CHAR_MAX
%39 = srem i32 %37, %38
%40 = trunc i32 %39 to i8
store i8 %40, i8* %15
%41 = tail call i32 (...) @rand()
%42 = load i32, i32* @CHAR_MAX
%43 = srem i32 %41, %42
%44 = trunc i32 %43 to i8
store i8 %44, i8* %16
%45 = tail call i32 (...) @rand()
%46 = load i32, i32* @CHAR_MAX
%47 = srem i32 %45, %46
%48 = trunc i32 %47 to i8
store i8 %48, i8* %17
%49 = tail call i32 (...) @rand()
%50 = load i32, i32* @CHAR_MAX
%51 = srem i32 %49, %50
%52 = trunc i32 %51 to i8
store i8 %52, i8* %18
%53 = load i64, i64* %9
%54 = sitofp i64 %53 to double
%55 = load i64, i64* @LLONG_MAX
%56 = sitofp i64 %55 to double
%57 = fdiv double %54, %56
%58 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %57)
%59 = bitcast i64 %53 to double
%60 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), double %59)
%61 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), double %54)
%62 = call i32 @fwrite(i32* %10, i32 1, i32 8, i32* %5)
%63 = add nuw nsw i64 %20, 1
%64 = icmp eq i64 %63, 1250000
br i1 %64, label %65, label %19
65: ; preds = %19
%66 = tail call i32 @fclose(i32* %2)
%67 = tail call i32 @fclose(i32* %3)
%68 = tail call i32 @fclose(i32* %4)
%69 = tail call i32 @fclose(i32* %5)
%70 = load i32, i32* @EXIT_SUCCESS
%71 = tail call i32 @exit(i32 %70)
unreachable
}