#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 /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ stderr;
void export(float averagecost, float bestcost) {
  FILE *fp;
  FILE *fp2;
  if ((fp = fopen("bestdata.txt", "a")) == NULL) {
    fprintf(stderr, "Error opening file data .txt");
    exit(0);
  } else {
    fprintf(fp, " %lf \n", bestcost);
  }
  fclose(fp);
  if ((fp2 = fopen("averagedata.txt", "a")) == NULL) {
    fprintf(stderr, "Error opening file data .txt");
    getchar();
  } else {
    fprintf(fp2, " %lf \n", averagecost);
  }
  fclose(fp2);
}


x86 assembly (clang, -O0):
<export>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a2 <export+0x52>
mov    0x2e56(%rip),%rax
movslq (%rax),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rdi
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe76(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe66(%rip),%rdi
lea    0xe39(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    120b <export+0xbb>
mov    0x2df2(%rip),%rax
movslq (%rax),%rdi
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
jmp    1226 <export+0xd6>
mov    -0x18(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe0d(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export>:
push   %rbx
sub    $0x10,%rsp
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
lea    0xe88(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121f <export+0xbf>
mov    %rax,%rbx
movss  0xc(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe8b(%rip),%rsi
mov    %rax,%rdi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe79(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11eb <export+0x8b>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe4d(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%al
call   1050 <fprintf@plt>
jmp    1212 <export+0xb2>
mov    0x2dee(%rip),%rax
movslq (%rax),%rcx
lea    0xe13(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <fclose@plt>
mov    0x2dba(%rip),%rax
movslq (%rax),%rcx
lea    0xddf(%rip),%rdi
mov    $0x1c,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"bestdata.txt\00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Error opening file data .txt\00"
@.str.3 = [7 x i8] c" %lf \0A\00"
@.str.4 = [16 x i8] c"averagedata.txt\00"
define void @export(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca i32*
%6 = alloca i32*
store float %0, float* %3
store float %1, float* %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = load float, float* %4
%18 = fpext float %17 to double
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %18)
br label %20
20: ; preds = %15
%21 = load i32*, i32** %5
%22 = call i32 @fclose(i32* %21)
%23 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i32*
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 (...) @getchar()
br label %36
31: ; preds = %20
%32 = load i32*, i32** %6
%33 = load float, float* %3
%34 = fpext float %33 to double
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %34)
br label %36
36: ; preds = %31, %25
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"bestdata.txt\00"
@.str.1 = [2 x i8] c"a\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Error opening file data .txt\00"
@.str.3 = [7 x i8] c" %lf \0A\00"
@.str.4 = [16 x i8] c"averagedata.txt\00"
define void @export(float %0, float %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i32*
%9 = tail call i64 @fwrite(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 28, i64 1, i32* %8)
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %2
%12 = fpext float %1 to double
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %12)
%14 = tail call i32 @fclose(i32* %3)
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i64 28, i64 1, i32* %20)
%22 = tail call i32 (...) @getchar()
br label %26
23: ; preds = %11
%24 = fpext float %0 to double
%25 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %24)
br label %26
26: ; preds = %23, %17
%27 = tail call i32 @fclose(i32* %15)
ret void
}