#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putchar(int);
bool print_file_contents(char *filename) {
  FILE *file = fopen(filename, "r");
  if (file == NULL) {
    return false;
  }
  int current_char = EOF;
  while ((current_char = fgetc(file)) != EOF) {
    putchar(current_char);
  }
  return true;
}


x86 assembly (clang, -O0):
<print_file_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1167 <print_file_contents+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11a2 <print_file_contents+0x72>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
je     119b <print_file_contents+0x6b>
mov    -0x1c(%rbp),%edi
call   1030 <putchar@plt>
jmp    1173 <print_file_contents+0x43>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file_contents>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1186 <print_file_contents+0x56>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e91(%rip),%rbp
mov    $0x1,%r14d
cmp    0x0(%rbp),%eax
je     1189 <print_file_contents+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1170 <print_file_contents+0x40>
jmp    1189 <print_file_contents+0x59>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @print_file_contents(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %22
11: ; preds = %1
%12 = load i32, i32* @EOF
store i32 %12, i32* %5
br label %13
13: ; preds = %18, %11
%14 = load i32*, i32** %4
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %5
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %5
%20 = call i32 @putchar(i32 %19)
br label %13
21: ; preds = %13
store i32 1, i32* %2
br label %22
22: ; preds = %21, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @print_file_contents(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call i32 @fgetc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %14, label %8
8: ; preds = %4, %8
%9 = phi i32 [ %11, %8 ], [ %5, %4 ]
%10 = tail call i32 @putchar(i32 %9)
%11 = tail call i32 @fgetc(i32* %2)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %8
14: ; preds = %8, %4, %1
%15 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 1, %8 ]
ret i32 %15
}