#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 */
scalar_t__ EOF;
int /*<<< orphan*/ errhandler(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int write_to_file(const char *filename, double output_val) {
  FILE *input = NULL;
  input = fopen(filename, "a+");
  if (input == 0) {
    char szBuff[80];
    sprintf(szBuff, "Can not append or create file %s", filename);
    errhandler(
        518,
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/"
        "refs/heads/master/project/ns_sim_serial/helper.c",
        szBuff);
  }
  if (fgetc(input) != EOF) {
    fprintf(input, " %f", output_val);
  } else {
    fprintf(input, "%f", output_val);
  }
  fclose(input);
  return 1;
}


x86 assembly (clang, -O0):
<write_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c1 <write_to_file+0x61>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe5c(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x70(%rbp),%rdx
mov    $0x206,%edi
lea    0xe68(%rip),%rsi
call   1030 <errhandler@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%rax
je     11f4 <write_to_file+0x94>
mov    -0x18(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xeed(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1209 <write_to_file+0xa9>
mov    -0x18(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
lea    0xed4(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%r14
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b1 <write_to_file+0x51>
lea    0xe76(%rip),%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
lea    0xe80(%rip),%rsi
mov    $0x206,%edi
mov    %r15,%rdx
call   1030 <errhandler@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
lea    0xf0e(%rip),%rax
lea    0xf06(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
movsd  0x8(%rsp),%xmm0
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"a+\00"
@.str.1 = [33 x i8] c"Can not append or create file %s\00"
@.str.2 = [179 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/refs/heads/master/project/ns_sim_serial/helper.c\00"
@EOF = global i64 0
@.str.3 = [4 x i8] c" %f\00"
@.str.4 = [3 x i8] c"%f\00"
define i32 @write_to_file(i8* %0, double %1) {
%3 = alloca i8*
%4 = alloca double
%5 = alloca i32*
%6 = alloca [80 x i8]
store i8* %0, i8** %3
store double %1, double* %4
store i32* null, i32** %5
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%16 = call i32 @errhandler(i32 518, i8* getelementptr inbounds ([179 x i8], [179 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %11, %2
%18 = load i32*, i32** %5
%19 = call i64 @fgetc(i32* %18)
%20 = load i64, i64* @EOF
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32*, i32** %5
%24 = load double, double* %4
%25 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), double %24)
br label %30
26: ; preds = %17
%27 = load i32*, i32** %5
%28 = load double, double* %4
%29 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), double %28)
br label %30
30: ; preds = %26, %22
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
ret i32 1
}

LLVM IR (-O2):
@.str = [3 x i8] c"a+\00"
@.str.1 = [33 x i8] c"Can not append or create file %s\00"
@.str.2 = [179 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/grantathon/computational_fluid_dynamics/refs/heads/master/project/ns_sim_serial/helper.c\00"
@EOF = global i64 0
@.str.3 = [4 x i8] c" %f\00"
@.str.4 = [3 x i8] c"%f\00"
define i32 @write_to_file(i8* %0, double %1) {
%3 = alloca [80 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = call i32 @errhandler(i32 518, i8* getelementptr inbounds ([179 x i8], [179 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %10
10: ; preds = %6, %2
%11 = call i64 @fgetc(i32* %4)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
%14 = select i1 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0)
%15 = call i32 @fprintf(i32* %4, i8* %14, double %1)
%16 = call i32 @fclose(i32* %4)
ret i32 1
}