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


x86 assembly (clang, -O0):
<output_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xe81(%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)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1204 <output_data+0x84>
lea    0xe1b(%rip),%rdi
call   1070 <report_error@plt>
movsd  0xdfc(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0xde7(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12c1 <output_data+0x141>
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
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <Cp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1080 <k@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <rho@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm3
lea    0xd8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    122c <output_data+0xac>
cmpq   $0x0,-0x28(%rbp)
je     12fa <output_data+0x17a>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12f5 <output_data+0x175>
lea    0xd62(%rip),%rdi
call   1070 <report_error@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12fa <output_data+0x17a>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_data>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11af <output_data+0x2f>
lea    0xe80(%rip),%rdi
call   1070 <report_error@plt>
movsd  0xe49(%rip),%xmm0
mov    $0x64,%ebp
lea    0xe88(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm0,0x18(%rsp)
mulsd  0xe2a(%rip),%xmm0
divsd  0xe2a(%rip),%xmm0
addsd  0xe2a(%rip),%xmm0
movsd  %xmm0,(%rsp)
call   1030 <Cp@plt>
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1080 <k@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1060 <rho@plt>
movaps %xmm0,%xmm3
mov    %rbx,%rdi
mov    %r14,%rsi
movsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
call   1050 <fprintf@plt>
movsd  0x18(%rsp),%xmm0
addsd  0xdbb(%rip),%xmm0
add    $0xffffffff,%ebp
jne    11d0 <output_data+0x50>
test   %rbx,%rbx
je     125c <output_data+0xdc>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
jne    1267 <output_data+0xe7>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdea(%rip),%rdi
call   1070 <report_error@plt>
mov    $0x1,%edi
call   10a0 <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 = [13 x i8] c"%f,%f,%f,%f\0A\00"
@.str.4 = [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
%9 = alloca double
%10 = 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 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 @report_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
store double 3.000000e+02, double* %1
store double 4.800000e+02, double* %2
store i32 100, i32* %3
store i32 1, i32* %4
br label %18
18: ; preds = %46, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load double, double* %1
%24 = load double, double* %2
%25 = load double, double* %1
%26 = fsub double %24, %25
%27 = load i32, i32* %4
%28 = sitofp i32 %27 to double
%29 = fmul double %26, %28
%30 = load i32, i32* %3
%31 = sitofp i32 %30 to double
%32 = fdiv double %29, %31
%33 = fadd double %23, %32
store double %33, double* %7
%34 = load double, double* %7
%35 = call double @Cp(double %34)
store double %35, double* %8
%36 = load double, double* %7
%37 = call double @k(double %36)
store double %37, double* %9
%38 = load double, double* %7
%39 = call double @rho(double %38)
store double %39, double* %10
%40 = load i32*, i32** %6
%41 = load double, double* %7
%42 = load double, double* %8
%43 = load double, double* %9
%44 = load double, double* %10
%45 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %41, double %42, double %43, double %44)
br label %46
46: ; preds = %22
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 1
store i32 %48, i32* %4
br label %18
49: ; preds = %18
%50 = load i32*, i32** %6
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %60
52: ; preds = %49
%53 = load i32*, i32** %6
%54 = call i64 @fclose(i32* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %52
%57 = call i32 @report_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %52
br label %60
60: ; preds = %59, %49
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 = [13 x i8] c"%f,%f,%f,%f\0A\00"
@.str.4 = [22 x i8] c"Failed to close file.\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
br label %6
6: ; preds = %5, %6
%7 = phi i32 [ %16, %6 ], [ 1, %5 ]
%8 = sitofp i32 %7 to double
%9 = fmul double %8, 1.800000e+02
%10 = fdiv double %9, 1.000000e+02
%11 = fadd double %10, 3.000000e+02
%12 = tail call double @Cp(double %11)
%13 = tail call double @k(double %11)
%14 = tail call double @rho(double %11)
%15 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), double %11, double %12, double %13, double %14)
%16 = add nuw nsw i32 %7, 1
%17 = icmp eq i32 %16, 101
br i1 %17, label %18, label %6
18: ; preds = %6
br i1 %2, label %25, label %19
19: ; preds = %18
%20 = tail call i64 @fclose(i32* %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @report_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19, %18
ret i32 0
}