#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *readContentFromFile(const char *filePath) {
  FILE *inputFile = fopen(filePath, "r");
  if (!inputFile) {
    perror("File opening failed");
    return NULL;
  }
  fseek(inputFile, 0L, SEEK_END);
  long fileSize = ftell(inputFile);
  rewind(inputFile);
  char *output = malloc(sizeof(char) * fileSize);
  long i = 0;
  fgets(output, sizeof(char) * fileSize, inputFile);
  fclose(inputFile);
  return output;
}


x86 assembly (clang, -O0):
<readContentFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c4 <readContentFromFile+0x44>
lea    0xe50(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1233 <readContentFromFile+0xb3>
mov    -0x18(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readContentFromFile>:
push   %r15
push   %r14
push   %rbx
lea    0xe74(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e9 <readContentFromFile+0x69>
mov    %rax,%rbx
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <rewind@plt>
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe12(%rip),%rdi
call   10a0 <perror@plt>
xor    %r14d,%r14d
jmp    11e0 <readContentFromFile+0x60>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"File opening failed\00"
@SEEK_END = global i32 0
define i8* @readContentFromFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %35
14: ; preds = %1
%15 = load i32*, i32** %4
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
%18 = load i32*, i32** %4
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %5
%20 = load i32*, i32** %4
%21 = call i32 @rewind(i32* %20)
%22 = load i64, i64* %5
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %6
store i64 0, i64* %7
%26 = load i8*, i8** %6
%27 = load i64, i64* %5
%28 = mul i64 1, %27
%29 = trunc i64 %28 to i32
%30 = load i32*, i32** %4
%31 = call i32 @fgets(i8* %26, i32 %29, i32* %30)
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
%34 = load i8*, i8** %6
store i8* %34, i8** %2
br label %35
35: ; preds = %14, %12
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"File opening failed\00"
@SEEK_END = global i32 0
define i8* @readContentFromFile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %15
6: ; preds = %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %2, i64 0, i32 %7)
%9 = tail call i64 @ftell(i32* %2)
%10 = tail call i32 @rewind(i32* %2)
%11 = trunc i64 %9 to i32
%12 = tail call i8* @malloc(i32 %11)
%13 = tail call i32 @fgets(i8* %12, i32 %11, i32* %2)
%14 = tail call i32 @fclose(i32* %2)
br label %15
15: ; preds = %6, %4
%16 = phi i8* [ %12, %6 ], [ null, %4 ]
ret i8* %16
}