#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
char *readFromFile(char *s, const char *file) {
  s = (char *)malloc(9000);
  FILE *f = fopen(file, "r");
  if (f == NULL) {
    printf("\n\t Probleme :Le fichier et introuvable ou il est utilises par un "
           "autre programme !\t");
    return NULL;
  }
  char c;
  int i = 0;
  while ((c = fgetc(f)) != EOF) {
    s[i] = c;
    i++;
  }
  s[i] = '\0';
  fclose(f);
  return s;
}


x86 assembly (clang, -O0):
<readFromFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x2328,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a6 <readFromFile+0x56>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1207 <readFromFile+0xb7>
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
mov    0x2e25(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11ea <readFromFile+0x9a>
mov    -0x21(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ad <readFromFile+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFromFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x2328,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1197 <readFromFile+0x47>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e5a(%rip),%r15
cmp    (%r15),%al
jne    11a8 <readFromFile+0x58>
xor    %eax,%eax
jmp    11c7 <readFromFile+0x77>
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
xor    %r14d,%r14d
jmp    11d4 <readFromFile+0x84>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11b0 <readFromFile+0x60>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r12,%rdi
call   1030 <fclose@plt>
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"
@.str.1 = [84 x i8] c"\0A\09 Probleme :Le fichier et introuvable ou il est utilises par un autre programme !\09\00"
@EOF = global i8 0
define i8* @readFromFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = call i64 @malloc(i32 9000)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %41
17: ; preds = %2
store i32 0, i32* %8
br label %18
18: ; preds = %25, %17
%19 = load i32*, i32** %6
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %7
%21 = sext i8 %20 to i32
%22 = load i8, i8* @EOF
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i8, i8* %7
%27 = load i8*, i8** %4
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 %26, i8* %30
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %18
33: ; preds = %18
%34 = load i8*, i8** %4
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
%40 = load i8*, i8** %4
store i8* %40, i8** %3
br label %41
41: ; preds = %33, %15
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [84 x i8] c"\0A\09 Probleme :Le fichier et introuvable ou il est utilises par un autre programme !\09\00"
@EOF = global i8 0
define i8* @readFromFile(i8* nocapture readnone %0, i8* nocapture %1) {
%3 = tail call i64 @malloc(i32 9000)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = tail call signext i8 @fgetc(i32* %5)
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %8, %9
br i1 %10, label %23, label %13
11: ; preds = %2
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0))
br label %27
13: ; preds = %7, %13
%14 = phi i64 [ %17, %13 ], [ 0, %7 ]
%15 = phi i8 [ %18, %13 ], [ %8, %7 ]
%16 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 %15, i8* %16
%17 = add nuw i64 %14, 1
%18 = tail call signext i8 @fgetc(i32* %5)
%19 = load i8, i8* @EOF
%20 = icmp eq i8 %18, %19
br i1 %20, label %21, label %13
21: ; preds = %13
%22 = and i64 %17, 4294967295
br label %23
23: ; preds = %21, %7
%24 = phi i64 [ 0, %7 ], [ %22, %21 ]
%25 = getelementptr inbounds i8, i8* %4, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @fclose(i32* %5)
br label %27
27: ; preds = %23, %11
%28 = phi i8* [ null, %11 ], [ %4, %23 ]
ret i8* %28
}