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


x86 assembly (clang, -O0):
<generate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b6 <generate+0x46>
lea    0xe61(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11eb <generate+0x7b>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  0xe28(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bd <generate+0x4d>
mov    -0x18(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1220 <generate+0xb0>
lea    0xe13(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1060 <write_data_as_json@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>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x0(,%r14,8),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1300 <generate+0x190>
mov    %rax,%rbx
test   %r14d,%r14d
je     12bd <generate+0x14d>
mov    %r14d,%eax
cmp    $0x4,%r14d
jae    11b3 <generate+0x43>
xor    %ecx,%ecx
jmp    1297 <generate+0x127>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
lea    -0x4(%rcx),%rdi
mov    %rdi,%rsi
shr    $0x2,%rsi
add    $0x1,%rsi
mov    %esi,%edx
and    $0x7,%edx
cmp    $0x1c,%rdi
jae    11d9 <generate+0x69>
xor    %edi,%edi
jmp    1261 <generate+0xf1>
and    $0xfffffffffffffff8,%rsi
xor    %edi,%edi
movaps 0xe1a(%rip),%xmm0
cs nopw 0x0(%rax,%rax,1)
movups %xmm0,(%rbx,%rdi,8)
movups %xmm0,0x10(%rbx,%rdi,8)
movups %xmm0,0x20(%rbx,%rdi,8)
movups %xmm0,0x30(%rbx,%rdi,8)
movups %xmm0,0x40(%rbx,%rdi,8)
movups %xmm0,0x50(%rbx,%rdi,8)
movups %xmm0,0x60(%rbx,%rdi,8)
movups %xmm0,0x70(%rbx,%rdi,8)
movups %xmm0,0x80(%rbx,%rdi,8)
movups %xmm0,0x90(%rbx,%rdi,8)
movups %xmm0,0xa0(%rbx,%rdi,8)
movups %xmm0,0xb0(%rbx,%rdi,8)
movups %xmm0,0xc0(%rbx,%rdi,8)
movups %xmm0,0xd0(%rbx,%rdi,8)
movups %xmm0,0xe0(%rbx,%rdi,8)
movups %xmm0,0xf0(%rbx,%rdi,8)
add    $0x20,%rdi
add    $0xfffffffffffffff8,%rsi
jne    11f0 <generate+0x80>
test   %rdx,%rdx
je     1292 <generate+0x122>
lea    (%rbx,%rdi,8),%rsi
add    $0x10,%rsi
shl    $0x5,%rdx
xor    %edi,%edi
movaps 0xd85(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
movups %xmm0,-0x10(%rsi,%rdi,1)
movups %xmm0,(%rsi,%rdi,1)
add    $0x20,%rdi
cmp    %rdi,%rdx
jne    1280 <generate+0x110>
cmp    %rax,%rcx
je     12bd <generate+0x14d>
movabs $0x40091eb851eb851f,%rdx
1e 09 40
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdx,(%rbx,%rcx,8)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    12b0 <generate+0x140>
lea    0xd4c(%rip),%rsi
mov    %r12,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1309 <generate+0x199>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1060 <write_data_as_json@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
lea    0xd1f(%rip),%rdi
jmp    1310 <generate+0x1a0>
lea    0xd02(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <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(double* %0, i32 %1, i8* %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32*
store double* %0, double** %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
store i32 0, i32* %7
br label %22
22: ; preds = %31, %21
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load double*, double** %8
%28 = load i32, i32* %7
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
store double 3.140000e+00, double* %30
br label %31
31: ; preds = %26
%32 = load i32, i32* %7
%33 = add i32 %32, 1
store i32 %33, i32* %7
br label %22
34: ; preds = %22
%35 = load i8*, i8** %6
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %9
%37 = load i32*, i32** %9
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = load i32*, i32** %9
%44 = load double*, double** %4
%45 = load double*, double** %8
%46 = load i32, i32* %5
%47 = call i32 @write_data_as_json(i32* %43, double* %44, double* %45, i32 %46)
%48 = load i32*, i32** %9
%49 = call i32 @fclose(i32* %48)
%50 = load double*, double** %8
%51 = call i32 @free(double* %50)
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(double* %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 %84, label %8
8: ; preds = %3
%9 = icmp eq i32 %1, 0
br i1 %9, label %92, label %10
10: ; preds = %8
%11 = zext i32 %1 to i64
%12 = icmp ult i32 %1, 4
br i1 %12, label %82, label %13
13: ; preds = %10
%14 = and i64 %11, 4294967292
%15 = add nsw i64 %14, -4
%16 = lshr exact i64 %15, 2
%17 = add nuw nsw i64 %16, 1
%18 = and i64 %17, 7
%19 = icmp ult i64 %15, 28
br i1 %19, label %67, label %20
20: ; preds = %13
%21 = and i64 %17, 9223372036854775800
br label %22
22: ; preds = %22, %20
%23 = phi i64 [ 0, %20 ], [ %64, %22 ]
%24 = phi i64 [ 0, %20 ], [ %65, %22 ]
%25 = getelementptr inbounds double, double* %6, i64 %23
%26 = bitcast double* %25 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %26
%27 = getelementptr inbounds double, double* %25, i64 2
%28 = bitcast double* %27 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %28
%29 = or i64 %23, 4
%30 = getelementptr inbounds double, double* %6, i64 %29
%31 = bitcast double* %30 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %31
%32 = getelementptr inbounds double, double* %30, i64 2
%33 = bitcast double* %32 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %33
%34 = or i64 %23, 8
%35 = getelementptr inbounds double, double* %6, i64 %34
%36 = bitcast double* %35 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %36
%37 = getelementptr inbounds double, double* %35, i64 2
%38 = bitcast double* %37 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %38
%39 = or i64 %23, 12
%40 = getelementptr inbounds double, double* %6, i64 %39
%41 = bitcast double* %40 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %41
%42 = getelementptr inbounds double, double* %40, i64 2
%43 = bitcast double* %42 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %43
%44 = or i64 %23, 16
%45 = getelementptr inbounds double, double* %6, i64 %44
%46 = bitcast double* %45 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %46
%47 = getelementptr inbounds double, double* %45, i64 2
%48 = bitcast double* %47 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %48
%49 = or i64 %23, 20
%50 = getelementptr inbounds double, double* %6, i64 %49
%51 = bitcast double* %50 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %51
%52 = getelementptr inbounds double, double* %50, i64 2
%53 = bitcast double* %52 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %53
%54 = or i64 %23, 24
%55 = getelementptr inbounds double, double* %6, i64 %54
%56 = bitcast double* %55 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %56
%57 = getelementptr inbounds double, double* %55, i64 2
%58 = bitcast double* %57 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %58
%59 = or i64 %23, 28
%60 = getelementptr inbounds double, double* %6, i64 %59
%61 = bitcast double* %60 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %61
%62 = getelementptr inbounds double, double* %60, i64 2
%63 = bitcast double* %62 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %63
%64 = add nuw i64 %23, 32
%65 = add i64 %24, 8
%66 = icmp eq i64 %65, %21
br i1 %66, label %67, label %22
67: ; preds = %22, %13
%68 = phi i64 [ 0, %13 ], [ %64, %22 ]
%69 = icmp eq i64 %18, 0
br i1 %69, label %80, label %70
70: ; preds = %67, %70
%71 = phi i64 [ %77, %70 ], [ %68, %67 ]
%72 = phi i64 [ %78, %70 ], [ 0, %67 ]
%73 = getelementptr inbounds double, double* %6, i64 %71
%74 = bitcast double* %73 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %74
%75 = getelementptr inbounds double, double* %73, i64 2
%76 = bitcast double* %75 to <2 x double>*
store <2 x double> <double 3.140000e+00, double 3.140000e+00>, <2 x double>* %76
%77 = add nuw i64 %71, 4
%78 = add i64 %72, 1
%79 = icmp eq i64 %78, %18
br i1 %79, label %80, label %70
80: ; preds = %70, %67
%81 = icmp eq i64 %14, %11
br i1 %81, label %92, label %82
82: ; preds = %10, %80
%83 = phi i64 [ 0, %10 ], [ %14, %80 ]
br label %87
84: ; preds = %3
%85 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.3, i64 0, i64 0))
%86 = tail call i32 @exit(i32 1)
unreachable
87: ; preds = %82, %87
%88 = phi i64 [ %90, %87 ], [ %83, %82 ]
%89 = getelementptr inbounds double, double* %6, i64 %88
store double 3.140000e+00, double* %89
%90 = add nuw nsw i64 %88, 1
%91 = icmp eq i64 %90, %11
br i1 %91, label %92, label %87
92: ; preds = %87, %80, %8
%93 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%94 = icmp eq i32* %93, null
br i1 %94, label %95, label %98
95: ; preds = %92
%96 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%97 = tail call i32 @exit(i32 1)
unreachable
98: ; preds = %92
%99 = tail call i32 @write_data_as_json(i32* %93, double* %0, double* %6, i32 %1)
%100 = tail call i32 @fclose(i32* %93)
%101 = tail call i32 @free(double* %6)
ret void
}