#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, 1.0);
  generate(x, len, "TODO.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    0xe6e(%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  0xe45(%rip),%xmm1
call   1050 <rand_array_f64@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
lea    0xe54(%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   %rbx
mov    $0x1f40,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ab <main+0x4b>
mov    %rax,%rbx
movsd  0xe85(%rip),%xmm1
xorps  %xmm0,%xmm0
mov    %rax,%rdi
mov    $0x3e8,%esi
call   1050 <rand_array_f64@plt>
lea    0xe76(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1080 <generate@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe60(%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 = [10 x i8] c"TODO.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+00)
%19 = load double*, double** %3
%20 = load i32, i32* %2
%21 = call i32 @generate(double* %19, i32 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = load double*, double** %3
%23 = call i32 @free(double* %22)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"TODO.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+00)
%9 = tail call i32 @generate(double* %2, i32 1000, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @free(double* %2)
ret i32 0
}