#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_WRONLY;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fstat(int, struct stat *);
char *getcwd(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ read(int, ...);
int write(int, ...);
int main(int argc, char *argv[]) {
  int fd, rd, wr, op, rop, ch, des, test, mk, cr;
  struct stat SourceFileInfo, DistFileInfo, TesterInfo;
  char buff[5], i;
  char destpath[20];
  char PresentPath[50];
  char *cwd;
  if (argc != 3) {
    cwd = getcwd(PresentPath, 1024);
    test = open(argv[argc - 1], O_RDONLY);
    fstat(test, &TesterInfo);
    if (S_ISDIR(TesterInfo.st_mode)) {
      for (i = 1; i < argc - 1; i++) {
        op = open(argv[i], O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
        chdir(argv[argc - 1]);
        cr = open(argv[i], O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
        while (rd = (read(op, &buff, 5)) > 0) {
          wr = write(cr, &buff, 5);
        }
        close(cr);
        chdir(cwd);
        close(op);
      }
    } else if (argc == 2)
      printf("%s :missing destination file operand after ‘%s’ \n Try 'cp "
             "--help' for more information.\n",
             *(argv + 0), *(argv + 1));
    else if (argc == 1)
      printf(
          "%s :missing file operand \nTry 'cp --help' for more information.\n",
          argv[0]);
    else
      printf("%s: target ‘%s’ is not a directory\n", *argv,
             *(argv + (argc - 1)));
  } else {
    op = open(argv[1], O_RDONLY);
    fstat(op, &SourceFileInfo);
    if (S_ISDIR(SourceFileInfo.st_mode)) {
      printf("%s: omitting directory ‘%s'\n", argv[0], argv[1]);
    }
    if (op < 0) {
      perror("file not open\n");
      exit(1);
    }
    des = open(argv[2], O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
    fstat(des, &DistFileInfo);
    if (S_ISDIR(DistFileInfo.st_mode)) {
      ch = chdir(argv[2]);
      rop = open(argv[1], O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
    } else {
      rop = open(argv[2], O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
    }
    if (rop < 0) {
      perror("creating file fail");
      exit(1);
    }
    while ((rd = read(op, buff, 5)) > 0) {
      if (rd < 0) {
        perror("read file");
        exit(1);
      }
      wr = write(rop, buff, rd);
      if (wr < 0) {
        perror("writing fial");
        exit(1);
      }
    }
    close(op);
    close(rop);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     13d8 <main+0x228>
lea    -0xb0(%rbp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
mov    %rax,-0xb8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edi
lea    -0x50(%rbp),%rsi
call   10d0 <fstat@plt>
mov    -0x50(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1353 <main+0x1a3>
movb   $0x1,-0x56(%rbp)
movsbl -0x56(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    134e <main+0x19e>
mov    -0x10(%rbp),%rax
movsbq -0x56(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
mov    0x2d78(%rip),%rax
mov    (%rax),%edx
mov    0x2d67(%rip),%rax
or     (%rax),%edx
mov    0x2d76(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rax
movsbq -0x56(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d08(%rip),%rax
mov    (%rax),%esi
mov    0x2d47(%rip),%rax
or     (%rax),%esi
mov    0x2d1e(%rip),%rax
mov    (%rax),%edx
mov    0x2d0d(%rip),%rax
or     (%rax),%edx
mov    0x2d1c(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1090 <read@plt>
cmp    $0x0,%rax
setg   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x18(%rbp)
test   $0x1,%al
jne    130a <main+0x15a>
jmp    1325 <main+0x175>
mov    -0x38(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
jmp    12d8 <main+0x128>
mov    -0x38(%rbp),%edi
call   1080 <close@plt>
mov    -0xb8(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x56(%rbp),%al
add    $0x1,%al
mov    %al,-0x56(%rbp)
jmp    1231 <main+0x81>
jmp    13d3 <main+0x223>
cmpl   $0x2,-0x8(%rbp)
jne    137f <main+0x1cf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc8d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ce <main+0x21e>
cmpl   $0x1,-0x8(%rbp)
jne    13a3 <main+0x1f3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13c9 <main+0x219>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13ce <main+0x21e>
jmp    13d3 <main+0x223>
jmp    15e9 <main+0x439>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2be1(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   10d0 <fstat@plt>
mov    -0x40(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     142e <main+0x27e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jge    144e <main+0x29e>
lea    0xca6(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2b6b(%rip),%rax
mov    (%rax),%esi
mov    0x2b72(%rip),%rax
mov    (%rax),%edx
mov    0x2b61(%rip),%rax
or     (%rax),%edx
mov    0x2b70(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x48(%rbp),%rsi
call   10d0 <fstat@plt>
mov    -0x48(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     14f6 <main+0x346>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <chdir@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2aef(%rip),%rax
mov    (%rax),%esi
mov    0x2b2e(%rip),%rax
or     (%rax),%esi
mov    0x2b05(%rip),%rax
mov    (%rax),%edx
mov    0x2af4(%rip),%rax
or     (%rax),%edx
mov    0x2b03(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
jmp    1535 <main+0x385>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2aab(%rip),%rax
mov    (%rax),%esi
mov    0x2aea(%rip),%rax
or     (%rax),%esi
mov    0x2ac1(%rip),%rax
mov    (%rax),%edx
mov    0x2ab0(%rip),%rax
or     (%rax),%edx
mov    0x2abf(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1555 <main+0x3a5>
lea    0xbae(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    155a <main+0x3aa>
mov    -0x20(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    15d2 <main+0x422>
cmpl   $0x0,-0x18(%rbp)
jge    1599 <main+0x3e9>
lea    0xb7d(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x24(%rbp),%edi
lea    -0x55(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    15cd <main+0x41d>
lea    0xb53(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    155a <main+0x3aa>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     1370 <main+0x1c0>
mov    %edi,%ebp
lea    0x30(%rsp),%rdi
mov    $0x400,%esi
call   1070 <getcwd@plt>
mov    %rax,0x28(%rsp)
movslq %ebp,%r15
mov    -0x8(%r14,%r15,8),%rdi
add    $0xffffffffffffffff,%r15
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10a0 <open@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     131d <main+0x16d>
mov    %r14,0x20(%rsp)
cmp    $0x3,%ebp
jl     135f <main+0x1af>
mov    $0x1,%r14b
lea    0x13(%rsp),%r12
mov    %r15,0x18(%rsp)
mov    0x20(%rsp),%r13
jmp    126e <main+0xbe>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1080 <close@plt>
mov    0x28(%rsp),%rdi
call   1040 <chdir@plt>
mov    %ebx,%edi
call   1080 <close@plt>
add    $0x1,%r14b
movsbl %r14b,%eax
mov    0x18(%rsp),%r15
cmp    %eax,%r15d
jle    135f <main+0x1af>
movsbq %r14b,%rbp
mov    0x0(%r13,%rbp,8),%rdi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
mov    0x2d48(%rip),%rax
or     (%rax),%edx
mov    0x2d4f(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%ebx
mov    0x0(%r13,%r15,8),%rdi
call   1040 <chdir@plt>
mov    0x0(%r13,%rbp,8),%rdi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
mov    0x2ced(%rip),%rax
or     (%rax),%esi
mov    0x2d04(%rip),%rax
mov    (%rax),%edx
mov    0x2d03(%rip),%rax
or     (%rax),%edx
mov    0x2d0a(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%ebp
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1090 <read@plt>
test   %rax,%rax
jle    1240 <main+0x90>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1030 <write@plt>
jmp    12f0 <main+0x140>
cmp    $0x1,%ebp
je     1337 <main+0x187>
cmp    $0x2,%ebp
jne    134a <main+0x19a>
mov    (%r14),%rsi
mov    0x8(%r14),%rdx
lea    0xccb(%rip),%rdi
jmp    1358 <main+0x1a8>
mov    (%r14),%rsi
lea    0xd1c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    135f <main+0x1af>
mov    (%r14),%rsi
mov    (%r14,%r15,8),%rdx
lea    0xd46(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%r13
mov    0x8(%r14),%rdi
mov    0x2c4a(%rip),%rbp
mov    0x0(%rbp),%esi
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%r14d
lea    0x30(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
mov    0x30(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     13bb <main+0x20b>
mov    0x0(%r13),%rsi
mov    0x8(%r13),%rdx
lea    0xd12(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r14d,%r14d
jns    13cc <main+0x21c>
lea    0xd1e(%rip),%rdi
jmp    1489 <main+0x2d9>
mov    %r13,%rbx
mov    0x10(%r13),%rdi
mov    0x2bfe(%rip),%r12
mov    0x2bef(%rip),%r15
mov    (%r15),%edx
or     (%r12),%edx
mov    0x0(%rbp),%esi
mov    0x2bf6(%rip),%rbp
or     0x0(%rbp),%edx
xor    %eax,%eax
call   10a0 <open@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
mov    0x10(%r13),%rdi
test   %rax,%rax
je     1423 <main+0x273>
call   1040 <chdir@plt>
mov    0x8(%r13),%rdi
mov    0x2b86(%rip),%rax
mov    0x2bc7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    (%r15),%edx
or     (%r12),%edx
or     0x0(%rbp),%edx
xor    %eax,%eax
call   10a0 <open@plt>
test   %eax,%eax
jns    1453 <main+0x2a3>
lea    0xca3(%rip),%rdi
jmp    1489 <main+0x2d9>
mov    %eax,%ebx
lea    0x13(%rsp),%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1090 <read@plt>
test   %eax,%eax
jle    1498 <main+0x2e8>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
test   %eax,%eax
jns    145a <main+0x2aa>
lea    0xc7e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [93 x i8] c"%s :missing destination file operand after \E2\80\98%s\E2\80\99 \0A Try 'cp --help' for more information.\0A\00"
@.str.1 = [65 x i8] c"%s :missing file operand \0ATry 'cp --help' for more information.\0A\00"
@.str.2 = [40 x i8] c"%s: target \E2\80\98%s\E2\80\99 is not a directory\0A\00"
@.str.3 = [31 x i8] c"%s: omitting directory \E2\80\98%s'\0A\00"
@.str.4 = [15 x i8] c"file not open\0A\00"
@.str.5 = [19 x i8] c"creating file fail\00"
@.str.6 = [10 x i8] c"read file\00"
@.str.7 = [13 x i8] c"writing fial\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.stat
%17 = alloca %struct.stat
%18 = alloca %struct.stat
%19 = alloca [5 x i8]
%20 = alloca i8
%21 = alloca [20 x i8]
%22 = alloca [50 x i8]
%23 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* %4
%25 = icmp ne i32 %24, 3
br i1 %25, label %26, label %135
26: ; preds = %2
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %22, i64 0, i64 0
%28 = call i8* @getcwd(i8* %27, i32 1024)
store i8* %28, i8** %23
%29 = load i8**, i8*** %5
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %29, i64 %32
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_RDONLY
%36 = call i32 (i8*, i32, ...) @open(i8* %34, i32 %35)
store i32 %36, i32* %13
%37 = load i32, i32* %13
%38 = call i32 @fstat(i32 %37, %struct.stat* %18)
%39 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISDIR(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %103
43: ; preds = %26
store i8 1, i8* %20
br label %44
44: ; preds = %99, %43
%45 = load i8, i8* %20
%46 = sext i8 %45 to i32
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %102
50: ; preds = %44
%51 = load i8**, i8*** %5
%52 = load i8, i8* %20
%53 = sext i8 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = load i32, i32* @O_RDONLY
%57 = load i32, i32* @S_IRWXU
%58 = load i32, i32* @S_IRWXG
%59 = or i32 %57, %58
%60 = load i32, i32* @S_IRWXO
%61 = or i32 %59, %60
%62 = call i32 (i8*, i32, ...) @open(i8* %55, i32 %56, i32 %61)
store i32 %62, i32* %9
%63 = load i8**, i8*** %5
%64 = load i32, i32* %4
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %63, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @chdir(i8* %68)
%70 = load i8**, i8*** %5
%71 = load i8, i8* %20
%72 = sext i8 %71 to i64
%73 = getelementptr inbounds i8*, i8** %70, i64 %72
%74 = load i8*, i8** %73
%75 = load i32, i32* @O_WRONLY
%76 = load i32, i32* @O_CREAT
%77 = or i32 %75, %76
%78 = load i32, i32* @S_IRWXU
%79 = load i32, i32* @S_IRWXG
%80 = or i32 %78, %79
%81 = load i32, i32* @S_IRWXO
%82 = or i32 %80, %81
%83 = call i32 (i8*, i32, ...) @open(i8* %74, i32 %77, i32 %82)
store i32 %83, i32* %15
br label %84
84: ; preds = %89, %50
%85 = load i32, i32* %9
%86 = call i64 (i32, ...) @read(i32 %85, [5 x i8]* %19, i32 5)
%87 = icmp sgt i64 %86, 0
%88 = zext i1 %87 to i32
store i32 %88, i32* %7
br i1 %87, label %89, label %92
89: ; preds = %84
%90 = load i32, i32* %15
%91 = call i32 (i32, ...) @write(i32 %90, [5 x i8]* %19, i32 5)
store i32 %91, i32* %8
br label %84
92: ; preds = %84
%93 = load i32, i32* %15
%94 = call i32 @close(i32 %93)
%95 = load i8*, i8** %23
%96 = call i32 @chdir(i8* %95)
%97 = load i32, i32* %9
%98 = call i32 @close(i32 %97)
br label %99
99: ; preds = %92
%100 = load i8, i8* %20
%101 = add i8 %100, 1
store i8 %101, i8* %20
br label %44
102: ; preds = %44
br label %134
103: ; preds = %26
%104 = load i32, i32* %4
%105 = icmp eq i32 %104, 2
br i1 %105, label %106, label %114
106: ; preds = %103
%107 = load i8**, i8*** %5
%108 = getelementptr inbounds i8*, i8** %107, i64 0
%109 = load i8*, i8** %108
%110 = load i8**, i8*** %5
%111 = getelementptr inbounds i8*, i8** %110, i64 1
%112 = load i8*, i8** %111
%113 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8* %109, i8* %112)
br label %133
114: ; preds = %103
%115 = load i32, i32* %4
%116 = icmp eq i32 %115, 1
br i1 %116, label %117, label %122
117: ; preds = %114
%118 = load i8**, i8*** %5
%119 = getelementptr inbounds i8*, i8** %118, i64 0
%120 = load i8*, i8** %119
%121 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %120)
br label %132
122: ; preds = %114
%123 = load i8**, i8*** %5
%124 = load i8*, i8** %123
%125 = load i8**, i8*** %5
%126 = load i32, i32* %4
%127 = sub nsw i32 %126, 1
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds i8*, i8** %125, i64 %128
%130 = load i8*, i8** %129
%131 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %124, i8* %130)
br label %132
132: ; preds = %122, %117
br label %133
133: ; preds = %132, %106
br label %134
134: ; preds = %133, %102
br label %244
135: ; preds = %2
%136 = load i8**, i8*** %5
%137 = getelementptr inbounds i8*, i8** %136, i64 1
%138 = load i8*, i8** %137
%139 = load i32, i32* @O_RDONLY
%140 = call i32 (i8*, i32, ...) @open(i8* %138, i32 %139)
store i32 %140, i32* %9
%141 = load i32, i32* %9
%142 = call i32 @fstat(i32 %141, %struct.stat* %16)
%143 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%144 = load i32, i32* %143
%145 = call i64 @S_ISDIR(i32 %144)
%146 = icmp ne i64 %145, 0
br i1 %146, label %147, label %155
147: ; preds = %135
%148 = load i8**, i8*** %5
%149 = getelementptr inbounds i8*, i8** %148, i64 0
%150 = load i8*, i8** %149
%151 = load i8**, i8*** %5
%152 = getelementptr inbounds i8*, i8** %151, i64 1
%153 = load i8*, i8** %152
%154 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %150, i8* %153)
br label %155
155: ; preds = %147, %135
%156 = load i32, i32* %9
%157 = icmp slt i32 %156, 0
br i1 %157, label %158, label %161
158: ; preds = %155
%159 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%160 = call i32 @exit(i32 1)
unreachable
161: ; preds = %155
%162 = load i8**, i8*** %5
%163 = getelementptr inbounds i8*, i8** %162, i64 2
%164 = load i8*, i8** %163
%165 = load i32, i32* @O_RDONLY
%166 = load i32, i32* @S_IRWXU
%167 = load i32, i32* @S_IRWXG
%168 = or i32 %166, %167
%169 = load i32, i32* @S_IRWXO
%170 = or i32 %168, %169
%171 = call i32 (i8*, i32, ...) @open(i8* %164, i32 %165, i32 %170)
store i32 %171, i32* %12
%172 = load i32, i32* %12
%173 = call i32 @fstat(i32 %172, %struct.stat* %17)
%174 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%175 = load i32, i32* %174
%176 = call i64 @S_ISDIR(i32 %175)
%177 = icmp ne i64 %176, 0
br i1 %177, label %178, label %195
178: ; preds = %161
%179 = load i8**, i8*** %5
%180 = getelementptr inbounds i8*, i8** %179, i64 2
%181 = load i8*, i8** %180
%182 = call i32 @chdir(i8* %181)
store i32 %182, i32* %11
%183 = load i8**, i8*** %5
%184 = getelementptr inbounds i8*, i8** %183, i64 1
%185 = load i8*, i8** %184
%186 = load i32, i32* @O_WRONLY
%187 = load i32, i32* @O_CREAT
%188 = or i32 %186, %187
%189 = load i32, i32* @S_IRWXU
%190 = load i32, i32* @S_IRWXG
%191 = or i32 %189, %190
%192 = load i32, i32* @S_IRWXO
%193 = or i32 %191, %192
%194 = call i32 (i8*, i32, ...) @open(i8* %185, i32 %188, i32 %193)
store i32 %194, i32* %10
br label %208
195: ; preds = %161
%196 = load i8**, i8*** %5
%197 = getelementptr inbounds i8*, i8** %196, i64 2
%198 = load i8*, i8** %197
%199 = load i32, i32* @O_WRONLY
%200 = load i32, i32* @O_CREAT
%201 = or i32 %199, %200
%202 = load i32, i32* @S_IRWXU
%203 = load i32, i32* @S_IRWXG
%204 = or i32 %202, %203
%205 = load i32, i32* @S_IRWXO
%206 = or i32 %204, %205
%207 = call i32 (i8*, i32, ...) @open(i8* %198, i32 %201, i32 %206)
store i32 %207, i32* %10
br label %208
208: ; preds = %195, %178
%209 = load i32, i32* %10
%210 = icmp slt i32 %209, 0
br i1 %210, label %211, label %214
211: ; preds = %208
%212 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%213 = call i32 @exit(i32 1)
unreachable
214: ; preds = %208
br label %215
215: ; preds = %237, %214
%216 = load i32, i32* %9
%217 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%218 = call i64 (i32, ...) @read(i32 %216, i8* %217, i32 5)
%219 = trunc i64 %218 to i32
store i32 %219, i32* %7
%220 = icmp sgt i32 %219, 0
br i1 %220, label %221, label %238
221: ; preds = %215
%222 = load i32, i32* %7
%223 = icmp slt i32 %222, 0
br i1 %223, label %224, label %227
224: ; preds = %221
%225 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
%226 = call i32 @exit(i32 1)
unreachable
227: ; preds = %221
%228 = load i32, i32* %10
%229 = getelementptr inbounds [5 x i8], [5 x i8]* %19, i64 0, i64 0
%230 = load i32, i32* %7
%231 = call i32 (i32, ...) @write(i32 %228, i8* %229, i32 %230)
store i32 %231, i32* %8
%232 = load i32, i32* %8
%233 = icmp slt i32 %232, 0
br i1 %233, label %234, label %237
234: ; preds = %227
%235 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%236 = call i32 @exit(i32 1)
unreachable
237: ; preds = %227
br label %215
238: ; preds = %215
%239 = load i32, i32* %9
%240 = call i32 @close(i32 %239)
%241 = load i32, i32* %10
%242 = call i32 @close(i32 %241)
%243 = call i32 @exit(i32 0)
unreachable
244: ; preds = %134
%245 = load i32, i32* %3
ret i32 %245
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str = [93 x i8] c"%s :missing destination file operand after \E2\80\98%s\E2\80\99 \0A Try 'cp --help' for more information.\0A\00"
@.str.1 = [65 x i8] c"%s :missing file operand \0ATry 'cp --help' for more information.\0A\00"
@.str.2 = [40 x i8] c"%s: target \E2\80\98%s\E2\80\99 is not a directory\0A\00"
@.str.3 = [31 x i8] c"%s: omitting directory \E2\80\98%s'\0A\00"
@.str.4 = [15 x i8] c"file not open\0A\00"
@.str.5 = [19 x i8] c"creating file fail\00"
@.str.7 = [13 x i8] c"writing fial\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca %struct.stat
%6 = alloca [5 x i8]
%7 = alloca [50 x i8]
%8 = bitcast %struct.stat* %3 to i8*
%9 = bitcast %struct.stat* %4 to i8*
%10 = bitcast %struct.stat* %5 to i8*
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%13 = icmp eq i32 %0, 3
br i1 %13, label %79, label %14
14: ; preds = %2
%15 = call i8* @getcwd(i8* %12, i32 1024)
%16 = add nsw i32 %0, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 (i8*, i32, ...) @open(i8* %19, i32 %20)
%22 = call i32 @fstat(i32 %21, %struct.stat* %5)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @S_ISDIR(i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %66, label %27
27: ; preds = %14
%28 = icmp sgt i32 %0, 2
br i1 %28, label %29, label %146
29: ; preds = %27, %59
%30 = phi i8 [ %63, %59 ], [ 1, %27 ]
%31 = sext i8 %30 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* @O_RDONLY
%35 = load i32, i32* @S_IRWXU
%36 = load i32, i32* @S_IRWXG
%37 = or i32 %36, %35
%38 = load i32, i32* @S_IRWXO
%39 = or i32 %37, %38
%40 = call i32 (i8*, i32, ...) @open(i8* %33, i32 %34, i32 %39)
%41 = load i8*, i8** %18
%42 = call i32 @chdir(i8* %41)
%43 = load i8*, i8** %32
%44 = load i32, i32* @O_WRONLY
%45 = load i32, i32* @O_CREAT
%46 = or i32 %45, %44
%47 = load i32, i32* @S_IRWXU
%48 = load i32, i32* @S_IRWXG
%49 = or i32 %48, %47
%50 = load i32, i32* @S_IRWXO
%51 = or i32 %49, %50
%52 = call i32 (i8*, i32, ...) @open(i8* %43, i32 %46, i32 %51)
%53 = call i64 (i32, ...) @read(i32 %40, [5 x i8]* %6, i32 5)
%54 = icmp sgt i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %29, %55
%56 = call i32 (i32, ...) @write(i32 %52, [5 x i8]* %6, i32 5)
%57 = call i64 (i32, ...) @read(i32 %40, [5 x i8]* %6, i32 5)
%58 = icmp sgt i64 %57, 0
br i1 %58, label %55, label %59
59: ; preds = %55, %29
%60 = call i32 @close(i32 %52)
%61 = call i32 @chdir(i8* %15)
%62 = call i32 @close(i32 %40)
%63 = add i8 %30, 1
%64 = sext i8 %63 to i32
%65 = icmp sgt i32 %16, %64
br i1 %65, label %29, label %146
66: ; preds = %14
switch i32 %0, label %75 [
i32 2, label %67
i32 1, label %72
]
67: ; preds = %66
%68 = load i8*, i8** %1
%69 = getelementptr inbounds i8*, i8** %1, i64 1
%70 = load i8*, i8** %69
%71 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0), i8* %68, i8* %70)
br label %146
72: ; preds = %66
%73 = load i8*, i8** %1
%74 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %73)
br label %146
75: ; preds = %66
%76 = load i8*, i8** %1
%77 = load i8*, i8** %18
%78 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %76, i8* %77)
br label %146
79: ; preds = %2
%80 = getelementptr inbounds i8*, i8** %1, i64 1
%81 = load i8*, i8** %80
%82 = load i32, i32* @O_RDONLY
%83 = tail call i32 (i8*, i32, ...) @open(i8* %81, i32 %82)
%84 = call i32 @fstat(i32 %83, %struct.stat* %3)
%85 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%86 = load i32, i32* %85
%87 = tail call i64 @S_ISDIR(i32 %86)
%88 = icmp eq i64 %87, 0
br i1 %88, label %93, label %89
89: ; preds = %79
%90 = load i8*, i8** %1
%91 = load i8*, i8** %80
%92 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %90, i8* %91)
br label %93
93: ; preds = %89, %79
%94 = icmp slt i32 %83, 0
br i1 %94, label %95, label %98
95: ; preds = %93
%96 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%97 = tail call i32 @exit(i32 1)
unreachable
98: ; preds = %93
%99 = getelementptr inbounds i8*, i8** %1, i64 2
%100 = load i8*, i8** %99
%101 = load i32, i32* @O_RDONLY
%102 = load i32, i32* @S_IRWXU
%103 = load i32, i32* @S_IRWXG
%104 = or i32 %103, %102
%105 = load i32, i32* @S_IRWXO
%106 = or i32 %104, %105
%107 = tail call i32 (i8*, i32, ...) @open(i8* %100, i32 %101, i32 %106)
%108 = call i32 @fstat(i32 %107, %struct.stat* %4)
%109 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%110 = load i32, i32* %109
%111 = tail call i64 @S_ISDIR(i32 %110)
%112 = icmp eq i64 %111, 0
%113 = load i8*, i8** %99
br i1 %112, label %117, label %114
114: ; preds = %98
%115 = tail call i32 @chdir(i8* %113)
%116 = load i8*, i8** %80
br label %117
117: ; preds = %98, %114
%118 = phi i8* [ %116, %114 ], [ %113, %98 ]
%119 = load i32, i32* @O_WRONLY
%120 = load i32, i32* @O_CREAT
%121 = or i32 %120, %119
%122 = load i32, i32* @S_IRWXU
%123 = load i32, i32* @S_IRWXG
%124 = or i32 %123, %122
%125 = load i32, i32* @S_IRWXO
%126 = or i32 %124, %125
%127 = tail call i32 (i8*, i32, ...) @open(i8* %118, i32 %121, i32 %126)
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %117
%130 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%131 = tail call i32 @exit(i32 1)
unreachable
132: ; preds = %117, %136
%133 = call i64 (i32, ...) @read(i32 %83, i8* %11, i32 5)
%134 = trunc i64 %133 to i32
%135 = icmp sgt i32 %134, 0
br i1 %135, label %136, label %142
136: ; preds = %132
%137 = call i32 (i32, ...) @write(i32 %127, i8* %11, i32 %134)
%138 = icmp slt i32 %137, 0
br i1 %138, label %139, label %132
139: ; preds = %136
%140 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%141 = call i32 @exit(i32 1)
unreachable
142: ; preds = %132
%143 = call i32 @close(i32 %83)
%144 = call i32 @close(i32 %127)
%145 = call i32 @exit(i32 0)
unreachable
146: ; preds = %59, %27, %72, %75, %67
ret i32 0
}