#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*/ error_exit(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, float);
int main() {
  int i;
  float x = 2015;
  FILE *outfile;
  FILE *infile;
  outfile = fopen("testfile.dat", "a+");
  if (!outfile)
    error_exit("testfile.dat");
  for (i = 0; i < 4; i++, x++)
    fwrite(&x, 1, 4, outfile);
  fclose(outfile);
  infile = fopen("testfile.dat", "r");
  if (!infile)
    error_exit("testfile.dat");
  while (fread(&x, 1, 4, outfile))
    printf("%f\n", x);
  fclose(outfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movss  0xe89(%rip),%xmm0
movss  %xmm0,-0xc(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11aa <main+0x4a>
lea    0xe63(%rip),%rdi
call   1060 <error_exit@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11f2 <main+0x92>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1080 <fwrite@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movss  0xe21(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
jmp    11b1 <main+0x51>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe06(%rip),%rdi
lea    0xe0f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1229 <main+0xc9>
lea    0xde4(%rip),%rdi
call   1060 <error_exit@plt>
jmp    122e <main+0xce>
mov    -0x18(%rbp),%rcx
lea    -0xc(%rbp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
je     1265 <main+0x105>
movss  -0xc(%rbp),%xmm0
lea    0xdbf(%rip),%rdi
call   1050 <printf@plt>
jmp    122e <main+0xce>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x44fbe000,0xc(%rsp)
44
lea    0xe8c(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1198 <main+0x38>
lea    0xe71(%rip),%rdi
call   1060 <error_exit@plt>
lea    0xc(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
movss  0xc(%rsp),%xmm0
addss  0xe40(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
movss  0xc(%rsp),%xmm0
addss  0xe17(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
movss  0xc(%rsp),%xmm0
addss  0xdee(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1080 <fwrite@plt>
movss  0xdcb(%rip),%xmm0
addss  0xc(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xdb4(%rip),%rdi
lea    0xdbd(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    126d <main+0x10d>
lea    0xd9c(%rip),%rdi
call   1060 <error_exit@plt>
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     12c8 <main+0x168>
lea    0xd86(%rip),%r14
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movss  0xc(%rsp),%xmm0
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    12a0 <main+0x140>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"testfile.dat\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca float
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
store float 2.015000e+03, float* %3
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @error_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
store i32 0, i32* %2
br label %12
12: ; preds = %18, %11
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32*, i32** %4
%17 = call i32 @fwrite(float* %3, i32 1, i32 4, i32* %16)
br label %18
18: ; preds = %15
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
%21 = load float, float* %3
%22 = fadd float %21, 1.000000e+00
store float %22, float* %3
br label %12
23: ; preds = %12
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
%26 = 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.2, i64 0, i64 0))
store i32* %26, i32** %5
%27 = load i32*, i32** %5
%28 = icmp ne i32* %27, null
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = call i32 @error_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
br label %32
32: ; preds = %36, %31
%33 = load i32*, i32** %4
%34 = call i64 @fread(float* %3, i32 1, i32 4, i32* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load float, float* %3
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), float %37)
br label %32
39: ; preds = %32
%40 = load i32*, i32** %4
%41 = call i32 @fclose(i32* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"testfile.dat\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%f\0A\00"
define i32 @main() {
%1 = alloca float
%2 = bitcast float* %1 to i8*
store float 2.015000e+03, float* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @error_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32 @fwrite(float* %1, i32 1, i32 4, i32* %3)
%9 = load float, float* %1
%10 = fadd float %9, 1.000000e+00
store float %10, float* %1
%11 = call i32 @fwrite(float* %1, i32 1, i32 4, i32* %3)
%12 = load float, float* %1
%13 = fadd float %12, 1.000000e+00
store float %13, float* %1
%14 = call i32 @fwrite(float* %1, i32 1, i32 4, i32* %3)
%15 = load float, float* %1
%16 = fadd float %15, 1.000000e+00
store float %16, float* %1
%17 = call i32 @fwrite(float* %1, i32 1, i32 4, i32* %3)
%18 = load float, float* %1
%19 = fadd float %18, 1.000000e+00
store float %19, float* %1
%20 = tail call i32 @fclose(i32* %3)
%21 = 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.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %7
%24 = tail call i32 @error_exit(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %7
%26 = call i64 @fread(float* %1, i32 1, i32 4, i32* %3)
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25, %28
%29 = load float, float* %1
%30 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), float %29)
%31 = call i64 @fread(float* %1, i32 1, i32 4, i32* %3)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %28
33: ; preds = %28, %25
%34 = tail call i32 @fclose(i32* %3)
ret i32 0
}