#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
void print_file(const char *filename) {
  FILE *f;
  char buf[1024];
  int s;
  f = fopen(filename, "r");
  if (!f) {
    fprintf(stderr, "Warning: Failed to open '%s' for reading!\n", filename);
    return;
  }
  s = fread(buf, sizeof(char), sizeof(buf), f);
  fclose(f);
  if (s >= sizeof(buf)) {
    fprintf(stderr, "Warning: Size of '%s' is too big?!\n", filename);
  } else {
    buf[s] = '\0';
    printf("\t'%s'\n", buf);
  }
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119c <print_file+0x4c>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1218 <print_file+0xc8>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x414(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movslq -0x414(%rbp),%rax
cmp    $0x400,%rax
jb     11f6 <print_file+0xa6>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1218 <print_file+0xc8>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
lea    0xe9b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ab <print_file+0x5b>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    $0x400,%ebp
jb     11ce <print_file+0x7e>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
jmp    11bb <print_file+0x6b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
mov    %r14,%rdx
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <fprintf@plt>
mov    %ebp,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe76(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Warning: Failed to open '%s' for reading!\0A\00"
@.str.2 = [36 x i8] c"Warning: Size of '%s' is too big?!\0A\00"
@.str.3 = [7 x i8] c"\09'%s'\0A\00"
define void @print_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %33
14: ; preds = %1
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i32 @fread(i8* %15, i32 1, i32 1024, i32* %16)
store i32 %17, i32* %5
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = icmp uge i64 %21, 1024
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %2
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %33
27: ; preds = %14
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%32 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %10, %27, %23
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [43 x i8] c"Warning: Failed to open '%s' for reading!\0A\00"
@.str.2 = [36 x i8] c"Warning: Size of '%s' is too big?!\0A\00"
@.str.3 = [7 x i8] c"\09'%s'\0A\00"
define void @print_file(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
9: ; preds = %1
%10 = call i32 @fread(i8* %3, i32 1, i32 1024, i32* %4)
%11 = tail call i32 @fclose(i32* %4)
%12 = icmp ugt i32 %10, 1023
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %20
16: ; preds = %9
%17 = zext i32 %10 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %20
20: ; preds = %13, %16, %6
ret void
}