#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 O_CREAT;
int O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("USAGE: %s [source][cible]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  int source = open(argv[1], O_RDONLY);
  if (source == -1) {
    printf("Erreur lors de l'ouverture du fichier %s \n", argv[1]);
    perror("Open ");
    exit(1);
  }
  int cible = open(argv[2], O_WRONLY | O_CREAT);
  if (cible == -1) {
    printf("Erreur lors de la création du fichier %s \n", argv[2]);
    perror("Open ");
    exit(1);
  }
  char buffer[2048];
  int nbLus = 0;
  while (nbLus = read(source, buffer, 2048))
    write(cible, buffer, nbLus);
  close(source);
  close(cible);
  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   $0x3,-0x8(%rbp)
je     11b4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1201 <main+0x91>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
lea    0xe54(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1257 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x824(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1060 <read@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
je     129e <main+0x12e>
mov    -0x18(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x824(%rbp),%edx
call   1030 <write@plt>
jmp    1261 <main+0xf1>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    122f <main+0xbf>
mov    0x8(%r14),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     124c <main+0xdc>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2e0e(%rip),%rax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1259 <main+0xe9>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x800,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1210 <main+0xa0>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    11f0 <main+0x80>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x8(%r14),%rsi
lea    0xdc4(%rip),%rdi
jmp    1264 <main+0xf4>
mov    0x10(%r14),%rsi
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
lea    0xdd6(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"USAGE: %s [source][cible]\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"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.3 = [44 x i8] c"Erreur lors de la cr\C3\A9ation du fichier %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2048 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %34
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %19
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_WRONLY
%39 = load i32, i32* @O_CREAT
%40 = or i32 %38, %39
%41 = call i32 @open(i8* %37, i32 %40)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %51
44: ; preds = %34
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %34
store i32 0, i32* %9
br label %52
52: ; preds = %57, %51
%53 = load i32, i32* %6
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%55 = call i32 @read(i32 %53, i8* %54, i32 2048)
store i32 %55, i32* %9
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i32, i32* %7
%59 = getelementptr inbounds [2048 x i8], [2048 x i8]* %8, i64 0, i64 0
%60 = load i32, i32* %9
%61 = call i32 @write(i32 %58, i8* %59, i32 %60)
br label %52
62: ; preds = %52
%63 = load i32, i32* %6
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* %7
%66 = call i32 @close(i32 %65)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"USAGE: %s [source][cible]\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"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.3 = [44 x i8] c"Erreur lors de la cr\C3\A9ation du fichier %s \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = icmp eq i32 %0, 3
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 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 i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_WRONLY
%25 = load i32, i32* @O_CREAT
%26 = or i32 %25, %24
%27 = tail call i32 @open(i8* %23, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i8*, i8** %22
%31 = tail call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %21
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%36 = call i32 @read(i32 %14, i8* %35, i32 2048)
%37 = icmp eq i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %34, %38
%39 = phi i32 [ %41, %38 ], [ %36, %34 ]
%40 = call i32 @write(i32 %27, i8* %35, i32 %39)
%41 = call i32 @read(i32 %14, i8* %35, i32 2048)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %38
43: ; preds = %38, %34
%44 = tail call i32 @close(i32 %14)
%45 = tail call i32 @close(i32 %27)
ret i32 0
}