#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 *, char);
int main() {
  FILE *file = fopen("/home/transvaal/Documents/example.txt", "r");
  char c;
  do {
    c = fgetc(file);
    printf("%c", c);
  } while (c != EOF);
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
lea    0xeaf(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1040 <printf@plt>
movsbl -0x11(%rbp),%eax
mov    0x2e5b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1166 <main+0x26>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
lea    0xed1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xec4(%rip),%r14
mov    0x2e7d(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <fgetc@plt>
movsbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
cmp    (%r15),%bpl
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/home/transvaal/Documents/example.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%c\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 ([38 x i8], [38 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
br label %5
5: ; preds = %10, %0
%6 = load i32*, i32** %2
%7 = call signext i8 @fgetc(i32* %6)
store i8 %7, i8* %3
%8 = load i8, i8* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %8)
br label %10
10: ; preds = %5
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %5, label %16
16: ; preds = %10
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"/home/transvaal/Documents/example.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%c\00"
@EOF = global i8 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %2, %0
%3 = tail call signext i8 @fgetc(i32* %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %3)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %3, %5
br i1 %6, label %7, label %2
7: ; preds = %2
%8 = tail call i32 @fclose(i32* %1)
ret i32 0
}