#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 */

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("USAGE: %s [fichier]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  int fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    printf("Erreur lors de l'ouverture du fichier %s \n", argv[1]);
    perror("Open ");
    exit(1);
  }
  char buffer[2048];
  int nbLus = 0;
  while (nbLus = read(fd, buffer, 2048)) {
    buffer[nbLus] = '\0';
    printf("%s", buffer);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f1 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
lea    0xe5e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
movl   $0x0,-0x824(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1050 <read@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
je     1245 <main+0xe5>
movslq -0x824(%rbp),%rax
movb   $0x0,-0x820(%rbp,%rax,1)
lea    -0x820(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
jmp    11fb <main+0x9b>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e9 <main+0x89>
mov    0x8(%rbx),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1206 <main+0xa6>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x800,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11d4 <main+0x74>
lea    0xea0(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    11b0 <main+0x50>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x8(%rbx),%rsi
lea    0xe04(%rip),%rdi
call   1030 <printf@plt>
lea    0xe23(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"USAGE: %s [fichier]\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [43 x i8] c"Erreur lors de l'ouverture du fichier %s \0A\00"
@.str.2 = [6 x i8] c"Open \00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2048 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %33
26: ; preds = %18
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
store i32 0, i32* %8
br label %34
34: ; preds = %39, %33
%35 = load i32, i32* %6
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%37 = call i32 @read(i32 %35, i8* %36, i32 2048)
store i32 %37, i32* %8
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i32, i32* %8
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 %41
store i8 0, i8* %42
%43 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %34
45: ; preds = %34
%46 = load i32, i32* %6
%47 = call i32 @close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"USAGE: %s [fichier]\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [43 x i8] c"Erreur lors de l'ouverture du fichier %s \0A\00"
@.str.2 = [6 x i8] c"Open \00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8*, i8** %11
%18 = tail call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%23 = call i32 @read(i32 %14, i8* %22, i32 2048)
%24 = icmp eq i32 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %21, %25
%26 = phi i32 [ %30, %25 ], [ %23, %21 ]
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %27
store i8 0, i8* %28
%29 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%30 = call i32 @read(i32 %14, i8* %22, i32 2048)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %25
32: ; preds = %25, %21
%33 = call i32 @close(i32 %14)
ret i32 0
}