#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
void printFile() {
  FILE *f;
  char c;
  f = fopen("car.txt", "r");
  printf("---- FILE CONTENTS ----\n");
  c = fgetc(f);
  do {
    putchar(c);
    c = fgetc(f);
  } while (!feof(f));
  fclose(f);
  printf("\n-----------------------\n\n");
}


x86 assembly (clang, -O0):
<printFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xe84(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1197 <printFile+0x37>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe4e(%rip),%rdi
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFile>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebx
movsbl %bl,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1190 <printFile+0x30>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    0xe65(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"car.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"---- FILE CONTENTS ----\0A\00"
@.str.3 = [27 x i8] c"\0A-----------------------\0A\0A\00"
define void @printFile() {
%1 = alloca i32*
%2 = alloca i8
%3 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%5 = load i32*, i32** %1
%6 = call signext i8 @fgetc(i32* %5)
store i8 %6, i8* %2
br label %7
7: ; preds = %12, %0
%8 = load i8, i8* %2
%9 = call i32 @putchar(i8 signext %8)
%10 = load i32*, i32** %1
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %2
br label %12
12: ; preds = %7
%13 = load i32*, i32** %1
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %7, label %17
17: ; preds = %12
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"car.txt\00"
@.str.1 = [2 x i8] c"r\00"
@str = [24 x i8] c"---- FILE CONTENTS ----\00"
@str.4 = [26 x i8] c"\0A-----------------------\0A\00"
define void @printFile() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%3 = tail call signext i8 @fgetc(i32* %1)
br label %4
4: ; preds = %4, %0
%5 = phi i8 [ %3, %0 ], [ %7, %4 ]
%6 = tail call i32 @putchar(i8 signext %5)
%7 = tail call signext i8 @fgetc(i32* %1)
%8 = tail call i32 @feof(i32* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %4, label %10
10: ; preds = %4
%11 = tail call i32 @fclose(i32* %1)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
ret void
}