#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;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: %s file_from file_to\n", argv[0]);
    return 1;
  }
  int fd_from = open(argv[1], O_RDONLY);
  if (fd_from < 0) {
    char msg[80];
    sprintf(msg, "Cannot openinng file '%s'", argv[1]);
    perror(msg);
    return 2;
  }
  int fd_to = open(argv[2], O_CREAT | O_WRONLY, 0755);
  if (fd_to < 0) {
    char msg[80];
    sprintf(msg, "Cannot creating file '%s'", argv[2]);
    perror(msg);
    return 3;
  }
  char buffer[1024];
  while (1) {
    int size = read(fd_from, buffer, sizeof(buffer));
    printf("read size: %i\n", size);
    if (size == 0)
      break;
    int si = write(fd_to, buffer, size);
    printf("write size: %i\n", si);
  }
  puts("Copy file success!\n");
  close(fd_from);
  close(fd_to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1216 <main+0x96>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe21(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1318 <main+0x198>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    0x2d9a(%rip),%rax
or     (%rax),%esi
mov    $0x1ed,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    127c <main+0xfc>
lea    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdd8(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0xd0(%rbp),%rdi
call   1090 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1318 <main+0x198>
jmp    1281 <main+0x101>
mov    -0x14(%rbp),%edi
lea    -0x4d0(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,-0x4d4(%rbp)
mov    -0x4d4(%rbp),%esi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x4d4(%rbp)
jne    12c1 <main+0x141>
jmp    12f5 <main+0x175>
mov    -0x74(%rbp),%edi
lea    -0x4d0(%rbp),%rsi
mov    -0x4d4(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x4d8(%rbp)
mov    -0x4d8(%rbp),%esi
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1281 <main+0x101>
lea    0xd74(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x74(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    127b <main+0xfb>
mov    0x8(%r14),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     12a3 <main+0x123>
mov    %eax,%r15d
mov    0x10(%r14),%rdi
mov    0x2e31(%rip),%rax
mov    0x2dfa(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ed,%edx
xor    %eax,%eax
call   1080 <open@plt>
test   %eax,%eax
js     12c8 <main+0x148>
mov    %eax,%r13d
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,%ebp
lea    0xe4f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
je     125b <main+0xdb>
mov    %rsp,%rbx
lea    0xe47(%rip),%r12
lea    0xe31(%rip),%r14
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebp,%ebp
jne    1220 <main+0xa0>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   1060 <close@plt>
mov    %r13d,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    1291 <main+0x111>
mov    (%r14),%rsi
lea    0xd7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r14),%rdx
lea    0xd6f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1090 <perror@plt>
mov    $0x2,%eax
jmp    1291 <main+0x111>
mov    0x10(%r14),%rdx
lea    0xd64(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1090 <perror@plt>
mov    $0x3,%eax
jmp    1291 <main+0x111>

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: %s file_from file_to\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Cannot openinng file '%s'\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [26 x i8] c"Cannot creating file '%s'\00"
@.str.3 = [15 x i8] c"read size: %i\0A\00"
@.str.4 = [16 x i8] c"write size: %i\0A\00"
@.str.5 = [20 x i8] c"Copy file success!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca [80 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %77
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = call i32 (i8*, i32, ...) @open(i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%35 = call i32 @perror(i8* %34)
store i32 2, i32* %3
br label %77
36: ; preds = %20
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_CREAT
%41 = load i32, i32* @O_WRONLY
%42 = or i32 %40, %41
%43 = call i32 (i8*, i32, ...) @open(i8* %39, i32 %42, i32 493)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %36
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%53 = call i32 @perror(i8* %52)
store i32 3, i32* %3
br label %77
54: ; preds = %36
br label %55
55: ; preds = %54, %64
%56 = load i32, i32* %6
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%58 = call i32 @read(i32 %56, i8* %57, i32 1024)
store i32 %58, i32* %11
%59 = load i32, i32* %11
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %59)
%61 = load i32, i32* %11
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %55
br label %71
64: ; preds = %55
%65 = load i32, i32* %8
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%67 = load i32, i32* %11
%68 = call i32 @write(i32 %65, i8* %66, i32 %67)
store i32 %68, i32* %12
%69 = load i32, i32* %12
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %69)
br label %55
71: ; preds = %63
%72 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* %8
%76 = call i32 @close(i32 %75)
store i32 0, i32* %3
br label %77
77: ; preds = %71, %46, %28, %15
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: %s file_from file_to\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"Cannot openinng file '%s'\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@.str.2 = [26 x i8] c"Cannot creating file '%s'\00"
@.str.3 = [15 x i8] c"read size: %i\0A\00"
@.str.4 = [16 x i8] c"write size: %i\0A\00"
@.str.5 = [20 x i8] c"Copy file success!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca [1024 x i8]
%6 = icmp eq i32 %0, 3
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %50
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 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%18 = load i8*, i8** %11
%19 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @perror(i8* %17)
br label %50
21: ; preds = %10
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_CREAT
%25 = load i32, i32* @O_WRONLY
%26 = or i32 %25, %24
%27 = tail call i32 (i8*, i32, ...) @open(i8* %23, i32 %26, i32 493)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%31 = load i8*, i8** %22
%32 = call i32 @sprintf(i8* %30, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = call i32 @perror(i8* %30)
br label %50
34: ; preds = %21
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%36 = call i32 @read(i32 %14, i8* %35, i32 1024)
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %36)
%38 = icmp eq i32 %36, 0
br i1 %38, label %46, label %39
39: ; preds = %34, %39
%40 = phi i32 [ %43, %39 ], [ %36, %34 ]
%41 = call i32 @write(i32 %27, i8* %35, i32 %40)
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = call i32 @read(i32 %14, i8* %35, i32 1024)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = icmp eq i32 %43, 0
br i1 %45, label %46, label %39
46: ; preds = %39, %34
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%48 = tail call i32 @close(i32 %14)
%49 = tail call i32 @close(i32 %27)
br label %50
50: ; preds = %16, %46, %29, %7
%51 = phi i32 [ 1, %7 ], [ 2, %16 ], [ 3, %29 ], [ 0, %46 ]
ret i32 %51
}