#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(double *);
double genrand_res53();
int /*<<< orphan*/ init_genrand(unsigned int const);
scalar_t__ malloc(unsigned int const);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ write_data_as_json_f64(int /*<<< orphan*/ *, double *,
                                          unsigned int const);
void generate_f64_integer_seed(const unsigned int seed, const unsigned int len,
                               const char *name) {
  unsigned int i;
  double *y;
  FILE *f;
  y = (double *)malloc(len * sizeof(double));
  if (y == NULL) {
    printf("Error allocating memory.\n");
    exit(1);
  }
  init_genrand(seed);
  for (i = 0; i < len; i++) {
    y[i] = genrand_res53();
  }
  f = fopen(name, "w");
  if (f == NULL) {
    printf("Error opening file.\n");
    exit(1);
  }
  write_data_as_json_f64(f, y, len);
  fclose(f);
  free(y);
}


x86 assembly (clang, -O0):
<generate_f64_integer_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d5 <generate_f64_integer_seed+0x45>
lea    0xe3a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%edi
call   10a0 <init_genrand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1211 <generate_f64_integer_seed+0x81>
mov    $0x0,%al
call   1070 <genrand_res53@plt>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e4 <generate_f64_integer_seed+0x54>
mov    -0x10(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1246 <generate_f64_integer_seed+0xb6>
lea    0xde5(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1090 <write_data_as_json_f64@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_f64_integer_seed>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x0(,%r14,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1223 <generate_f64_integer_seed+0x93>
mov    %rax,%r12
mov    %ebp,%edi
call   10a0 <init_genrand@plt>
test   %r14d,%r14d
je     11e6 <generate_f64_integer_seed+0x56>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <genrand_res53@plt>
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11d0 <generate_f64_integer_seed+0x40>
lea    0xe13(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     122c <generate_f64_integer_seed+0x9c>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1090 <write_data_as_json_f64@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xdec(%rip),%rdi
jmp    1233 <generate_f64_integer_seed+0xa3>
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Error allocating memory.\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [21 x i8] c"Error opening file.\0A\00"
define void @generate_f64_integer_seed(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %5
%11 = zext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %8
%16 = load double*, double** %8
%17 = icmp eq double* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i32, i32* %4
%23 = call i32 @init_genrand(i32 %22)
store i32 0, i32* %7
br label %24
24: ; preds = %34, %21
%25 = load i32, i32* %7
%26 = load i32, i32* %5
%27 = icmp ult i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = call double (...) @genrand_res53()
%30 = load double*, double** %8
%31 = load i32, i32* %7
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds double, double* %30, i64 %32
store double %29, double* %33
br label %34
34: ; preds = %28
%35 = load i32, i32* %7
%36 = add i32 %35, 1
store i32 %36, i32* %7
br label %24
37: ; preds = %24
%38 = load i8*, i8** %6
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %39, i32** %9
%40 = load i32*, i32** %9
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %37
%46 = load i32*, i32** %9
%47 = load double*, double** %8
%48 = load i32, i32* %5
%49 = call i32 @write_data_as_json_f64(i32* %46, double* %47, i32 %48)
%50 = load i32*, i32** %9
%51 = call i32 @fclose(i32* %50)
%52 = load double*, double** %8
%53 = call i32 @free(double* %52)
ret void
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"w\00"
@str = [20 x i8] c"Error opening file.\00"
@str.3 = [25 x i8] c"Error allocating memory.\00"
define void @generate_f64_integer_seed(i32 %0, i32 %1, i8* nocapture %2) {
%4 = shl i32 %1, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to double*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.3, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = tail call i32 @init_genrand(i32 %0)
%13 = icmp eq i32 %1, 0
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %20, %16 ]
%18 = tail call double (...) @genrand_res53()
%19 = getelementptr inbounds double, double* %6, i64 %17
store double %18, double* %19
%20 = add nuw nsw i64 %17, 1
%21 = icmp eq i64 %20, %15
br i1 %21, label %22, label %16
22: ; preds = %16, %11
%23 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = tail call i32 @write_data_as_json_f64(i32* %23, double* %6, i32 %1)
%30 = tail call i32 @fclose(i32* %23)
%31 = tail call i32 @free(double* %6)
ret void
}