#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ generate(double *, unsigned int, char *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rand_array_f64(double *, unsigned int, double, double);
int main(void) {
  unsigned int len;
  double *x;
  len = 1000;
  x = (double *)malloc(len * sizeof(double));
  if (x == NULL) {
    printf("Error allocating memory.\n");
    exit(1);
  }
  rand_array_f64(x, len, 0.0, 10.0);
  generate(x, len, "small.json");
  rand_array_f64(x, len, 10.0, 100.0);
  generate(x, len, "medium.json");
  rand_array_f64(x, len, 100.0, 36973.0);
  generate(x, len, "medium.json");
  rand_array_f64(x, len, 40000.0, 60000.0);
  generate(x, len, "huge.json");
  free(x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <main+0x49>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
xorps  %xmm0,%xmm0
movsd  0xe65(%rip),%xmm1
call   1050 <rand_array_f64@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
lea    0xe74(%rip),%rdx
call   1080 <generate@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
movsd  0xe3e(%rip),%xmm0
movsd  0xe26(%rip),%xmm1
call   1050 <rand_array_f64@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
lea    0xe50(%rip),%rdx
call   1080 <generate@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
movsd  0xdff(%rip),%xmm0
movsd  0xdff(%rip),%xmm1
call   1050 <rand_array_f64@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
lea    0xe21(%rip),%rdx
call   1080 <generate@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
movsd  0xdc0(%rip),%xmm0
movsd  0xdc0(%rip),%xmm1
call   1050 <rand_array_f64@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
lea    0xdfe(%rip),%rdx
call   1080 <generate@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1f40,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     124a <main+0xea>
mov    %rax,%rbx
movsd  0xe7e(%rip),%xmm1
xorps  %xmm0,%xmm0
mov    %rax,%rdi
mov    $0x3e8,%esi
call   1050 <rand_array_f64@plt>
lea    0xe8f(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1080 <generate@plt>
movsd  0xe5a(%rip),%xmm1
mov    %rbx,%rdi
mov    $0x3e8,%esi
movsd  0xe42(%rip),%xmm0
call   1050 <rand_array_f64@plt>
lea    0xe69(%rip),%r14
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1080 <generate@plt>
movsd  0xe2e(%rip),%xmm1
mov    %rbx,%rdi
mov    $0x3e8,%esi
movsd  0xe16(%rip),%xmm0
call   1050 <rand_array_f64@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1080 <generate@plt>
movsd  0xe09(%rip),%xmm0
movsd  0xe09(%rip),%xmm1
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1050 <rand_array_f64@plt>
lea    0xe14(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1080 <generate@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdf8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Error allocating memory.\0A\00"
@.str.1 = [11 x i8] c"small.json\00"
@.str.2 = [12 x i8] c"medium.json\00"
@.str.3 = [10 x i8] c"huge.json\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double*
store i32 0, i32* %1
store i32 1000, i32* %2
%4 = load i32, i32* %2
%5 = zext i32 %4 to i64
%6 = mul i64 %5, 8
%7 = trunc i64 %6 to i32
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
store double* %9, double** %3
%10 = load double*, double** %3
%11 = icmp eq double* %10, null
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load double*, double** %3
%17 = load i32, i32* %2
%18 = call i32 @rand_array_f64(double* %16, i32 %17, double 0.000000e+00, double 1.000000e+01)
%19 = load double*, double** %3
%20 = load i32, i32* %2
%21 = call i32 @generate(double* %19, i32 %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%22 = load double*, double** %3
%23 = load i32, i32* %2
%24 = call i32 @rand_array_f64(double* %22, i32 %23, double 1.000000e+01, double 1.000000e+02)
%25 = load double*, double** %3
%26 = load i32, i32* %2
%27 = call i32 @generate(double* %25, i32 %26, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%28 = load double*, double** %3
%29 = load i32, i32* %2
%30 = call i32 @rand_array_f64(double* %28, i32 %29, double 1.000000e+02, double 3.697300e+04)
%31 = load double*, double** %3
%32 = load i32, i32* %2
%33 = call i32 @generate(double* %31, i32 %32, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%34 = load double*, double** %3
%35 = load i32, i32* %2
%36 = call i32 @rand_array_f64(double* %34, i32 %35, double 4.000000e+04, double 6.000000e+04)
%37 = load double*, double** %3
%38 = load i32, i32* %2
%39 = call i32 @generate(double* %37, i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%40 = load double*, double** %3
%41 = call i32 @free(double* %40)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"small.json\00"
@.str.2 = [12 x i8] c"medium.json\00"
@.str.3 = [10 x i8] c"huge.json\00"
@str = [25 x i8] c"Error allocating memory.\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 8000)
%2 = inttoptr i64 %1 to double*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 @rand_array_f64(double* %2, i32 1000, double 0.000000e+00, double 1.000000e+01)
%9 = tail call i32 @generate(double* %2, i32 1000, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @rand_array_f64(double* %2, i32 1000, double 1.000000e+01, double 1.000000e+02)
%11 = tail call i32 @generate(double* %2, i32 1000, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @rand_array_f64(double* %2, i32 1000, double 1.000000e+02, double 3.697300e+04)
%13 = tail call i32 @generate(double* %2, i32 1000, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @rand_array_f64(double* %2, i32 1000, double 4.000000e+04, double 6.000000e+04)
%15 = tail call i32 @generate(double* %2, i32 1000, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @free(double* %2)
ret i32 0
}