#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 EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int feof(int /*<<< orphan*/ *);
int ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  int c;
  int eof, err;
  fp = fopen("data.in", "r+");
  assert(fp);
  while ((c = getc(fp)) != EOF) {
    printf("%x ", c);
  }
  eof = feof(fp);
  if (eof)
    printf("eof\n");
  err = ferror(fp);
  if (err)
    printf("file error\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%eax
je     11d0 <main+0x60>
mov    -0x14(%rbp),%esi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    119f <main+0x2f>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11f4 <main+0x84>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1218 <main+0xa8>
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%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
lea    0xe74(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <assert@plt>
mov    %rbx,%rdi
call   10a0 <getc@plt>
mov    0x2e36(%rip),%r15
cmp    (%r15),%eax
je     11d9 <main+0x59>
lea    0xe4d(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   10a0 <getc@plt>
cmp    (%r15),%eax
jne    11c0 <main+0x40>
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     11f1 <main+0x71>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %eax,%eax
je     1209 <main+0x89>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"data.in\00"
@.str.1 = [3 x i8] c"r+\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"%x \00"
@.str.3 = [5 x i8] c"eof\0A\00"
@.str.4 = [12 x i8] c"file error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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** %2
%7 = load i32*, i32** %2
%8 = call i32 @assert(i32* %7)
br label %9
9: ; preds = %14, %0
%10 = load i32*, i32** %2
%11 = call i32 @getc(i32* %10)
store i32 %11, i32* %3
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %9
17: ; preds = %9
%18 = load i32*, i32** %2
%19 = call i32 @feof(i32* %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %17
%25 = load i32*, i32** %2
%26 = call i32 @ferror(i32* %25)
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"data.in\00"
@.str.1 = [3 x i8] c"r+\00"
@EOF = global i32 0
@.str.2 = [4 x i8] c"%x \00"
@str = [11 x i8] c"file error\00"
@str.5 = [4 x i8] c"eof\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @assert(i32* %1)
%3 = tail call i32 @getc(i32* %1)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %12, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %9, %6 ], [ %3, %0 ]
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @getc(i32* %1)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %6
12: ; preds = %6, %0
%13 = tail call i32 @feof(i32* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.5, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = tail call i32 @ferror(i32* %1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = tail call i32 @fclose(i32* %1)
ret i32 0
}