#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, char const *);
void read_file(const char file_name[]) {
  char line[60];
  int line_count = 0;
  FILE *handle = fopen(file_name, "r");
  if (handle != NULL) {
    while (fgets(line, 60, handle) != NULL) {
      line_count++;
    }
    fclose(handle);
  } else {
    printf("Error in read_file(): File '%s' cannot be opened.\n", file_name);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     11bf <read_file+0x6f>
jmp    1187 <read_file+0x37>
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    $0x3c,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11b1 <read_file+0x61>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1187 <read_file+0x37>
mov    -0x60(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11dd <read_file+0x8d>
mov    -0x8(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a5 <read_file+0x55>
mov    %rax,%rbx
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x3c,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1180 <read_file+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe56(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [51 x i8] c"Error in read_file(): File '%s' cannot be opened.\0A\00"
@EXIT_FAILURE = global i32 0
define void @read_file(i8* %0) {
%2 = alloca i8*
%3 = alloca [60 x i8]
%4 = alloca i32
%5 = alloca i32*
store i8* %0, i8** %2
store i32 0, i32* %4
%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** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %22
10: ; preds = %1
br label %11
11: ; preds = %16, %10
%12 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%13 = load i32*, i32** %5
%14 = call i32* @fgets(i8* %12, i32 60, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %11
19: ; preds = %11
%20 = load i32*, i32** %5
%21 = call i32 @fclose(i32* %20)
br label %27
22: ; preds = %1
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %19
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [51 x i8] c"Error in read_file(): File '%s' cannot be opened.\0A\00"
@EXIT_FAILURE = global i32 0
define void @read_file(i8* %0) {
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [60 x i8], [60 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 %11, label %6
6: ; preds = %1, %6
%7 = call i32* @fgets(i8* %3, i32 60, i32* %4)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %6
9: ; preds = %6
%10 = call i32 @fclose(i32* %4)
ret void
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
}