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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int printFile(char *filename, char *buffer) {
  FILE *currentFile = fopen(filename, "r");
  if (!currentFile) {
    char buf[100];
    sprintf(buf, "File %s does not exist", filename);
    perror(buf);
    return 1;
  }
  while (NULL != fgets(buffer, sizeof(buffer), currentFile)) {
    printf("%s", buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<printFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b1 <printFile+0x61>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f2 <printFile+0xa2>
jmp    11b6 <printFile+0x66>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x8,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11eb <printFile+0x9b>
mov    -0x18(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
jmp    11b6 <printFile+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe99(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11ce <printFile+0x7e>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11c0 <printFile+0x70>
lea    0xe86(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11a0 <printFile+0x50>
mov    %r15d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2d(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <perror@plt>
mov    $0x1,%r15d
jmp    11c0 <printFile+0x70>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"File %s does not exist\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @printFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [100 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%17 = call i32 @perror(i8* %16)
store i32 1, i32* %3
br label %28
18: ; preds = %2
br label %19
19: ; preds = %24, %18
%20 = load i8*, i8** %5
%21 = load i32*, i32** %6
%22 = call i32* @fgets(i8* %20, i32 8, i32* %21)
%23 = icmp ne i32* null, %22
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %25)
br label %19
27: ; preds = %19
store i32 0, i32* %3
br label %28
28: ; preds = %27, %12
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"File %s does not exist\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @printFile(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%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 %9, label %6
6: ; preds = %2
%7 = tail call i32* @fgets(i8* %1, i32 8, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %17, label %13
9: ; preds = %2
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = call i32 @perror(i8* %10)
br label %17
13: ; preds = %6, %13
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%15 = tail call i32* @fgets(i8* %1, i32 8, i32* %4)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %13
17: ; preds = %13, %6, %9
%18 = phi i32 [ 1, %9 ], [ 0, %6 ], [ 0, %13 ]
ret i32 %18
}