#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *sorgente;
  FILE *destinazione;
  char buffer[1024];
  int num_elem;
  if (argc != 3) {
    fprintf(stderr, "Errore \n");
    return -1;
  }
  if ((sorgente = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Errore sorgente \n");
    return -2;
  }
  if ((destinazione = fopen(argv[2], "wb")) == NULL) {
    fprintf(stderr, "Errore destinazione \n");
    return -3;
  }
  while ((num_elem = fread(buffer, 1, sizeof(buffer), sorgente)) != 0) {
    fwrite(buffer, 1, num_elem, destinazione);
  }
  fprintf(stdout, "File scritto con successo \n");
  fclose(sorgente);
  fclose(destinazione);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1194 <main+0x44>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <main+0x146>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d7 <main+0x87>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1296 <main+0x146>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe38(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121a <main+0xca>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1296 <main+0x146>
jmp    121f <main+0xcf>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
je     1268 <main+0x118>
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    121f <main+0xcf>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
cmp    $0x3,%edi
jne    1214 <main+0xc4>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe96(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1230 <main+0xe0>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     124c <main+0xfc>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
je     11eb <main+0x9b>
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %eax,%eax
jne    11c0 <main+0x70>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1266 <main+0x116>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xddc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1266 <main+0x116>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xfffffffe,%eax
jmp    1266 <main+0x116>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xfffffffd,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"Errore \0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Errore sorgente \0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [22 x i8] c"Errore destinazione \0A\00"
@stdout = global i32 0
@.str.5 = [28 x i8] c"File scritto con successo \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 [1024 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 %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %51
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -2, i32* %3
br label %51
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %7
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 -3, i32* %3
br label %51
33: ; preds = %24
br label %34
34: ; preds = %39, %33
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%36 = load i32*, i32** %6
%37 = call i32 @fread(i8* %35, i32 1, i32 1024, i32* %36)
store i32 %37, i32* %9
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %9
%42 = load i32*, i32** %7
%43 = call i32 @fwrite(i8* %40, i32 1, i32 %41, i32* %42)
br label %34
44: ; preds = %34
%45 = load i32, i32* @stdout
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
%49 = load i32*, i32** %7
%50 = call i32 @fclose(i32* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %44, %30, %21, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"Errore \0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [18 x i8] c"Errore sorgente \0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [22 x i8] c"Errore destinazione \0A\00"
@stdout = global i32 0
@.str.5 = [28 x i8] c"File scritto con successo \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %38
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %38
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = call i32 @fread(i8* %4, i32 1, i32 1024, i32* %12)
%24 = icmp eq i32 %23, 0
br i1 %24, label %33, label %28
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
br label %38
28: ; preds = %22, %28
%29 = phi i32 [ %31, %28 ], [ %23, %22 ]
%30 = call i32 @fwrite(i8* %4, i32 1, i32 %29, i32* %20)
%31 = call i32 @fread(i8* %4, i32 1, i32 1024, i32* %12)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %28
33: ; preds = %28, %22
%34 = load i32, i32* @stdout
%35 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%36 = tail call i32 @fclose(i32* %12)
%37 = tail call i32 @fclose(i32* %20)
br label %38
38: ; preds = %33, %25, %14, %6
%39 = phi i32 [ -1, %6 ], [ -2, %14 ], [ -3, %25 ], [ 0, %33 ]
ret i32 %39
}