#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 const *, char *);
int /*<<< orphan*/ printf(char *, ...);
void print_file(const char *filename) {
  char c;
  FILE *file;
  file = fopen(filename, "r");
  printf("%s:\n", filename);
  while ((c = fgetc(file)) != EOF) {
    printf("%c", c);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<print_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2e60(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11aa <print_file+0x6a>
movsbl -0x9(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1172 <print_file+0x32>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e62(%rip),%r14
cmp    (%r14),%al
je     11a5 <print_file+0x55>
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
jne    1190 <print_file+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [5 x i8] c"%s:\0A\00"
@EOF = global i8 0
@.str.2 = [3 x i8] c"%c\00"
define void @print_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %4
%7 = load i8*, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %16, %1
%10 = load i32*, i32** %4
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, 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 %16, label %20
16: ; preds = %9
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %9
20: ; preds = %9
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
ret void
}

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