#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 /*<<< orphan*/ putchar(char);
scalar_t__ 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 de l'ouverture du fichier %s \n", argv[1]);
    perror("Open ");
    exit(1);
  }
  char c;
  while (read(fd, &c, 1))
    putchar(c);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11fe <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1203 <main+0x93>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
je     122c <main+0xbc>
movsbl -0x15(%rbp),%edi
call   1030 <putchar@plt>
jmp    1203 <main+0x93>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11df <main+0x6f>
mov    0x8(%r14),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11fc <main+0x8c>
mov    %eax,%ebx
lea    0x7(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
je     11ce <main+0x5e>
lea    0x7(%rsp),%r14
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jne    11b0 <main+0x40>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%r14),%rsi
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe28(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <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 = [38 x i8] c"Erreur de l'ouverture du fichier %s \0A\00"
@.str.2 = [6 x i8] c"Open \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %32
25: ; preds = %17
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %17
br label %33
33: ; preds = %37, %32
%34 = load i32, i32* %6
%35 = call i64 @read(i32 %34, i8* %7, i32 1)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i8, i8* %7
%39 = call i32 @putchar(i8 signext %38)
br label %33
40: ; preds = %33
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
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 = [38 x i8] c"Erreur de l'ouverture du fichier %s \0A\00"
@.str.2 = [6 x i8] c"Open \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca 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 ([38 x i8], [38 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 = call i64 @read(i32 %14, i8* %3, i32 1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21, %24
%25 = load i8, i8* %3
%26 = tail call i32 @putchar(i8 signext %25)
%27 = call i64 @read(i32 %14, i8* %3, i32 1)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %24
29: ; preds = %24, %21
%30 = tail call i32 @close(i32 %14)
ret i32 0
}