#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *f = fopen("exo1.f.out", "r");
  char c = 0;
  if (f == NULL) {
    printf("Could not open file\n");
    return 1;
  }
  do {
    c = fgetc(f);
    printf("%c, %i\n", c, c);
  } while (c != EOF);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118f <main+0x4f>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11dc <main+0x9c>
jmp    1194 <main+0x54>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
movsbl -0x11(%rbp),%edx
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x11(%rbp),%eax
mov    0x2e27(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1194 <main+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
lea    0xea6(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11aa <main+0x5a>
mov    %rax,%rbx
lea    0xe94(%rip),%r14
mov    0x2e68(%rip),%r15
mov    %rbx,%rdi
call   1060 <fgetc@plt>
movsbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    (%r15),%bpl
jne    1180 <main+0x30>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11bb <main+0x6b>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"exo1.f.out\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Could not open file\0A\00"
@.str.3 = [8 x i8] c"%c, %i\0A\00"
@EOF = global i8 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
store i8 0, i8* %3
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %27
9: ; preds = %0
br label %10
10: ; preds = %18, %9
%11 = load i32*, i32** %2
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %3
%13 = load i8, i8* %3
%14 = sext i8 %13 to i32
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %14, i32 %16)
br label %18
18: ; preds = %10
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = load i8, i8* @EOF
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %10, label %24
24: ; preds = %18
%25 = load i32*, i32** %2
%26 = call i32 @fclose(i32* %25)
store i32 0, i32* %1
br label %27
27: ; preds = %24, %7
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [11 x i8] c"exo1.f.out\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"%c, %i\0A\00"
@EOF = global i8 0
@str = [20 x i8] c"Could not open file\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %13
5: ; preds = %0, %5
%6 = tail call signext i8 @fgetc(i32* %1)
%7 = sext i8 %6 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %7, i32 %7)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %6, %9
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = tail call i32 @fclose(i32* %1)
br label %13
13: ; preds = %11, %3
%14 = phi i32 [ 1, %3 ], [ 0, %11 ]
ret i32 %14
}