#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_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int rd_fd, wr_fd;
  char read_buf[128] = {0};
  int rd_ret = 0;
  if (argc < 3) {
    printf("please input src file and des file\n");
    return -1;
  }
  rd_fd = open(argv[1], O_RDONLY);
  if (rd_fd < 0) {
    printf("open src file %s failure\n", argv[1]);
    return -2;
  }
  printf("open src file %s success, rd_fd=%d\n", argv[1], rd_fd);
  wr_fd = open(argv[2], O_CREAT | O_RDWR, 0777);
  if (wr_fd < 0) {
    printf("open des file %s failure\n", argv[2]);
    return -3;
  }
  printf("open des file %s success, wr_fd=%d\n", argv[2], wr_fd);
  while (1) {
    rd_ret = read(rd_fd, read_buf, 128);
    if (rd_ret < 128) {
      break;
    }
    write(wr_fd, read_buf, rd_ret);
    memset(read_buf, 0, 128);
  }
  write(wr_fd, read_buf, rd_ret);
  close(rd_fd);
  close(wr_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
movl   $0x0,-0xa4(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ba <main+0x5a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1310 <main+0x1b0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1201 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1310 <main+0x1b0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    126f <main+0x10f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    1310 <main+0x1b0>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x18(%rbp),%edx
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1070 <read@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x80,-0xa4(%rbp)
jge    12b7 <main+0x157>
jmp    12e4 <main+0x184>
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa4(%rbp),%edx
call   1030 <write@plt>
lea    -0xa0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
jmp    1288 <main+0x128>
mov    -0x18(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa4(%rbp),%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
jg     11c3 <main+0x53>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    12d7 <main+0x167>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1090 <open@plt>
mov    0x8(%r14),%rsi
test   %eax,%eax
js     12ad <main+0x13d>
mov    %eax,%r15d
lea    0xe2a(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r14),%rdi
mov    0x2df4(%rip),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1090 <open@plt>
mov    0x10(%r14),%rsi
test   %eax,%eax
js     12c3 <main+0x153>
mov    %eax,%ebp
lea    0xe28(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x80,%eax
jl     1290 <main+0x120>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1080 <read@plt>
cmp    $0x7f,%eax
jg     1260 <main+0xf0>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %ebp,%edi
call   1070 <close@plt>
jmp    12d7 <main+0x167>
lea    0xd4c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffe,%r14d
jmp    12d7 <main+0x167>
lea    0xd74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffd,%r14d
mov    %r14d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"please input src file and des file\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"open src file %s failure\0A\00"
@.str.2 = [36 x i8] c"open src file %s success, rd_fd=%d\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.3 = [26 x i8] c"open des file %s failure\0A\00"
@.str.4 = [36 x i8] c"open des file %s success, wr_fd=%d\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 [128 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [128 x i8]* %8 to i8*
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %77
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 (i8*, i32, ...) @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -2, i32* %3
br label %77
28: ; preds = %15
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = load i32, i32* %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32)
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_CREAT
%38 = load i32, i32* @O_RDWR
%39 = or i32 %37, %38
%40 = call i32 (i8*, i32, ...) @open(i8* %36, i32 %39, i32 511)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %28
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 2
%46 = load i8*, i8** %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %46)
store i32 -3, i32* %3
br label %77
48: ; preds = %28
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i32, i32* %7
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %51, i32 %52)
br label %54
54: ; preds = %48, %61
%55 = load i32, i32* %6
%56 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 128)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = icmp slt i32 %58, 128
br i1 %59, label %60, label %61
60: ; preds = %54
br label %68
61: ; preds = %54
%62 = load i32, i32* %7
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%64 = load i32, i32* %9
%65 = call i32 @write(i32 %62, i8* %63, i32 %64)
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 128)
br label %54
68: ; preds = %60
%69 = load i32, i32* %7
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%71 = load i32, i32* %9
%72 = call i32 @write(i32 %69, i8* %70, i32 %71)
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
%75 = load i32, i32* %7
%76 = call i32 @close(i32 %75)
store i32 0, i32* %3
br label %77
77: ; preds = %68, %43, %23, %13
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [26 x i8] c"open src file %s failure\0A\00"
@.str.2 = [36 x i8] c"open src file %s success, rd_fd=%d\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.3 = [26 x i8] c"open des file %s failure\0A\00"
@.str.4 = [36 x i8] c"open des file %s success, wr_fd=%d\0A\00"
@str = [35 x i8] c"please input src file and des file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %44
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 (i8*, i32, ...) @open(i8* %10, i32 %11)
%13 = icmp slt i32 %12, 0
%14 = load i8*, i8** %9
br i1 %13, label %15, label %17
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %44
17: ; preds = %8
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %14, i32 %12)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @O_RDWR
%23 = or i32 %22, %21
%24 = tail call i32 (i8*, i32, ...) @open(i8* %20, i32 %23, i32 511)
%25 = icmp slt i32 %24, 0
%26 = load i8*, i8** %19
br i1 %25, label %27, label %29
27: ; preds = %17
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %26)
br label %44
29: ; preds = %17
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* %26, i32 %24)
%31 = call i32 @read(i32 %12, i8* %4, i32 128)
%32 = icmp slt i32 %31, 128
br i1 %32, label %39, label %33
33: ; preds = %29, %33
%34 = phi i32 [ %37, %33 ], [ %31, %29 ]
%35 = call i32 @write(i32 %24, i8* %4, i32 %34)
%36 = call i32 @memset(i8* %4, i32 0, i32 128)
%37 = call i32 @read(i32 %12, i8* %4, i32 128)
%38 = icmp slt i32 %37, 128
br i1 %38, label %39, label %33
39: ; preds = %33, %29
%40 = phi i32 [ %31, %29 ], [ %37, %33 ]
%41 = call i32 @write(i32 %24, i8* %4, i32 %40)
%42 = call i32 @close(i32 %12)
%43 = call i32 @close(i32 %24)
br label %44
44: ; preds = %39, %27, %15, %6
%45 = phi i32 [ -1, %6 ], [ -2, %15 ], [ -3, %27 ], [ 0, %39 ]
ret i32 %45
}