#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
void readFile(FILE *reader) {
  int accessFile;
  reader = fopen("studentDetails.txt", "r");
  if (reader == NULL) {
    printf("Cannot open file for reading\n");
    exit(1);
  }
  do {
    accessFile = getc(reader);
    putchar(accessFile);
  } while (accessFile != EOF);
  fclose(reader);
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a4 <readFile+0x44>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    11a9 <readFile+0x49>
mov    -0x8(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%eax
jne    11a9 <readFile+0x49>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b2 <readFile+0x52>
mov    %rax,%rbx
mov    0x2e62(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <getc@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <putchar@plt>
cmp    (%r14),%ebp
jne    1190 <readFile+0x30>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <fclose@plt>
lea    0xe5c(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"studentDetails.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [30 x i8] c"Cannot open file for reading\0A\00"
@EOF = global i32 0
define void @readFile(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
br label %11
11: ; preds = %16, %10
%12 = load i32*, i32** %2
%13 = call i32 @getc(i32* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @putchar(i32 %14)
br label %16
16: ; preds = %11
%17 = load i32, i32* %3
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %11, label %20
20: ; preds = %16
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"studentDetails.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [29 x i8] c"Cannot open file for reading\00"
define void @readFile(i32* nocapture readnone %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1, %7
%8 = tail call i32 @getc(i32* %2)
%9 = tail call i32 @putchar(i32 %8)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %8, %10
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = tail call i32 @fclose(i32* %2)
ret void
}