#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*/ buf;

/* 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 read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int rd_fd = -1;
  int rd_ret = -1;
  int wr_fd = -1;
  if (argc >= 2) {
    rd_fd = open(argv[1], O_RDONLY);
    if (-1 == rd_fd)
      perror("open");
    wr_fd = open(argv[2], O_WRONLY | O_CREAT, 0777);
    if (-1 == wr_fd)
      perror("open");
    while (1) {
      char buf[100];
      rd_ret = read(rd_fd, buf, sizeof(buf[100]));
      if (0 == rd_ret) {
        break;
      }
      write(wr_fd, buf, rd_ret);
    }
    close(rd_fd);
    close(wr_fd);
  } else {
    printf("文件地址输入错误");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1262 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    11cd <main+0x6d>
lea    0xe38(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    $0xffffffff,%eax
cmp    -0x1c(%rbp),%eax
jne    1210 <main+0xb0>
lea    0xdf5(%rip),%rdi
call   1080 <perror@plt>
jmp    1215 <main+0xb5>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%eax
jne    1239 <main+0xd9>
jmp    124d <main+0xed>
mov    -0x1c(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
jmp    1215 <main+0xb5>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
jmp    127a <main+0x11a>
lea    0xd9c(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1281 <main+0x121>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
cmp    $0x2,%edi
jl     1211 <main+0xb1>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     1228 <main+0xc8>
mov    0x10(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    0x2e52(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   1070 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1239 <main+0xd9>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
je     1200 <main+0xa0>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    11e0 <main+0x80>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    121d <main+0xbd>
lea    0xded(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd1(%rip),%rdi
call   1080 <perror@plt>
jmp    1194 <main+0x34>
lea    0xdc0(%rip),%rdi
call   1080 <perror@plt>
jmp    11bd <main+0x5d>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [25 x i8] c"\E6\96\87\E4\BB\B6\E5\9C\B0\E5\9D\80\E8\BE\93\E5\85\A5\E9\94\99\E8\AF\AF\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 i32
%9 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
%10 = load i32, i32* %4
%11 = icmp sge i32 %10, 2
br i1 %11, label %12, label %52
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = call i32 (i8*, i32, ...) @open(i8* %15, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %22
20: ; preds = %12
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %12
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_WRONLY
%27 = load i32, i32* @O_CREAT
%28 = or i32 %26, %27
%29 = call i32 (i8*, i32, ...) @open(i8* %25, i32 %28, i32 511)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 -1, %30
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %22
br label %35
35: ; preds = %34, %42
%36 = load i32, i32* %6
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 1)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp eq i32 0, %39
br i1 %40, label %41, label %42
41: ; preds = %35
br label %47
42: ; preds = %35
%43 = load i32, i32* %8
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%45 = load i32, i32* %7
%46 = call i32 @write(i32 %43, i8* %44, i32 %45)
br label %35
47: ; preds = %41
%48 = load i32, i32* %6
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %8
%51 = call i32 @close(i32 %50)
br label %54
52: ; preds = %2
%53 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %55
54: ; preds = %47
store i32 0, i32* %3
br label %55
55: ; preds = %54, %52
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.1 = [25 x i8] c"\E6\96\87\E4\BB\B6\E5\9C\B0\E5\9D\80\E8\BE\93\E5\85\A5\E9\94\99\E8\AF\AF\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %35
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 (i8*, i32, ...) @open(i8* %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %5
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* @O_CREAT
%18 = or i32 %17, %16
%19 = tail call i32 (i8*, i32, ...) @open(i8* %15, i32 %18, i32 511)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %13
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%25 = call i32 @read(i32 %9, i8* %24, i32 1)
%26 = icmp eq i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %23, %27
%28 = phi i32 [ %30, %27 ], [ %25, %23 ]
%29 = call i32 @write(i32 %19, i8* %24, i32 %28)
%30 = call i32 @read(i32 %9, i8* %24, i32 1)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %27
32: ; preds = %27, %23
%33 = tail call i32 @close(i32 %9)
%34 = tail call i32 @close(i32 %19)
br label %37
35: ; preds = %2
%36 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %32, %35
ret i32 0
}