#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
char *readFile(char *filePath) {
  FILE *myFile = fopen(filePath, "r");
  if (myFile) {
    fseek(myFile, 0L, SEEK_END);
    if (ftell(myFile) <= 1000000) {
      size_t size = ftell(myFile) + 1;
      fseek(myFile, size - 2, SEEK_SET);
      char finalChar = (char)fgetc(myFile);
      if (finalChar == '\n')
        size -= 1;
      fseek(myFile, 0L, 0);
      char *toReturn = (char *)malloc(size);
      fgets(toReturn, size, myFile);
      toReturn[size - 1] = '\0';
      fclose(myFile);
      return toReturn;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     126e <readFile+0xfe>
mov    -0x18(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
cmp    $0xf4240,%eax
jg     1269 <readFile+0xf9>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
sub    $0x2,%rsi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    1216 <readFile+0xa6>
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1276 <readFile+0x106>
jmp    126e <readFile+0xfe>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1229 <readFile+0xb9>
mov    %rax,%rbx
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
cmp    $0xf4240,%eax
jg     122c <readFile+0xbc>
mov    %rbx,%rdi
call   1060 <ftell@plt>
movslq %eax,%r14
lea    -0x1(%r14),%rsi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
mov    %r14,%r12
sub    %rcx,%r12
neg    %rcx
lea    (%r14,%rcx,1),%r15
add    $0x1,%r15
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <fgets@plt>
movb   $0x0,(%r14,%r12,1)
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    122c <readFile+0xbc>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8
%7 = alloca i8*
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 %12, label %56
12: ; preds = %1
%13 = load i32*, i32** %4
%14 = load i32, i32* @SEEK_END
%15 = call i32 @fseek(i32* %13, i64 0, i32 %14)
%16 = load i32*, i32** %4
%17 = call i32 @ftell(i32* %16)
%18 = icmp sle i32 %17, 1000000
br i1 %18, label %19, label %55
19: ; preds = %12
%20 = load i32*, i32** %4
%21 = call i32 @ftell(i32* %20)
%22 = add nsw i32 %21, 1
%23 = sext i32 %22 to i64
store i64 %23, i64* %5
%24 = load i32*, i32** %4
%25 = load i64, i64* %5
%26 = sub i64 %25, 2
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %24, i64 %26, i32 %27)
%29 = load i32*, i32** %4
%30 = call i64 @fgetc(i32* %29)
%31 = trunc i64 %30 to i8
store i8 %31, i8* %6
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %38
35: ; preds = %19
%36 = load i64, i64* %5
%37 = sub i64 %36, 1
store i64 %37, i64* %5
br label %38
38: ; preds = %35, %19
%39 = load i32*, i32** %4
%40 = call i32 @fseek(i32* %39, i64 0, i32 0)
%41 = load i64, i64* %5
%42 = call i64 @malloc(i64 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = load i64, i64* %5
%46 = load i32*, i32** %4
%47 = call i32 @fgets(i8* %44, i64 %45, i32* %46)
%48 = load i8*, i8** %7
%49 = load i64, i64* %5
%50 = sub i64 %49, 1
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = load i32*, i32** %4
%53 = call i32 @fclose(i32* %52)
%54 = load i8*, i8** %7
store i8* %54, i8** %2
br label %57
55: ; preds = %12
br label %56
56: ; preds = %55, %1
store i8* null, i8** %2
br label %57
57: ; preds = %56, %38
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @readFile(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 %28, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %2, i64 0, i32 %5)
%7 = tail call i32 @ftell(i32* %2)
%8 = icmp slt i32 %7, 1000001
br i1 %8, label %9, label %28
9: ; preds = %4
%10 = tail call i32 @ftell(i32* %2)
%11 = add nsw i32 %10, 1
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, -2
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %2, i64 %13, i32 %14)
%16 = tail call i64 @fgetc(i32* %2)
%17 = and i64 %16, 255
%18 = icmp eq i64 %17, 10
%19 = sext i1 %18 to i64
%20 = add nsw i64 %19, %12
%21 = tail call i32 @fseek(i32* %2, i64 0, i32 0)
%22 = tail call i64 @malloc(i64 %20)
%23 = inttoptr i64 %22 to i8*
%24 = tail call i32 @fgets(i8* %23, i64 %20, i32* %2)
%25 = add nsw i64 %20, -1
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = tail call i32 @fclose(i32* %2)
br label %28
28: ; preds = %1, %4, %9
%29 = phi i8* [ %23, %9 ], [ null, %4 ], [ null, %1 ]
ret i8* %29
}