#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*/ close(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: %s file_from file_to\n", argv[0]);
    return 1;
  }
  FILE *file_in = fopen(argv[1], "r");
  if (file_in == NULL) {
    char msg[80];
    sprintf(msg, "Cannot openinng file '%s'", argv[1]);
    perror(msg);
    return 2;
  }
  FILE *file_to = fopen(argv[2], "w+");
  if (file_to == NULL) {
    char msg[80];
    sprintf(msg, "Cannot creating file '%s'", argv[2]);
    perror(msg);
    return 3;
  }
  char buffer[256];
  while (1) {
    size_t size = fread(buffer, sizeof(char), sizeof(buffer), file_in);
    printf("read size: %i\n", size);
    if (size == 0)
      break;
    size_t num;
    if (size == sizeof(buffer)) {
      num = fwrite(buffer, sizeof(char), sizeof(buffer), file_to);
    } else {
      num = fwrite(buffer, sizeof(char), size, file_to);
    }
    printf("write num: %i\n", num);
  }
  puts("Copy file success!\n");
  close(file_in);
  close(file_to);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%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    1351 <main+0x1d1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1214 <main+0x94>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe25(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1351 <main+0x1d1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe16(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    126a <main+0xea>
lea    -0xd0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdef(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xd0(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    1351 <main+0x1d1>
jmp    126f <main+0xef>
lea    -0x1d0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1040 <fread@plt>
mov    %rax,-0x1d8(%rbp)
mov    -0x1d8(%rbp),%rsi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x1d8(%rbp)
jne    12b8 <main+0x138>
jmp    132c <main+0x1ac>
cmpq   $0x100,-0x1d8(%rbp)
jne    12ef <main+0x16f>
lea    -0x1d0(%rbp),%rdi
mov    -0x78(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   10a0 <fwrite@plt>
mov    %rax,-0x1e0(%rbp)
jmp    1312 <main+0x192>
lea    -0x1d0(%rbp),%rdi
mov    -0x1d8(%rbp),%rdx
mov    -0x78(%rbp),%rcx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
mov    %rax,-0x1e0(%rbp)
mov    -0x1e0(%rbp),%rsi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    126f <main+0xef>
lea    0xd41(%rip),%rdi
call   1030 <puts@plt>
mov    -0x18(%rbp),%rdi
call   1060 <close@plt>
mov    -0x78(%rbp),%rdi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    123c <main+0xbc>
mov    0x8(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1284 <main+0x104>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12a9 <main+0x129>
mov    %rax,%r15
mov    %rsp,%rbx
lea    0xe77(%rip),%r12
lea    0xe7f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbp,%rbp
je     1254 <main+0xd4>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %r15,%rcx
call   10a0 <fwrite@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f0 <main+0x70>
mov    (%rbx),%rsi
lea    0xdba(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    1272 <main+0xf2>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <close@plt>
mov    %r15,%rdi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdx
lea    0xd90(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    $0x2,%eax
jmp    1272 <main+0xf2>
mov    0x10(%rbx),%rdx
lea    0xd88(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1080 <perror@plt>
mov    $0x3,%eax
jmp    1272 <main+0xf2>

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: %s file_from file_to\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Cannot openinng file '%s'\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [26 x i8] c"Cannot creating file '%s'\00"
@.str.5 = [15 x i8] c"read size: %i\0A\00"
@.str.6 = [15 x i8] c"write num: %i\0A\00"
@.str.7 = [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 [256 x i8]
%11 = alloca i64
%12 = alloca i64
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 %81
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %35
27: ; preds = %20
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%34 = call i32 @perror(i8* %33)
store i32 2, i32* %3
br label %81
35: ; preds = %20
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %39, i32** %8
%40 = load i32*, i32** %8
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%49 = call i32 @perror(i8* %48)
store i32 3, i32* %3
br label %81
50: ; preds = %35
br label %51
51: ; preds = %50, %72
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%53 = load i32*, i32** %6
%54 = call i64 @fread(i8* %52, i32 1, i32 256, i32* %53)
store i64 %54, i64* %11
%55 = load i64, i64* %11
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %55)
%57 = load i64, i64* %11
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %51
br label %75
60: ; preds = %51
%61 = load i64, i64* %11
%62 = icmp eq i64 %61, 256
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%65 = load i32*, i32** %8
%66 = call i64 @fwrite(i8* %64, i32 1, i64 256, i32* %65)
store i64 %66, i64* %12
br label %72
67: ; preds = %60
%68 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%69 = load i64, i64* %11
%70 = load i32*, i32** %8
%71 = call i64 @fwrite(i8* %68, i32 1, i64 %69, i32* %70)
store i64 %71, i64* %12
br label %72
72: ; preds = %67, %63
%73 = load i64, i64* %12
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 %73)
br label %51
75: ; preds = %59
%76 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%77 = load i32*, i32** %6
%78 = call i32 @close(i32* %77)
%79 = load i32*, i32** %8
%80 = call i32 @close(i32* %79)
store i32 0, i32* %3
br label %81
81: ; preds = %75, %42, %27, %15
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: %s file_from file_to\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Cannot openinng file '%s'\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [26 x i8] c"Cannot creating file '%s'\00"
@.str.5 = [15 x i8] c"read size: %i\0A\00"
@.str.6 = [15 x i8] c"write num: %i\0A\00"
@.str.7 = [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 [256 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 %43
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%17 = load i8*, i8** %11
%18 = call i32 @sprintf(i8* %16, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = call i32 @perror(i8* %16)
br label %43
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%27 = load i8*, i8** %21
%28 = call i32 @sprintf(i8* %26, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%29 = call i32 @perror(i8* %26)
br label %43
30: ; preds = %20
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
br label %32
32: ; preds = %36, %30
%33 = call i64 @fread(i8* %31, i32 1, i32 256, i32* %13)
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i64 %33)
%35 = icmp eq i64 %33, 0
br i1 %35, label %39, label %36
36: ; preds = %32
%37 = call i64 @fwrite(i8* %31, i32 1, i64 %33, i32* %23)
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i64 %37)
br label %32
39: ; preds = %32
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%41 = tail call i32 @close(i32* %13)
%42 = tail call i32 @close(i32* %23)
br label %43
43: ; preds = %15, %39, %25, %7
%44 = phi i32 [ 1, %7 ], [ 2, %15 ], [ 3, %25 ], [ 0, %39 ]
ret i32 %44
}