#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 st_mode;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int O_CREAT;
int O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
scalar_t__ fstat(int, struct stat *);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
scalar_t__ stat(char *, struct stat *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  struct stat st;
  int dst_exist = 0;
  int dst_isdir = 0;
  int i, n, err, fdin, fdout;
  char buf[512];
  if (argc < 3) {
    printf("cp: file1 file2 file.. dest dir or\n");
    printf("cp: file1 file2\n");
    return 1;
  }
  if (stat(argv[argc - 1], &st) == 0) {
    dst_exist = 1;
    if (st.st_mode & 0040000)
      dst_isdir = 1;
  }
  if (argc > 3 && (dst_exist == 0 || !(st.st_mode & 0040000))) {
    printf("cp: for multiple files, dest %s should be a directory\n",
           argv[argc - 1]);
    return 1;
  }
  err = 0;
  for (i = 1; i < argc - 1; i++) {
    if ((fdin = open(argv[i], O_RDONLY, 0)) < 0) {
      printf("cp: cannot open %s\n", argv[i]);
      err++;
      continue;
    }
    if (fstat(fdin, &st) < 0) {
      printf("cp: cannot stat %s\n", argv[i]);
      close(fdin);
      err++;
      continue;
    }
    if (st.st_mode & 0040000) {
      printf("cp: directory copy not supported: %s\n", argv[i]);
      close(fdin);
      err++;
      continue;
    }
    strncpy(buf, argv[argc - 1], sizeof(buf) - 1);
    if (dst_isdir) {
      strncat(buf, "/", sizeof(buf) - strlen(buf) - 1);
      strncat(buf, argv[i], sizeof(buf - strlen(buf) - 1));
    }
    if ((fdout = open(buf, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode)) < 0) {
      printf("cp: cannot open %s\n", argv[argc - 1]);
      close(fdin);
      err++;
      continue;
    }
    while ((n = read(fdin, buf, sizeof(buf))) > 0) {
      if (write(fdout, buf, n) != n) {
        printf("cp: error in copying %s\n", argv[i]);
        err++;
        break;
      }
    }
    close(fdin);
    close(fdout);
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11f9 <main+0x59>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    150a <main+0x36a>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jne    1241 <main+0xa1>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     123c <main+0x9c>
movl   $0x1,-0x20(%rbp)
jmp    1241 <main+0xa1>
cmpl   $0x3,-0x8(%rbp)
jle    1291 <main+0xf1>
cmpl   $0x0,-0x1c(%rbp)
je     1266 <main+0xc6>
mov    -0x18(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
jne    1291 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    150a <main+0x36a>
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1504 <main+0x364>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <open@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    1300 <main+0x160>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14f6 <main+0x356>
mov    -0x30(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   10c0 <fstat@plt>
cmp    $0x0,%rax
jge    1346 <main+0x1a6>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14f6 <main+0x356>
mov    -0x18(%rbp),%eax
and    $0x4000,%eax
cmp    $0x0,%eax
je     1387 <main+0x1e7>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14f6 <main+0x356>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
cmpl   $0x0,-0x20(%rbp)
je     140e <main+0x26e>
lea    -0x240(%rbp),%rax
mov    %rax,-0x248(%rbp)
lea    -0x240(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x248(%rbp),%rdi
movslq %eax,%rcx
mov    $0x200,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
lea    0xcce(%rip),%rsi
call   1070 <strncat@plt>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    $0x8,%edx
call   1070 <strncat@plt>
lea    -0x240(%rbp),%rdi
mov    0x2ba4(%rip),%rax
mov    (%rax),%esi
mov    0x2bd3(%rip),%rax
or     (%rax),%esi
mov    0x2bc2(%rip),%rax
or     (%rax),%esi
mov    -0x18(%rbp),%edx
call   10b0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1479 <main+0x2d9>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14f6 <main+0x356>
jmp    147e <main+0x2de>
mov    -0x30(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jle    14e6 <main+0x346>
mov    -0x34(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <write@plt>
cmp    -0x28(%rbp),%eax
je     14e1 <main+0x341>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xbf0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14e6 <main+0x346>
jmp    147e <main+0x2de>
mov    -0x30(%rbp),%edi
call   1080 <close@plt>
mov    -0x34(%rbp),%edi
call   1080 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    129f <main+0xff>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
cmp    $0x2,%edi
jg     11e0 <main+0x30>
lea    0xed3(%rip),%rdi
call   1040 <puts@plt>
lea    0xeea(%rip),%rdi
call   1040 <puts@plt>
jmp    123c <main+0x8c>
mov    %rsi,%rbp
mov    %edi,%ebx
lea    -0x1(%rbx),%r14d
mov    (%rsi,%r14,8),%rdi
lea    0x10(%rsp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
je     1208 <main+0x58>
movb   $0x1,0xb(%rsp)
cmp    $0x3,%ebx
ja     1229 <main+0x79>
jmp    1253 <main+0xa3>
mov    $0x4000,%eax
and    0x10(%rsp),%eax
sete   %cl
cmp    $0x4,%ebx
setb   %dl
and    %cl,%dl
mov    %dl,0xb(%rsp)
cmp    $0x4,%ebx
jb     1253 <main+0xa3>
test   %eax,%eax
jne    1253 <main+0xa3>
mov    0x0(%rbp,%r14,8),%rsi
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r13d
mov    0x2d78(%rip),%rbx
lea    0xdd0(%rip),%r15
xor    %eax,%eax
mov    %r14,0x18(%rsp)
jmp    128f <main+0xdf>
mov    0x0(%rbp,%r13,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0xc(%rsp),%eax
add    $0x1,%eax
add    $0x1,%r13
cmp    %r14,%r13
je     1241 <main+0x91>
mov    %eax,0xc(%rsp)
mov    0x0(%rbp,%r13,8),%rdi
mov    (%rbx),%esi
xor    %edx,%edx
call   10c0 <open@plt>
test   %eax,%eax
js     1270 <main+0xc0>
mov    %eax,%r12d
mov    %eax,%edi
lea    0x10(%rsp),%rsi
call   10d0 <fstat@plt>
test   %rax,%rax
js     13c0 <main+0x210>
testb  $0x40,0x11(%rsp)
jne    13ce <main+0x21e>
mov    0x0(%rbp,%r14,8),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
cmpb   $0x0,0xb(%rsp)
jne    1316 <main+0x166>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    $0x1ff,%edx
sub    %eax,%edx
mov    %rbx,%rdi
lea    0xd86(%rip),%rsi
call   1080 <strncat@plt>
mov    0x0(%rbp,%r13,8),%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
call   1080 <strncat@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%esi
mov    0x2c9a(%rip),%rax
or     (%rax),%esi
mov    0x2cc1(%rip),%rax
or     (%rax),%esi
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
call   10c0 <open@plt>
mov    %eax,%r14d
test   %eax,%eax
js     13ee <main+0x23e>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    1391 <main+0x1e1>
mov    %eax,%r15d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %r15d,%eax
je     1350 <main+0x1a0>
mov    0x0(%rbp,%r13,8),%rsi
lea    0xd02(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
addl   $0x1,0xc(%rsp)
mov    %r12d,%edi
call   1090 <close@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    0x18(%rsp),%r14
mov    0x2c2b(%rip),%rbx
lea    0xc83(%rip),%r15
mov    0xc(%rsp),%eax
jmp    1286 <main+0xd6>
nopl   (%rax)
mov    0x0(%rbp,%r13,8),%rsi
lea    0xc7f(%rip),%rdi
jmp    13da <main+0x22a>
mov    0x0(%rbp,%r13,8),%rsi
lea    0xc85(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
jmp    127f <main+0xcf>
mov    0x18(%rsp),%r14
mov    0x0(%rbp,%r14,8),%rsi
lea    0xc38(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0xc(%rsp),%eax
add    $0x1,%eax
mov    0x2bb9(%rip),%rbx
jmp    1286 <main+0xd6>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [36 x i8] c"cp: file1 file2 file.. dest dir or\0A\00"
@.str.1 = [17 x i8] c"cp: file1 file2\0A\00"
@.str.2 = [55 x i8] c"cp: for multiple files, dest %s should be a directory\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [20 x i8] c"cp: cannot open %s\0A\00"
@.str.4 = [20 x i8] c"cp: cannot stat %s\0A\00"
@.str.5 = [38 x i8] c"cp: directory copy not supported: %s\0A\00"
@.str.6 = [2 x i8] c"/\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.7 = [25 x i8] c"cp: error in copying %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %193
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @stat(i8* %26, %struct.stat* %6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %20
store i32 1, i32* %7
%30 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%31 = load i32, i32* %30
%32 = and i32 %31, 16384
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 1, i32* %8
br label %35
35: ; preds = %34, %29
br label %36
36: ; preds = %35, %20
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 3
br i1 %38, label %39, label %55
39: ; preds = %36
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%44 = load i32, i32* %43
%45 = and i32 %44, 16384
%46 = icmp ne i32 %45, 0
br i1 %46, label %55, label %47
47: ; preds = %42, %39
%48 = load i8**, i8*** %5
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %53)
store i32 1, i32* %3
br label %193
55: ; preds = %42, %36
store i32 0, i32* %11
store i32 1, i32* %9
br label %56
56: ; preds = %188, %55
%57 = load i32, i32* %9
%58 = load i32, i32* %4
%59 = sub nsw i32 %58, 1
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %191
61: ; preds = %56
%62 = load i8**, i8*** %5
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8*, i8** %62, i64 %64
%66 = load i8*, i8** %65
%67 = load i32, i32* @O_RDONLY
%68 = call i32 @open(i8* %66, i32 %67, i32 0)
store i32 %68, i32* %12
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %79
70: ; preds = %61
%71 = load i8**, i8*** %5
%72 = load i32, i32* %9
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8*, i8** %71, i64 %73
%75 = load i8*, i8** %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %75)
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %188
79: ; preds = %61
%80 = load i32, i32* %12
%81 = call i64 @fstat(i32 %80, %struct.stat* %6)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %94
83: ; preds = %79
%84 = load i8**, i8*** %5
%85 = load i32, i32* %9
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8*, i8** %84, i64 %86
%88 = load i8*, i8** %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %88)
%90 = load i32, i32* %12
%91 = call i32 @close(i32 %90)
%92 = load i32, i32* %11
%93 = add nsw i32 %92, 1
store i32 %93, i32* %11
br label %188
94: ; preds = %79
%95 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%96 = load i32, i32* %95
%97 = and i32 %96, 16384
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %110
99: ; preds = %94
%100 = load i8**, i8*** %5
%101 = load i32, i32* %9
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i8*, i8** %100, i64 %102
%104 = load i8*, i8** %103
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %104)
%106 = load i32, i32* %12
%107 = call i32 @close(i32 %106)
%108 = load i32, i32* %11
%109 = add nsw i32 %108, 1
store i32 %109, i32* %11
br label %188
110: ; preds = %94
%111 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%112 = load i8**, i8*** %5
%113 = load i32, i32* %4
%114 = sub nsw i32 %113, 1
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8*, i8** %112, i64 %115
%117 = load i8*, i8** %116
%118 = call i32 @strncpy(i8* %111, i8* %117, i32 511)
%119 = load i32, i32* %8
%120 = icmp ne i32 %119, 0
br i1 %120, label %121, label %137
121: ; preds = %110
%122 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%123 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%124 = call i32 @strlen(i8* %123)
%125 = sext i32 %124 to i64
%126 = sub i64 512, %125
%127 = sub i64 %126, 1
%128 = trunc i64 %127 to i32
%129 = call i32 @strncat(i8* %122, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %128)
%130 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%131 = load i8**, i8*** %5
%132 = load i32, i32* %9
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i8*, i8** %131, i64 %133
%135 = load i8*, i8** %134
%136 = call i32 @strncat(i8* %130, i8* %135, i32 8)
br label %137
137: ; preds = %121, %110
%138 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%139 = load i32, i32* @O_WRONLY
%140 = load i32, i32* @O_CREAT
%141 = or i32 %139, %140
%142 = load i32, i32* @O_TRUNC
%143 = or i32 %141, %142
%144 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%145 = load i32, i32* %144
%146 = call i32 @open(i8* %138, i32 %143, i32 %145)
store i32 %146, i32* %13
%147 = icmp slt i32 %146, 0
br i1 %147, label %148, label %160
148: ; preds = %137
%149 = load i8**, i8*** %5
%150 = load i32, i32* %4
%151 = sub nsw i32 %150, 1
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i8*, i8** %149, i64 %152
%154 = load i8*, i8** %153
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %154)
%156 = load i32, i32* %12
%157 = call i32 @close(i32 %156)
%158 = load i32, i32* %11
%159 = add nsw i32 %158, 1
store i32 %159, i32* %11
br label %188
160: ; preds = %137
br label %161
161: ; preds = %182, %160
%162 = load i32, i32* %12
%163 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%164 = call i32 @read(i32 %162, i8* %163, i32 512)
store i32 %164, i32* %10
%165 = icmp sgt i32 %164, 0
br i1 %165, label %166, label %183
166: ; preds = %161
%167 = load i32, i32* %13
%168 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%169 = load i32, i32* %10
%170 = call i32 @write(i32 %167, i8* %168, i32 %169)
%171 = load i32, i32* %10
%172 = icmp ne i32 %170, %171
br i1 %172, label %173, label %182
173: ; preds = %166
%174 = load i8**, i8*** %5
%175 = load i32, i32* %9
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i8*, i8** %174, i64 %176
%178 = load i8*, i8** %177
%179 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %178)
%180 = load i32, i32* %11
%181 = add nsw i32 %180, 1
store i32 %181, i32* %11
br label %183
182: ; preds = %166
br label %161
183: ; preds = %173, %161
%184 = load i32, i32* %12
%185 = call i32 @close(i32 %184)
%186 = load i32, i32* %13
%187 = call i32 @close(i32 %186)
br label %188
188: ; preds = %183, %148, %99, %83, %70
%189 = load i32, i32* %9
%190 = add nsw i32 %189, 1
store i32 %190, i32* %9
br label %56
191: ; preds = %56
%192 = load i32, i32* %11
store i32 %192, i32* %3
br label %193
193: ; preds = %191, %47, %17
%194 = load i32, i32* %3
ret i32 %194
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str.2 = [55 x i8] c"cp: for multiple files, dest %s should be a directory\0A\00"
@O_RDONLY = global i32 0
@.str.3 = [20 x i8] c"cp: cannot open %s\0A\00"
@.str.4 = [20 x i8] c"cp: cannot stat %s\0A\00"
@.str.5 = [38 x i8] c"cp: directory copy not supported: %s\0A\00"
@.str.6 = [2 x i8] c"/\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.7 = [25 x i8] c"cp: error in copying %s\0A\00"
@str = [35 x i8] c"cp: file1 file2 file.. dest dir or\00"
@str.8 = [16 x i8] c"cp: file1 file2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca [512 x i8]
%5 = bitcast %struct.stat* %3 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0))
br label %105
11: ; preds = %2
%12 = add nsw i32 %0, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = call i64 @stat(i8* %15, %struct.stat* %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %11
%19 = icmp ugt i32 %0, 3
br i1 %19, label %29, label %32
20: ; preds = %11
%21 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, 16384
%24 = icmp eq i32 %23, 0
%25 = icmp ult i32 %0, 4
%26 = xor i1 %24, true
%27 = select i1 %25, i1 true, i1 %26
%28 = select i1 %25, i1 %24, i1 false
br i1 %27, label %32, label %29
29: ; preds = %20, %18
%30 = load i8*, i8** %14
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %105
32: ; preds = %20, %18
%33 = phi i1 [ %28, %20 ], [ true, %18 ]
%34 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %35
35: ; preds = %32, %101
%36 = phi i64 [ 1, %32 ], [ %103, %101 ]
%37 = phi i32 [ 0, %32 ], [ %102, %101 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 %36
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDONLY
%41 = call i32 @open(i8* %39, i32 %40, i32 0)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %35
%44 = load i8*, i8** %38
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = add nsw i32 %37, 1
br label %101
47: ; preds = %35
%48 = call i64 @fstat(i32 %41, %struct.stat* %3)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i8*, i8** %38
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %51)
%53 = call i32 @close(i32 %41)
%54 = add nsw i32 %37, 1
br label %101
55: ; preds = %47
%56 = load i32, i32* %34
%57 = and i32 %56, 16384
%58 = icmp eq i32 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %55
%60 = load i8*, i8** %38
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %60)
%62 = call i32 @close(i32 %41)
%63 = add nsw i32 %37, 1
br label %101
64: ; preds = %55
%65 = load i8*, i8** %14
%66 = call i32 @strncpy(i8* %6, i8* %65, i32 511)
br i1 %33, label %73, label %67
67: ; preds = %64
%68 = call i32 @strlen(i8* %6)
%69 = sub i32 511, %68
%70 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %69)
%71 = load i8*, i8** %38
%72 = call i32 @strncat(i8* %6, i8* %71, i32 8)
br label %73
73: ; preds = %67, %64
%74 = load i32, i32* @O_WRONLY
%75 = load i32, i32* @O_CREAT
%76 = or i32 %75, %74
%77 = load i32, i32* @O_TRUNC
%78 = or i32 %76, %77
%79 = load i32, i32* %34
%80 = call i32 @open(i8* %6, i32 %78, i32 %79)
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %87
82: ; preds = %73
%83 = load i8*, i8** %14
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %83)
%85 = call i32 @close(i32 %41)
%86 = add nsw i32 %37, 1
br label %101
87: ; preds = %73, %90
%88 = call i32 @read(i32 %41, i8* %6, i32 512)
%89 = icmp sgt i32 %88, 0
br i1 %89, label %90, label %97
90: ; preds = %87
%91 = call i32 @write(i32 %80, i8* %6, i32 %88)
%92 = icmp eq i32 %91, %88
br i1 %92, label %87, label %93
93: ; preds = %90
%94 = load i8*, i8** %38
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %94)
%96 = add nsw i32 %37, 1
br label %97
97: ; preds = %87, %93
%98 = phi i32 [ %96, %93 ], [ %37, %87 ]
%99 = call i32 @close(i32 %41)
%100 = call i32 @close(i32 %80)
br label %101
101: ; preds = %97, %82, %59, %50, %43
%102 = phi i32 [ %46, %43 ], [ %54, %50 ], [ %63, %59 ], [ %86, %82 ], [ %98, %97 ]
%103 = add nuw nsw i64 %36, 1
%104 = icmp eq i64 %103, %13
br i1 %104, label %105, label %35
105: ; preds = %101, %29, %8
%106 = phi i32 [ 1, %8 ], [ 1, %29 ], [ %102, %101 ]
ret i32 %106
}