#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);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double);
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
int /*<<< orphan*/ report_error(char *);
int output_data() {
  double min, max;
  int points, i;
  const char *file = "out.csv";
  FILE *fp;
  double *x, *y;
  min = 0;
  max = 0;
  points = 0;
  i = 0;
  fp = NULL;
  x = NULL;
  y = NULL;
  fp = fopen(file, "w");
  if (!fp) {
    report_error("Failed to open file for writing.");
  }
  min = 300;
  max = 480;
  points = 100;
  x = (double *)malloc(sizeof(double) * points);
  y = (double *)malloc(sizeof(double) * points);
  if (x == NULL) {
    report_error("Cannot allocate memory for x");
    exit(1);
  }
  if (y == NULL) {
    report_error("Cannot allocate memory for y");
    exit(1);
  }
  if (x || y == NULL) {
    report_error("Failed to allocate memory.");
    exit(1);
  }
  for (i = 1; i <= points; i++) {
    x[i] = min + (max - min) * i / points;
    fprintf(fp, "%f,%f\n", x[i], y[i]);
  }
  if (fp) {
    if (fclose(fp) != 0) {
      report_error("Failed to close file.");
      exit(1);
    }
  }
  free(x);
  free(y);
  return 0;
}


x86 assembly (clang, -O0):
<output_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e4 <output_data+0x74>
lea    0xe3b(%rip),%rdi
call   1070 <report_error@plt>
movsd  0xe1c(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xe07(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    124c <output_data+0xdc>
lea    0xdfe(%rip),%rdi
call   1070 <report_error@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
jne    126d <output_data+0xfd>
lea    0xdfa(%rip),%rdi
call   1070 <report_error@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1283 <output_data+0x113>
cmpq   $0x0,-0x38(%rbp)
jne    1299 <output_data+0x129>
lea    0xdeb(%rip),%rdi
call   1070 <report_error@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     1316 <output_data+0x1a6>
movsd  -0x8(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x18(%rbp),%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x14(%rbp),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
lea    0xd8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12a0 <output_data+0x130>
cmpq   $0x0,-0x28(%rbp)
je     134f <output_data+0x1df>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     134a <output_data+0x1da>
lea    0xd5c(%rip),%rdi
call   1070 <report_error@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    134f <output_data+0x1df>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_data>:
push   %rbx
lea    0xeb8(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    1165 <output_data+0x25>
lea    0xeaa(%rip),%rdi
call   1040 <report_error@plt>
mov    $0x320,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    $0x320,%edi
call   1030 <malloc@plt>
test   %rbx,%rbx
jne    118a <output_data+0x4a>
lea    0xea3(%rip),%rdi
jmp    119f <output_data+0x5f>
test   %rax,%rax
jne    1198 <output_data+0x58>
lea    0xeb2(%rip),%rdi
jmp    119f <output_data+0x5f>
lea    0xec6(%rip),%rdi
call   1040 <report_error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"out.csv\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [33 x i8] c"Failed to open file for writing.\00"
@.str.3 = [29 x i8] c"Cannot allocate memory for x\00"
@.str.4 = [29 x i8] c"Cannot allocate memory for y\00"
@.str.5 = [27 x i8] c"Failed to allocate memory.\00"
@.str.6 = [7 x i8] c"%f,%f\0A\00"
@.str.7 = [22 x i8] c"Failed to close file.\00"
define i32 @output_data() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca double*
%8 = alloca double*
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %5
store double 0.000000e+00, double* %1
store double 0.000000e+00, double* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32* null, i32** %6
store double* null, double** %7
store double* null, double** %8
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @report_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
store double 3.000000e+02, double* %1
store double 4.800000e+02, double* %2
store i32 100, i32* %3
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = mul i64 8, %17
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double*
store double* %21, double** %7
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = mul i64 8, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to double*
store double* %27, double** %8
%28 = load double*, double** %7
%29 = icmp eq double* %28, null
br i1 %29, label %30, label %33
30: ; preds = %15
%31 = call i32 @report_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %15
%34 = load double*, double** %8
%35 = icmp eq double* %34, null
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @report_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %33
%40 = load double*, double** %7
%41 = icmp ne double* %40, null
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load double*, double** %8
%44 = icmp eq double* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42, %39
%46 = call i32 @report_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
store i32 1, i32* %4
br label %49
49: ; preds = %81, %48
%50 = load i32, i32* %4
%51 = load i32, i32* %3
%52 = icmp sle i32 %50, %51
br i1 %52, label %53, label %84
53: ; preds = %49
%54 = load double, double* %1
%55 = load double, double* %2
%56 = load double, double* %1
%57 = fsub double %55, %56
%58 = load i32, i32* %4
%59 = sitofp i32 %58 to double
%60 = fmul double %57, %59
%61 = load i32, i32* %3
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
%64 = fadd double %54, %63
%65 = load double*, double** %7
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
store double %64, double* %68
%69 = load i32*, i32** %6
%70 = load double*, double** %7
%71 = load i32, i32* %4
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load double*, double** %8
%76 = load i32, i32* %4
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double, double* %75, i64 %77
%79 = load double, double* %78
%80 = call i32 @fprintf(i32* %69, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), double %74, double %79)
br label %81
81: ; preds = %53
%82 = load i32, i32* %4
%83 = add nsw i32 %82, 1
store i32 %83, i32* %4
br label %49
84: ; preds = %49
%85 = load i32*, i32** %6
%86 = icmp ne i32* %85, null
br i1 %86, label %87, label %95
87: ; preds = %84
%88 = load i32*, i32** %6
%89 = call i64 @fclose(i32* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = call i32 @report_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %87
br label %95
95: ; preds = %94, %84
%96 = load double*, double** %7
%97 = call i32 @free(double* %96)
%98 = load double*, double** %8
%99 = call i32 @free(double* %98)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"out.csv\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [33 x i8] c"Failed to open file for writing.\00"
@.str.3 = [29 x i8] c"Cannot allocate memory for x\00"
@.str.4 = [29 x i8] c"Cannot allocate memory for y\00"
@.str.5 = [27 x i8] c"Failed to allocate memory.\00"
define i32 @output_data() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @report_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %5
5: ; preds = %3, %0
%6 = tail call i64 @malloc(i32 800)
%7 = tail call i64 @malloc(i32 800)
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = tail call i32 @report_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %5
%13 = icmp eq i64 %7, 0
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = tail call i32 @report_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %12
%18 = tail call i32 @report_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
}