#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*/ GLlog(char *, long);
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
long getFileContent(char *buffer, long len, const char *filePath) {
  FILE *file = fopen(filePath, "rb");
  if (file == NULL) {
    return -1;
  }
  fseek(file, 0, SEEK_END);
  long size = ftell(file);
  rewind(file);
  if (len < size) {
    GLlog("file is large than the size(%ld) you give\n", len);
    return -1;
  }
  fread(buffer, 1, size, file);
  buffer[size] = '\0';
  fclose(file);
  return size;
}


x86 assembly (clang, -O0):
<getFileContent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b0 <getFileContent+0x40>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1238 <getFileContent+0xc8>
mov    -0x28(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1205 <getFileContent+0x95>
mov    -0x18(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1080 <GLlog@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1238 <getFileContent+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileContent>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
lea    0xe7a(%rip),%rsi
mov    %rdx,%rdi
call   1090 <fopen@plt>
mov    $0xffffffffffffffff,%r15
test   %rax,%rax
je     11fc <getFileContent+0x8c>
mov    %rax,%rbx
mov    0x2e44(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1050 <rewind@plt>
cmp    %r12,%r13
jle    11d9 <getFileContent+0x69>
lea    0xe34(%rip),%rdi
mov    %r12,%rsi
call   1080 <GLlog@plt>
jmp    11fc <getFileContent+0x8c>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
movb   $0x0,(%r14,%r13,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r13,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [43 x i8] c"file is large than the size(%ld) you give\0A\00"
define i64 @getFileContent(i8* %0, i64 %1, i8* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i64 -1, i64* %4
br label %40
15: ; preds = %3
%16 = load i32*, i32** %8
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = load i32*, i32** %8
%20 = call i64 @ftell(i32* %19)
store i64 %20, i64* %9
%21 = load i32*, i32** %8
%22 = call i32 @rewind(i32* %21)
%23 = load i64, i64* %6
%24 = load i64, i64* %9
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = load i64, i64* %6
%28 = call i32 @GLlog(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %27)
store i64 -1, i64* %4
br label %40
29: ; preds = %15
%30 = load i8*, i8** %5
%31 = load i64, i64* %9
%32 = load i32*, i32** %8
%33 = call i32 @fread(i8* %30, i32 1, i64 %31, i32* %32)
%34 = load i8*, i8** %5
%35 = load i64, i64* %9
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
%37 = load i32*, i32** %8
%38 = call i32 @fclose(i32* %37)
%39 = load i64, i64* %9
store i64 %39, i64* %4
br label %40
40: ; preds = %29, %26, %14
%41 = load i64, i64* %4
ret i64 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [43 x i8] c"file is large than the size(%ld) you give\0A\00"
define i64 @getFileContent(i8* nocapture %0, i64 %1, i8* nocapture %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %4, i32 0, i32 %7)
%9 = tail call i64 @ftell(i32* %4)
%10 = tail call i32 @rewind(i32* %4)
%11 = icmp sgt i64 %9, %1
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @GLlog(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i64 %1)
br label %18
14: ; preds = %6
%15 = tail call i32 @fread(i8* %0, i32 1, i64 %9, i32* %4)
%16 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %16
%17 = tail call i32 @fclose(i32* %4)
br label %18
18: ; preds = %12, %14, %3
%19 = phi i64 [ -1, %3 ], [ -1, %12 ], [ %9, %14 ]
ret i64 %19
}