#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv, char **arge) {
  if (argc != 3) {
    printf("Syntaxe incorrecte : %s source.txt destination.txt\n", argv[0]);
    return 1;
  }
  int source = open(argv[1], O_RDONLY);
  if (source < 0) {
    printf("Impossible d'ouvrir %s !\n", argv[1]);
    return 2;
  }
  int dest = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0x644);
  if (dest < 0) {
    printf("Impossible d'ouvrir %s !\n", argv[2]);
    return 3;
  }
  char c;
  while (0 < read(source, &c, 1)) {
    write(dest, &c, 1);
  }
  close(dest);
  close(source);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1193 <main+0x43>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11d8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    127e <main+0x12e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%rip),%rax
or     (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    $0x644,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1234 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    127e <main+0x12e>
jmp    1239 <main+0xe9>
mov    -0x1c(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    126e <main+0x11e>
mov    -0x20(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1239 <main+0xe9>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    1217 <main+0xc7>
mov    0x8(%r14),%rdi
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     122d <main+0xdd>
mov    %eax,%r15d
mov    0x2e37(%rip),%rax
mov    0x2e68(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%r14),%rdi
mov    0x2e51(%rip),%rax
or     (%rax),%esi
mov    $0x644,%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     1244 <main+0xf4>
mov    %eax,%ebp
lea    0x7(%rsp),%rsi
mov    %r15d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    1204 <main+0xb4>
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     11e0 <main+0x90>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1259 <main+0x109>
mov    (%r14),%rsi
lea    0xddf(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    1259 <main+0x109>
mov    0x8(%r14),%rsi
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%eax
jmp    1259 <main+0x109>
mov    0x10(%r14),%rsi
lea    0xde5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Syntaxe incorrecte : %s source.txt destination.txt\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Impossible d'ouvrir %s !\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i8**, i8*** %6
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %4
br label %61
18: ; preds = %3
%19 = load i8**, i8*** %6
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 (i8*, i32, ...) @open(i8* %21, i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load i8**, i8*** %6
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 2, i32* %4
br label %61
31: ; preds = %18
%32 = load i8**, i8*** %6
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_WRONLY
%36 = load i32, i32* @O_CREAT
%37 = or i32 %35, %36
%38 = load i32, i32* @O_TRUNC
%39 = or i32 %37, %38
%40 = call i32 (i8*, i32, ...) @open(i8* %34, i32 %39, i32 1604)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %31
%44 = load i8**, i8*** %6
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %46)
store i32 3, i32* %4
br label %61
48: ; preds = %31
br label %49
49: ; preds = %53, %48
%50 = load i32, i32* %8
%51 = call i64 @read(i32 %50, i8* %10, i32 1)
%52 = icmp slt i64 0, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %9
%55 = call i32 @write(i32 %54, i8* %10, i32 1)
br label %49
56: ; preds = %49
%57 = load i32, i32* %9
%58 = call i32 @close(i32 %57)
%59 = load i32, i32* %8
%60 = call i32 @close(i32 %59)
br label %61
61: ; preds = %56, %43, %26, %13
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@.str = [52 x i8] c"Syntaxe incorrecte : %s source.txt destination.txt\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Impossible d'ouvrir %s !\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca i8
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %41
9: ; preds = %3
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8*, i8** %10
%17 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %41
18: ; preds = %9
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %22, %21
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = tail call i32 (i8*, i32, ...) @open(i8* %20, i32 %25, i32 1604)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %18
%29 = load i8*, i8** %19
%30 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %41
31: ; preds = %18
%32 = call i64 @read(i32 %13, i8* %4, i32 1)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31, %34
%35 = call i32 @write(i32 %26, i8* %4, i32 1)
%36 = call i64 @read(i32 %13, i8* %4, i32 1)
%37 = icmp sgt i64 %36, 0
br i1 %37, label %34, label %38
38: ; preds = %34, %31
%39 = tail call i32 @close(i32 %26)
%40 = tail call i32 @close(i32 %13)
br label %41
41: ; preds = %15, %38, %28, %6
%42 = phi i32 [ 1, %6 ], [ 2, %15 ], [ 3, %28 ], [ 0, %38 ]
ret i32 %42
}