#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_by_array(unsigned long *, 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_array_seed(unsigned long *seed, const unsigned int nwords,
                             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_by_array(seed, nwords);
  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_array_seed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d9 <generate_f64_array_seed+0x49>
lea    0xe36(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1060 <init_by_array@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1219 <generate_f64_array_seed+0x89>
mov    $0x0,%al
call   1080 <genrand_res53@plt>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ec <generate_f64_array_seed+0x5c>
mov    -0x18(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124e <generate_f64_array_seed+0xbe>
lea    0xddd(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   10a0 <write_data_as_json_f64@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_f64_array_seed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbp
lea    0x0(,%r14,8),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     123a <generate_f64_array_seed+0xaa>
mov    %rax,%r13
mov    %rbp,%rdi
mov    %r12d,%esi
call   1060 <init_by_array@plt>
test   %r14d,%r14d
je     11f7 <generate_f64_array_seed+0x67>
mov    %r14d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <genrand_res53@plt>
movsd  %xmm0,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <generate_f64_array_seed+0x50>
lea    0xe02(%rip),%rsi
mov    %r15,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1243 <generate_f64_array_seed+0xb3>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r14d,%edx
call   10a0 <write_data_as_json_f64@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xdd5(%rip),%rdi
jmp    124a <generate_f64_array_seed+0xba>
lea    0xdb8(%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_array_seed(i64* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32*
store i64* %0, i64** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i32, i32* %7
%13 = zext i32 %12 to i64
%14 = mul i64 %13, 8
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to double*
store double* %17, double** %10
%18 = load double*, double** %10
%19 = icmp eq double* %18, null
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %4
%24 = load i64*, i64** %5
%25 = load i32, i32* %6
%26 = call i32 @init_by_array(i64* %24, i32 %25)
store i32 0, i32* %9
br label %27
27: ; preds = %37, %23
%28 = load i32, i32* %9
%29 = load i32, i32* %7
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = call double (...) @genrand_res53()
%33 = load double*, double** %10
%34 = load i32, i32* %9
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
store double %32, double* %36
br label %37
37: ; preds = %31
%38 = load i32, i32* %9
%39 = add i32 %38, 1
store i32 %39, i32* %9
br label %27
40: ; preds = %27
%41 = load i8*, i8** %8
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %42, i32** %11
%43 = load i32*, i32** %11
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %40
%49 = load i32*, i32** %11
%50 = load double*, double** %10
%51 = load i32, i32* %7
%52 = call i32 @write_data_as_json_f64(i32* %49, double* %50, i32 %51)
%53 = load i32*, i32** %11
%54 = call i32 @fclose(i32* %53)
%55 = load double*, double** %10
%56 = call i32 @free(double* %55)
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_array_seed(i64* %0, i32 %1, i32 %2, i8* nocapture %3) {
%5 = shl i32 %2, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = tail call i32 @init_by_array(i64* %0, i32 %1)
%14 = icmp eq i32 %2, 0
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = zext i32 %2 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %21, %17 ]
%19 = tail call double (...) @genrand_res53()
%20 = getelementptr inbounds double, double* %7, i64 %18
store double %19, double* %20
%21 = add nuw nsw i64 %18, 1
%22 = icmp eq i64 %21, %16
br i1 %22, label %23, label %17
23: ; preds = %17, %12
%24 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %23
%30 = tail call i32 @write_data_as_json_f64(i32* %24, double* %7, i32 %2)
%31 = tail call i32 @fclose(i32* %24)
%32 = tail call i32 @free(double* %7)
ret void
}