#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 S_IRUSR;
int S_IWUSR;
char *calloc(int, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int mycopyf(char *rpath, char *wpath) {
  int rF, wF, rbytes, wbytes;
  char *buf;
  buf = calloc(4096, sizeof(char));
  if ((rF = open(rpath, O_RDONLY)) < 0) {
    fprintf(stdout, "Errore in apertura\n");
    exit(10);
  }
  if ((wF = open(wpath, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) < 0) {
    fprintf(stdout, "Errore in apertura\n");
    exit(11);
  }
  while ((rbytes = read(rF, buf, 4096)) > 0) {
    if ((wbytes = write(wF, buf, strlen(buf))) != rbytes)
      fprintf(stderr, "Errore in scrittura %d/%d\n", wbytes, rbytes);
  }
  close(rF);
  close(wF);
  return 0;
}


x86 assembly (clang, -O0):
<mycopyf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11e4 <mycopyf+0x64>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    0x2e00(%rip),%rax
or     (%rax),%esi
mov    0x2def(%rip),%rax
or     (%rax),%esi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
mov    0x2dbd(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1249 <mycopyf+0xc9>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xb,%edi
call   10a0 <exit@plt>
jmp    124e <mycopyf+0xce>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    12be <mycopyf+0x13e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x20(%rbp)
cmp    -0x1c(%rbp),%eax
je     12b9 <mycopyf+0x139>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    124e <mycopyf+0xce>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mycopyf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbp
mov    $0x1000,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     1294 <mycopyf+0x114>
mov    %eax,%r14d
mov    0x2dd8(%rip),%rax
mov    0x2e29(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e16(%rip),%rax
or     (%rax),%esi
mov    0x2dd5(%rip),%rax
mov    0x2de6(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    %r15,%rdi
xor    %eax,%eax
call   1090 <open@plt>
test   %eax,%eax
js     12b5 <mycopyf+0x135>
mov    %eax,%r12d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1273 <mycopyf+0xf3>
mov    %eax,%ebp
mov    0x2da0(%rip),%r13
lea    0xded(%rip),%r15
jmp    1246 <mycopyf+0xc6>
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1273 <mycopyf+0xf3>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,%eax
je     1230 <mycopyf+0xb0>
mov    0x0(%r13),%edi
mov    %r15,%rsi
mov    %eax,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    1230 <mycopyf+0xb0>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xb,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@stdout = global i32 0
@.str = [20 x i8] c"Errore in apertura\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Errore in scrittura %d/%d\0A\00"
define i32 @mycopyf(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = call i8* @calloc(i32 4096, i32 1)
store i8* %10, i8** %9
%11 = load i8*, i8** %3
%12 = load i32, i32* @O_RDONLY
%13 = call i32 (i8*, i32, ...) @open(i8* %11, i32 %12)
store i32 %13, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stdout
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 10)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %4
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %21, %22
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = load i32, i32* @S_IWUSR
%28 = or i32 %26, %27
%29 = call i32 (i8*, i32, ...) @open(i8* %20, i32 %25, i32 %28)
store i32 %29, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %19
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 11)
unreachable
35: ; preds = %19
br label %36
36: ; preds = %54, %35
%37 = load i32, i32* %5
%38 = load i8*, i8** %9
%39 = call i32 @read(i32 %37, i8* %38, i32 4096)
store i32 %39, i32* %7
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %36
%42 = load i32, i32* %6
%43 = load i8*, i8** %9
%44 = load i8*, i8** %9
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @write(i32 %42, i8* %43, i32 %45)
store i32 %46, i32* %8
%47 = load i32, i32* %7
%48 = icmp ne i32 %46, %47
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i32, i32* @stderr
%51 = load i32, i32* %8
%52 = load i32, i32* %7
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %51, i32 %52)
br label %54
54: ; preds = %49, %41
br label %36
55: ; preds = %36
%56 = load i32, i32* %5
%57 = call i32 @close(i32 %56)
%58 = load i32, i32* %6
%59 = call i32 @close(i32 %58)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@stdout = global i32 0
@.str = [20 x i8] c"Errore in apertura\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Errore in scrittura %d/%d\0A\00"
define i32 @mycopyf(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call dereferenceable_or_null(4096) i8* @calloc(i32 4096, i32 1)
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 (i8*, i32, ...) @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 10)
unreachable
11: ; preds = %2
%12 = load i32, i32* @O_WRONLY
%13 = load i32, i32* @O_CREAT
%14 = or i32 %13, %12
%15 = load i32, i32* @O_TRUNC
%16 = or i32 %14, %15
%17 = load i32, i32* @S_IRUSR
%18 = load i32, i32* @S_IWUSR
%19 = or i32 %18, %17
%20 = tail call i32 (i8*, i32, ...) @open(i8* %1, i32 %16, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %11
%23 = tail call i32 @read(i32 %5, i8* %3, i32 4096)
%24 = icmp sgt i32 %23, 0
br i1 %24, label %29, label %40
25: ; preds = %11
%26 = load i32, i32* @stdout
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 11)
unreachable
29: ; preds = %22, %37
%30 = phi i32 [ %38, %37 ], [ %23, %22 ]
%31 = tail call i32 @strlen(i8* %3)
%32 = tail call i32 @write(i32 %20, i8* %3, i32 %31)
%33 = icmp eq i32 %32, %30
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %30)
br label %37
37: ; preds = %34, %29
%38 = tail call i32 @read(i32 %5, i8* %3, i32 4096)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %29, label %40
40: ; preds = %37, %22
%41 = tail call i32 @close(i32 %5)
%42 = tail call i32 @close(i32 %20)
ret i32 0
}