#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ getcwd(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *bufferingFichier(char *nomFichier) {
  FILE *pFile;
  long lSize;
  char *buffer;
  size_t result;
  char currentDirectory[2048];
  getcwd(currentDirectory, 2048);
  strcat(currentDirectory, "/");
  strcat(currentDirectory, nomFichier);
  pFile = fopen(currentDirectory, "r");
  if (pFile == NULL) {
    fputs("Erreur de fichier\n", stderr);
    exit(1);
  }
  fseek(pFile, 0, SEEK_END);
  lSize = ftell(pFile);
  rewind(pFile);
  buffer = (char *)malloc(sizeof(char) * lSize);
  memset(buffer, 0x0, sizeof(char) * lSize);
  if (buffer == NULL) {
    fputs("Erreur mémoire\n", stderr);
    exit(2);
  }
  result = fread(buffer, 1, lSize, pFile);
  if (result != lSize) {
    fputs("Erreur de lecture\n", stderr);
    exit(3);
  }
  fclose(pFile);
  return buffer;
}


x86 assembly (clang, -O0):
<bufferingFichier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x830(%rbp),%rdi
mov    $0x800,%esi
call   1080 <getcwd@plt>
lea    -0x830(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   10d0 <strcat@plt>
lea    -0x830(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10d0 <strcat@plt>
lea    -0x830(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1244 <bufferingFichier+0x84>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xdcf(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d99(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
jne    12c0 <bufferingFichier+0x100>
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    0xd66(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1307 <bufferingFichier+0x147>
mov    0x2ce9(%rip),%rax
mov    (%rax),%esi
lea    0xd30(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferingFichier>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1080 <getcwd@plt>
lea    0xe1a(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10d0 <strcat@plt>
lea    0xe02(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1283 <bufferingFichier+0xc3>
mov    %rax,%r14
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r14,%rdi
call   1090 <ftell@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <rewind@plt>
mov    %r15d,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1070 <memset@plt>
test   %rbx,%rbx
je     12a2 <bufferingFichier+0xe2>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
jne    12c1 <bufferingFichier+0x101>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d4e(%rip),%rax
mov    (%rax),%esi
lea    0xd71(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
lea    0xd65(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
lea    0xd57(%rip),%rdi
call   1060 <fputs@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Erreur de fichier\0A\00"
@stderr = global i32 0
@SEEK_END = global i32 0
@.str.3 = [17 x i8] c"Erreur m\C3\A9moire\0A\00"
@.str.4 = [19 x i8] c"Erreur de lecture\0A\00"
define i8* @bufferingFichier(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [2048 x i8]
store i8* %0, i8** %2
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%9 = call i32 @getcwd(i8* %8, i32 2048)
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%11 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%13 = load i8*, i8** %2
%14 = call i32 @strcat(i8* %12, i8* %13)
%15 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %3
%17 = load i32*, i32** %3
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %1
%20 = load i32, i32* @stderr
%21 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %1
%24 = load i32*, i32** %3
%25 = load i32, i32* @SEEK_END
%26 = call i32 @fseek(i32* %24, i32 0, i32 %25)
%27 = load i32*, i32** %3
%28 = call i64 @ftell(i32* %27)
store i64 %28, i64* %4
%29 = load i32*, i32** %3
%30 = call i32 @rewind(i32* %29)
%31 = load i64, i64* %4
%32 = mul i64 1, %31
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = load i64, i64* %4
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i32 @memset(i8* %36, i32 0, i32 %39)
%41 = load i8*, i8** %5
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %23
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = call i32 @exit(i32 2)
unreachable
47: ; preds = %23
%48 = load i8*, i8** %5
%49 = load i64, i64* %4
%50 = load i32*, i32** %3
%51 = call i64 @fread(i8* %48, i32 1, i64 %49, i32* %50)
store i64 %51, i64* %6
%52 = load i64, i64* %6
%53 = load i64, i64* %4
%54 = icmp ne i64 %52, %53
br i1 %54, label %55, label %59
55: ; preds = %47
%56 = load i32, i32* @stderr
%57 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %56)
%58 = call i32 @exit(i32 3)
unreachable
59: ; preds = %47
%60 = load i32*, i32** %3
%61 = call i32 @fclose(i32* %60)
%62 = load i8*, i8** %5
ret i8* %62
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"Erreur de fichier\0A\00"
@stderr = global i32 0
@SEEK_END = global i32 0
@.str.3 = [17 x i8] c"Erreur m\C3\A9moire\0A\00"
@.str.4 = [19 x i8] c"Erreur de lecture\0A\00"
define i8* @bufferingFichier(i8* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = call i32 @getcwd(i8* %3, i32 2048)
%5 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcat(i8* %3, i8* %0)
%7 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* @SEEK_END
%15 = call i32 @fseek(i32* %7, i32 0, i32 %14)
%16 = call i64 @ftell(i32* %7)
%17 = call i32 @rewind(i32* %7)
%18 = trunc i64 %16 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @memset(i8* %20, i32 0, i32 %18)
%22 = icmp eq i64 %19, 0
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %13
%28 = call i64 @fread(i8* %20, i32 1, i64 %16, i32* %7)
%29 = icmp eq i64 %28, %16
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %31)
%33 = call i32 @exit(i32 3)
unreachable
34: ; preds = %27
%35 = call i32 @fclose(i32* %7)
ret i8* %20
}