#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 /*<<< orphan*/ EXIT_FAILURE;
int count_lines_in_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int *read_in_file(const char *filename) {
  if (filename == NULL) {
    exit(EXIT_FAILURE);
  } else {
    FILE *file = fopen(filename, "r");
    if (file == 0) {
      fprintf(stderr,
              "Could not open file \"%s\". Make sure the file exists.\n",
              filename);
    } else {
      int count = count_lines_in_file(file);
      int current_char;
      while ((current_char = fgetc(file)) != EOF) {
        printf("%c", current_char);
      }
      printf("Processed %i lines.\n", count);
      fclose(file);
    }
  }
}


x86 assembly (clang, -O0):
<read_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1195 <read_in_file+0x25>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d2 <read_in_file+0x62>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1225 <read_in_file+0xb5>
mov    -0x18(%rbp),%rdi
call   1070 <count_lines_in_file@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%eax
je     120d <read_in_file+0x9d>
mov    -0x20(%rbp),%esi
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
jmp    11de <read_in_file+0x6e>
mov    -0x1c(%rbp),%esi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    122a <read_in_file+0xba>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_in_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1213 <read_in_file+0xa3>
mov    %rdi,%rbp
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f0 <read_in_file+0x80>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <count_lines_in_file@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e37(%rip),%r15
cmp    (%r15),%eax
je     11d7 <read_in_file+0x67>
lea    0xe7b(%rip),%rbp
nopl   (%rax)
mov    %rbp,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    11c0 <read_in_file+0x50>
lea    0xe5d(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1208 <read_in_file+0x98>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [54 x i8] c"Could not open file \22%s\22. Make sure the file exists.\0A\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [21 x i8] c"Processed %i lines.\0A\00"
define i32* @read_in_file(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %37
21: ; preds = %12
%22 = load i32*, i32** %4
%23 = call i32 @count_lines_in_file(i32* %22)
store i32 %23, i32* %5
br label %24
24: ; preds = %29, %21
%25 = load i32*, i32** %4
%26 = call i32 @fgetc(i32* %25)
store i32 %26, i32* %6
%27 = load i32, i32* @EOF
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %6
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %24
32: ; preds = %24
%33 = load i32, i32* %5
%34 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %32, %17
br label %38
38: ; preds = %37
%39 = load i32*, i32** %2
ret i32* %39
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [54 x i8] c"Could not open file \22%s\22. Make sure the file exists.\0A\00"
@EOF = global i32 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [21 x i8] c"Processed %i lines.\0A\00"
define noalias i32* @read_in_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 @exit(i32 %4)
unreachable
6: ; preds = %1
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %26
12: ; preds = %6
%13 = tail call i32 @count_lines_in_file(i32* %7)
%14 = tail call i32 @fgetc(i32* %7)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %23, label %17
17: ; preds = %12, %17
%18 = phi i32 [ %20, %17 ], [ %14, %12 ]
%19 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = tail call i32 @fgetc(i32* %7)
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %17
23: ; preds = %17, %12
%24 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%25 = tail call i32 @fclose(i32* %7)
br label %26
26: ; preds = %23, %9
ret i32* undef
}