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

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ chdir(char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
char *getcwd(char *, int);
scalar_t__ mkdir(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int strlen(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int i, fd, fd1, fd2, ret;
  char buff[10];
  const char *path;
  char *temp;
  char PresentPath[50];
  char *cwd;
  DIR *op;
  if (argc == 1) {
    printf(
        "cp: missing file operand\nTry 'cp --help' for more information. \n");
    exit(1);
  }
  if (argc == 2) {
    printf("missing destination file operand after '%s'\n Try 'cp --help' for "
           "more information\n ",
           argv[1]);
    exit(1);
  }
  if (argc == 3) {
    if ((fd1 = open(argv[1], O_RDONLY)) < 0) {
      perror(" source file does not exist");
      exit(1);
    }
    if ((fd2 = open(argv[2], O_WRONLY | O_CREAT, 0777)) < 0) {
      perror("destination file creation fails");
      exit(1);
    }
    while ((ret = read(fd1, buff, 10)) > 0) {
      if (write(fd2, buff, ret) != ret) {
        printf(" write error");
        exit(1);
      }
      if (ret == 0) {
        close(fd2);
        close(fd1);
        exit(0);
      }
    }
  }
  if ((*(argv[argc - 1]) == '/') &&
      (*(argv[argc - 1] + strlen(argv[argc - 1]) - 1) == '/')) {
    cwd = getcwd(PresentPath, 1024);
    if (mkdir(argv[argc - 1], 0777) < 0) {
      printf("directory creation fails\n");
      exit(1);
    }
    for (i = 1; i <= argc - 2; i++) {
      if ((fd1 = open(argv[i], O_RDONLY)) < 0) {
        perror(" File opening error");
        exit(1);
      }
      path = argv[argc - 1];
      if (chdir(path) == 0) {
        if ((fd2 = open(argv[i], O_WRONLY | O_CREAT, 0777)) < 0) {
          perror(" file creation in directory fails");
          exit(1);
        }
        while ((ret = read(fd1, buff, 10)) != 0) {
          if (write(fd2, buff, ret) != ret) {
            printf(" write error");
            exit(1);
          }
        }
      }
      close(fd2);
      close(fd1);
      chdir(cwd);
    }
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11eb <main+0x3b>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1215 <main+0x65>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jne    131e <main+0x16e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1259 <main+0xa9>
lea    0xe4b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d60(%rip),%rax
mov    (%rax),%esi
mov    0x2d87(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    12a1 <main+0xf1>
lea    0xe1f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    12a6 <main+0xf6>
mov    -0x1c(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jle    1319 <main+0x169>
mov    -0x20(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
cmp    -0x24(%rbp),%eax
je     12f3 <main+0x143>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
jne    1314 <main+0x164>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
jmp    12a6 <main+0xf6>
jmp    131e <main+0x16e>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    152b <main+0x37b>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x98(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    152b <main+0x37b>
lea    -0x80(%rbp),%rdi
mov    $0x400,%esi
call   1080 <getcwd@plt>
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jge    13d5 <main+0x225>
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     1524 <main+0x374>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2be0(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    142b <main+0x27b>
lea    0xcdc(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%eax
jne    14fa <main+0x34a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2b63(%rip),%rax
mov    (%rax),%esi
mov    0x2b8a(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
mov    $0x0,%al
call   10b0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    149e <main+0x2ee>
lea    0xc7d(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    14a3 <main+0x2f3>
mov    -0x1c(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     14f5 <main+0x345>
mov    -0x20(%rbp),%edi
lea    -0x2e(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <write@plt>
cmp    -0x24(%rbp),%eax
je     14f0 <main+0x340>
lea    0xbf2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    14a3 <main+0x2f3>
jmp    14fa <main+0x34a>
mov    -0x20(%rbp),%edi
call   1090 <close@plt>
mov    -0x1c(%rbp),%edi
call   1090 <close@plt>
mov    -0x88(%rbp),%rdi
call   1060 <chdir@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13dc <main+0x22c>
xor    %edi,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
add    $0xa0,%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,%r15
mov    %edi,%r12d
cmp    $0x3,%edi
je     1224 <main+0x64>
cmp    $0x2,%r12d
je     12c3 <main+0x103>
cmp    $0x1,%r12d
je     12df <main+0x11f>
lea    -0x1(%r12),%ebp
movslq %ebp,%r14
mov    (%r15,%r14,8),%rbx
cmpb   $0x2f,(%rbx)
jne    1213 <main+0x53>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rbx,%rax,1)
je     12e8 <main+0x128>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r15),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     1325 <main+0x165>
mov    %eax,%r14d
mov    0x10(%r15),%rdi
mov    0x2d7a(%rip),%rax
mov    0x2da3(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     132e <main+0x16e>
mov    %eax,%r13d
lea    0x26(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   10b0 <read@plt>
test   %eax,%eax
jle    11ed <main+0x2d>
mov    %eax,%ebx
mov    %r13d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebx,%eax
je     1280 <main+0xc0>
lea    0xdde(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x8(%r15),%rsi
lea    0xd32(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xe06(%rip),%rdi
jmp    1316 <main+0x156>
lea    0x30(%rsp),%rdi
mov    $0x400,%esi
call   1090 <getcwd@plt>
mov    %rax,0x18(%rsp)
mov    (%r15,%r14,8),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jns    1344 <main+0x184>
lea    0xdbd(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd28(%rip),%rdi
jmp    1335 <main+0x175>
lea    0xd3b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmp    $0x3,%r12d
jge    1351 <main+0x191>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    %ebp,%ebp
mov    $0x1,%eax
lea    0x26(%rsp),%r12
mov    %rbp,0x10(%rsp)
jmp    1390 <main+0x1d0>
mov    0x10(%rsp),%rbp
mov    %r13d,%edi
call   10a0 <close@plt>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    0x18(%rsp),%rdi
call   1070 <chdir@plt>
mov    0x8(%rsp),%rax
add    $0x1,%rax
cmp    %rbp,%rax
je     134a <main+0x18a>
mov    %rax,0x8(%rsp)
mov    (%r15,%rax,8),%rdi
mov    0x2c40(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10c0 <open@plt>
test   %eax,%eax
js     1419 <main+0x259>
mov    %eax,%ebx
mov    (%r15,%r14,8),%rdi
call   1070 <chdir@plt>
test   %eax,%eax
jne    1369 <main+0x1a9>
mov    0x8(%rsp),%rax
mov    (%r15,%rax,8),%rdi
mov    0x2c2c(%rip),%rax
mov    (%rax),%esi
mov    0x2bf3(%rip),%rax
or     (%rax),%esi
mov    $0x1ff,%edx
xor    %eax,%eax
call   10c0 <open@plt>
mov    %eax,%r13d
test   %eax,%eax
js     1425 <main+0x265>
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0xa,%edx
call   10b0 <read@plt>
test   %eax,%eax
je     1364 <main+0x1a4>
mov    %eax,%ebp
mov    %r13d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebp,%eax
je     13ea <main+0x22a>
jmp    12ab <main+0xeb>
lea    0xc7d(%rip),%rdi
jmp    1335 <main+0x175>
lea    0xc85(%rip),%rdi
jmp    1335 <main+0x175>

LLVM IR (-O0):
@.str = [65 x i8] c"cp: missing file operand\0ATry 'cp --help' for more information. \0A\00"
@.str.1 = [84 x i8] c"missing destination file operand after '%s'\0A Try 'cp --help' for more information\0A \00"
@O_RDONLY = global i32 0
@.str.2 = [28 x i8] c" source file does not exist\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.3 = [32 x i8] c"destination file creation fails\00"
@.str.4 = [13 x i8] c" write error\00"
@.str.5 = [26 x i8] c"directory creation fails\0A\00"
@.str.6 = [20 x i8] c" File opening error\00"
@.str.7 = [34 x i8] c" file creation in directory fails\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 [10 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca [50 x i8]
%15 = alloca i8*
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 2
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* %4
%33 = icmp eq i32 %32, 3
br i1 %33, label %34, label %83
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDONLY
%39 = call i32 (i8*, i32, ...) @open(i8* %37, i32 %38)
store i32 %39, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = load i32, i32* @O_WRONLY
%49 = load i32, i32* @O_CREAT
%50 = or i32 %48, %49
%51 = call i32 (i8*, i32, ...) @open(i8* %47, i32 %50, i32 511)
store i32 %51, i32* %9
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %44
%54 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %44
br label %57
57: ; preds = %81, %56
%58 = load i32, i32* %8
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%60 = call i32 @read(i32 %58, i8* %59, i32 10)
store i32 %60, i32* %10
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %82
62: ; preds = %57
%63 = load i32, i32* %9
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%65 = load i32, i32* %10
%66 = call i32 @write(i32 %63, i8* %64, i32 %65)
%67 = load i32, i32* %10
%68 = icmp ne i32 %66, %67
br i1 %68, label %69, label %72
69: ; preds = %62
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %62
%73 = load i32, i32* %10
%74 = icmp eq i32 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %72
%76 = load i32, i32* %9
%77 = call i32 @close(i32 %76)
%78 = load i32, i32* %8
%79 = call i32 @close(i32 %78)
%80 = call i32 @exit(i32 0)
unreachable
81: ; preds = %72
br label %57
82: ; preds = %57
br label %83
83: ; preds = %82, %31
%84 = load i8**, i8*** %5
%85 = load i32, i32* %4
%86 = sub nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8*, i8** %84, i64 %87
%89 = load i8*, i8** %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 47
br i1 %92, label %93, label %199
93: ; preds = %83
%94 = load i8**, i8*** %5
%95 = load i32, i32* %4
%96 = sub nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8*, i8** %94, i64 %97
%99 = load i8*, i8** %98
%100 = load i8**, i8*** %5
%101 = load i32, i32* %4
%102 = sub nsw i32 %101, 1
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds i8*, i8** %100, i64 %103
%105 = load i8*, i8** %104
%106 = call i32 @strlen(i8* %105)
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i8, i8* %99, i64 %107
%109 = getelementptr inbounds i8, i8* %108, i64 -1
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp eq i32 %111, 47
br i1 %112, label %113, label %199
113: ; preds = %93
%114 = getelementptr inbounds [50 x i8], [50 x i8]* %14, i64 0, i64 0
%115 = call i8* @getcwd(i8* %114, i32 1024)
store i8* %115, i8** %15
%116 = load i8**, i8*** %5
%117 = load i32, i32* %4
%118 = sub nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8*, i8** %116, i64 %119
%121 = load i8*, i8** %120
%122 = call i64 @mkdir(i8* %121, i32 511)
%123 = icmp slt i64 %122, 0
br i1 %123, label %124, label %127
124: ; preds = %113
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%126 = call i32 @exit(i32 1)
unreachable
127: ; preds = %113
store i32 1, i32* %6
br label %128
128: ; preds = %194, %127
%129 = load i32, i32* %6
%130 = load i32, i32* %4
%131 = sub nsw i32 %130, 2
%132 = icmp sle i32 %129, %131
br i1 %132, label %133, label %197
133: ; preds = %128
%134 = load i8**, i8*** %5
%135 = load i32, i32* %6
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8*, i8** %134, i64 %136
%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* %8
%141 = icmp slt i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %133
%143 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%144 = call i32 @exit(i32 1)
unreachable
145: ; preds = %133
%146 = load i8**, i8*** %5
%147 = load i32, i32* %4
%148 = sub nsw i32 %147, 1
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i8*, i8** %146, i64 %149
%151 = load i8*, i8** %150
store i8* %151, i8** %12
%152 = load i8*, i8** %12
%153 = call i32 @chdir(i8* %152)
%154 = icmp eq i32 %153, 0
br i1 %154, label %155, label %187
155: ; preds = %145
%156 = load i8**, i8*** %5
%157 = load i32, i32* %6
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8*, i8** %156, i64 %158
%160 = load i8*, i8** %159
%161 = load i32, i32* @O_WRONLY
%162 = load i32, i32* @O_CREAT
%163 = or i32 %161, %162
%164 = call i32 (i8*, i32, ...) @open(i8* %160, i32 %163, i32 511)
store i32 %164, i32* %9
%165 = icmp slt i32 %164, 0
br i1 %165, label %166, label %169
166: ; preds = %155
%167 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%168 = call i32 @exit(i32 1)
unreachable
169: ; preds = %155
br label %170
170: ; preds = %185, %169
%171 = load i32, i32* %8
%172 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%173 = call i32 @read(i32 %171, i8* %172, i32 10)
store i32 %173, i32* %10
%174 = icmp ne i32 %173, 0
br i1 %174, label %175, label %186
175: ; preds = %170
%176 = load i32, i32* %9
%177 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%178 = load i32, i32* %10
%179 = call i32 @write(i32 %176, i8* %177, i32 %178)
%180 = load i32, i32* %10
%181 = icmp ne i32 %179, %180
br i1 %181, label %182, label %185
182: ; preds = %175
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%184 = call i32 @exit(i32 1)
unreachable
185: ; preds = %175
br label %170
186: ; preds = %170
br label %187
187: ; preds = %186, %145
%188 = load i32, i32* %9
%189 = call i32 @close(i32 %188)
%190 = load i32, i32* %8
%191 = call i32 @close(i32 %190)
%192 = load i8*, i8** %15
%193 = call i32 @chdir(i8* %192)
br label %194
194: ; preds = %187
%195 = load i32, i32* %6
%196 = add nsw i32 %195, 1
store i32 %196, i32* %6
br label %128
197: ; preds = %128
%198 = call i32 @exit(i32 0)
unreachable
199: ; preds = %93, %83
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [84 x i8] c"missing destination file operand after '%s'\0A Try 'cp --help' for more information\0A \00"
@O_RDONLY = global i32 0
@.str.2 = [28 x i8] c" source file does not exist\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.3 = [32 x i8] c"destination file creation fails\00"
@.str.4 = [13 x i8] c" write error\00"
@.str.6 = [20 x i8] c" File opening error\00"
@.str.7 = [34 x i8] c" file creation in directory fails\00"
@str = [25 x i8] c"directory creation fails\00"
@str.8 = [64 x i8] c"cp: missing file operand\0ATry 'cp --help' for more information. \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
switch i32 %0, label %44 [
i32 1, label %7
i32 2, label %10
i32 3, label %15
]
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @str.8, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([84 x i8], [84 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = tail call i32 (i8*, i32, ...) @open(i8* %17, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_WRONLY
%28 = load i32, i32* @O_CREAT
%29 = or i32 %28, %27
%30 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %29, i32 511)
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
35: ; preds = %24, %38
%36 = call i32 @read(i32 %19, i8* %5, i32 10)
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = call i32 @write(i32 %30, i8* %5, i32 %36)
%40 = icmp eq i32 %39, %36
br i1 %40, label %35, label %41
41: ; preds = %38
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %35, %2
%45 = phi i32 [ undef, %2 ], [ %30, %35 ]
%46 = add i32 %0, -1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %1, i64 %47
%49 = load i8*, i8** %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 47
br i1 %51, label %52, label %114
52: ; preds = %44
%53 = tail call i32 @strlen(i8* %49)
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %49, i64 %54
%56 = getelementptr inbounds i8, i8* %55, i64 -1
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 47
br i1 %58, label %59, label %114
59: ; preds = %52
%60 = call i8* @getcwd(i8* %6, i32 1024)
%61 = load i8*, i8** %48
%62 = call i64 @mkdir(i8* %61, i32 511)
%63 = icmp slt i64 %62, 0
br i1 %63, label %68, label %64
64: ; preds = %59
%65 = icmp slt i32 %0, 3
br i1 %65, label %112, label %66
66: ; preds = %64
%67 = zext i32 %46 to i64
br label %71
68: ; preds = %59
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %66, %105
%72 = phi i64 [ 1, %66 ], [ %110, %105 ]
%73 = phi i32 [ %45, %66 ], [ %106, %105 ]
%74 = getelementptr inbounds i8*, i8** %1, i64 %72
%75 = load i8*, i8** %74
%76 = load i32, i32* @O_RDONLY
%77 = call i32 (i8*, i32, ...) @open(i8* %75, i32 %76)
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %71
%80 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %71
%83 = load i8*, i8** %48
%84 = call i32 @chdir(i8* %83)
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %105
86: ; preds = %82
%87 = load i8*, i8** %74
%88 = load i32, i32* @O_WRONLY
%89 = load i32, i32* @O_CREAT
%90 = or i32 %89, %88
%91 = call i32 (i8*, i32, ...) @open(i8* %87, i32 %90, i32 511)
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %86
%94 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %86, %99
%97 = call i32 @read(i32 %77, i8* %5, i32 10)
%98 = icmp eq i32 %97, 0
br i1 %98, label %105, label %99
99: ; preds = %96
%100 = call i32 @write(i32 %91, i8* %5, i32 %97)
%101 = icmp eq i32 %100, %97
br i1 %101, label %96, label %102
102: ; preds = %99
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %96, %82
%106 = phi i32 [ %73, %82 ], [ %91, %96 ]
%107 = call i32 @close(i32 %106)
%108 = call i32 @close(i32 %77)
%109 = call i32 @chdir(i8* %60)
%110 = add nuw nsw i64 %72, 1
%111 = icmp eq i64 %110, %67
br i1 %111, label %112, label %71
112: ; preds = %105, %64
%113 = call i32 @exit(i32 0)
unreachable
114: ; preds = %52, %44
ret i32 0
}