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


x86 assembly (clang, -O0):
<printFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1164 <printFile+0x24>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
nopl   (%rax)
movsbl %bl,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1160 <printFile+0x20>
lea    0xe93(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"---- FILE CONTENTS ----\0A\00"
@.str.1 = [27 x i8] c"\0A-----------------------\0A\0A\00"
define void @printFile(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%5 = load i32*, i32** %2
%6 = call signext i8 @fgetc(i32* %5)
store i8 %6, i8* %3
br label %7
7: ; preds = %12, %1
%8 = load i8, i8* %3
%9 = call i32 @putchar(i8 signext %8)
%10 = load i32*, i32** %2
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %3
br label %12
12: ; preds = %7
%13 = load i32*, i32** %2
%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 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
ret void
}

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