#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 */
int EOF;
int /*<<< orphan*/ copie(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int errno;
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ validerUsage(int);
int main(int argc, char **argv) {
  FILE *source;
  FILE *destination;
  int close1, close2;
  validerUsage(argc);
  source = fopen(argv[1], "r");
  if (source == NULL) {
    printf("Erreur fichier source %d\n", errno);
    return 1;
  }
  destination = fopen(argv[2], "w");
  if (destination == NULL) {
    printf("Erreur fichier destination %d\n", errno);
    fclose(source);
    return 1;
  }
  if (!copie(source, destination))
    printf("Erreur lors de la copie du fichier.\n");
  close1 = fclose(source);
  close2 = fclose(destination);
  if (close1 == EOF || close2 == EOF) {
    printf("Erreur lors de la fermeture d'un fichier.\n");
    return 1;
  }
  return 0;
}


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    -0x8(%rbp),%edi
call   1060 <validerUsage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <main+0x64>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x134>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1203 <main+0xb3>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x134>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <copie@plt>
cmp    $0x0,%eax
jne    1227 <main+0xd7>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%eax
je     1263 <main+0x113>
mov    -0x28(%rbp),%eax
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%eax
jne    127d <main+0x12d>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x134>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1070 <validerUsage@plt>
mov    0x8(%rbx),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ed <main+0x8d>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1206 <main+0xa6>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <copie@plt>
test   %eax,%eax
jne    11b8 <main+0x58>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %eax,%ecx
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
cmp    %edx,%ebx
je     11df <main+0x7f>
xor    %eax,%eax
cmp    %edx,%ecx
jne    122a <main+0xca>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
jmp    1225 <main+0xc5>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1225 <main+0xc5>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Erreur fichier source %d\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [31 x i8] c"Erreur fichier destination %d\0A\00"
@.str.4 = [37 x i8] c"Erreur lors de la copie du fichier.\0A\00"
@EOF = global i32 0
@.str.5 = [43 x i8] c"Erreur lors de la fermeture d'un fichier.\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 i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = call i32 @validerUsage(i32 %10)
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @errno
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 1, i32* %3
br label %55
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = load i32, i32* @errno
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %6
%32 = call i32 @fclose(i32* %31)
store i32 1, i32* %3
br label %55
33: ; preds = %21
%34 = load i32*, i32** %6
%35 = load i32*, i32** %7
%36 = call i32 @copie(i32* %34, i32* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
store i32 %42, i32* %8
%43 = load i32*, i32** %7
%44 = call i32 @fclose(i32* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %8
%46 = load i32, i32* @EOF
%47 = icmp eq i32 %45, %46
br i1 %47, label %52, label %48
48: ; preds = %40
%49 = load i32, i32* %9
%50 = load i32, i32* @EOF
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %48, %40
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %55
54: ; preds = %48
store i32 0, i32* %3
br label %55
55: ; preds = %54, %52, %28, %18
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"Erreur fichier source %d\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [31 x i8] c"Erreur fichier destination %d\0A\00"
@EOF = global i32 0
@str = [36 x i8] c"Erreur lors de la copie du fichier.\00"
@str.6 = [42 x i8] c"Erreur lors de la fermeture d'un fichier.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @validerUsage(i32 %0)
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %34
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = load i32, i32* @errno
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = tail call i32 @fclose(i32* %6)
br label %34
20: ; preds = %11
%21 = tail call i32 @copie(i32* %6, i32* %14)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = tail call i32 @fclose(i32* %6)
%27 = tail call i32 @fclose(i32* %14)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %26, %28
%30 = icmp eq i32 %27, %28
%31 = or i1 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.6, i64 0, i64 0))
br label %34
34: ; preds = %25, %32, %16, %8
%35 = phi i32 [ 1, %8 ], [ 1, %16 ], [ 1, %32 ], [ 0, %25 ]
ret i32 %35
}