#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;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ EACCES;
scalar_t__ EXDEV;
int PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int copy_file(char *, char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
scalar_t__ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ rename(char *, char *);
int snprintf(char *, int, char *, char const *, ...);
scalar_t__ stat(char const *, struct stat *);
int strlen(char *);
char *strrchr(char *, char);
int copy(char *src, const char *dest) {
  int len;
  struct stat sb, sf;
  char target[PATH_MAX];
  char *p;
  p = strrchr(src, '/');
  if (p) {
    p++;
    if (strlen(p) == 0) {
      len = strlen(src) - 1;
      p = src;
      while (0 < len && p[len] == '/')
        p[len--] = '\0';
      p = strrchr(p, '/');
      p++;
    }
  } else {
    p = src;
  }
  memset(&sb, 0, sizeof(struct stat));
  if (stat(dest, &sb) == 0) {
    if (S_ISDIR(sb.st_mode)) {
      len = snprintf(target, PATH_MAX, "%s/%s", dest, p);
      if (len >= PATH_MAX)
        return -1;
    } else {
      len = snprintf(target, PATH_MAX, "%s/%s", dest, src);
      if (len >= PATH_MAX)
        return -1;
    }
  } else {
    len = snprintf(target, PATH_MAX, "%s", dest);
    if (len >= PATH_MAX)
      return -1;
  }
  if (rename(src, target) == 0) {
    return 0;
  } else {
    if (errno != EXDEV)
      return -1;
  }
  memset(&sf, 0, sizeof(struct stat));
  if (stat(src, &sf) < 0)
    return -1;
  if (!S_ISDIR(sf.st_mode)) {
    len = copy_file(src, target, sf.st_mode);
    if (len == 0)
      return 0;
    else
      return -1;
  }
  DIR *dir;
  struct dirent *d;
  char path[PATH_MAX];
  if (mkdir(target, sf.st_mode) < 0)
    return -1;
  dir = opendir(src);
  if (!dir) {
    if (errno != EACCES)
      return -1;
  }
  while ((d = readdir(dir))) {
    if (d->d_name[0] == '.' &&
        (d->d_name[1] == '\0' || (d->d_name[1] == '.' && d->d_name[2] == '\0')))
      continue;
    if (strlen(src) + 1 + strlen(d->d_name) >= PATH_MAX - 1)
      continue;
    snprintf(path, sizeof path, "%s/%s", src, d->d_name);
    if (len >= sizeof path)
      return -1;
    memset(&sf, 0, sizeof(struct stat));
    if (stat(path, &sf) < 0) {
      closedir(dir);
      return -1;
    }
    if (copy(path, target) < 0)
      return -1;
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     12d4 <copy+0x104>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%eax
jne    12cf <copy+0xff>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x69(%rbp)
jge    1286 <copy+0xb6>
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    1296 <copy+0xc6>
jmp    12b1 <copy+0xe1>
mov    -0x40(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1261 <copy+0x91>
mov    -0x40(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    12dc <copy+0x10c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0x0,%rax
jne    13ba <copy+0x1ea>
mov    -0x20(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1365 <copy+0x195>
mov    -0x68(%rbp),%rdi
mov    0x2cd0(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
mov    -0x40(%rbp),%r8
lea    0xccf(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2cab(%rip),%rcx
cmp    (%rcx),%eax
jl     1360 <copy+0x190>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
jmp    13b5 <copy+0x1e5>
mov    -0x68(%rbp),%rdi
mov    0x2c80(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xc7f(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2c5b(%rip),%rcx
cmp    (%rcx),%eax
jl     13b0 <copy+0x1e0>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
jmp    13b5 <copy+0x1e5>
jmp    1406 <copy+0x236>
mov    -0x68(%rbp),%rdi
mov    0x2c2b(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
lea    0xc31(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2c0a(%rip),%rcx
cmp    (%rcx),%eax
jl     1401 <copy+0x231>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
jmp    1406 <copy+0x236>
mov    -0x68(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   10f0 <rename@plt>
cmp    $0x0,%rax
jne    1430 <copy+0x260>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
mov    0x2b91(%rip),%rax
mov    (%rax),%rax
mov    0x2b8f(%rip),%rcx
cmp    (%rcx),%rax
je     145d <copy+0x28d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
jmp    1462 <copy+0x292>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0x0,%rax
jge    149c <copy+0x2cc>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
mov    -0x28(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    14f1 <copy+0x321>
mov    -0x68(%rbp),%rsi
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
call   1030 <copy_file@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    14de <copy+0x30e>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
mov    -0x68(%rbp),%rdi
mov    0x2af4(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x80(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    1543 <copy+0x373>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    158d <copy+0x3bd>
mov    0x2a66(%rip),%rax
mov    (%rax),%rax
mov    0x2a74(%rip),%rcx
cmp    (%rcx),%rax
je     1588 <copy+0x3b8>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
jmp    158d <copy+0x3bd>
jmp    1592 <copy+0x3c2>
mov    -0x50(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x58(%rbp)
cmp    $0x0,%rax
je     16f6 <copy+0x526>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    15fd <copy+0x42d>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     15f8 <copy+0x428>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    15fd <copy+0x42d>
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    15fd <copy+0x42d>
jmp    1592 <copy+0x3c2>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x84(%rbp),%eax
add    %ecx,%eax
mov    0x29c4(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     163e <copy+0x46e>
jmp    1592 <copy+0x3c2>
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x58(%rbp),%rax
mov    (%rax),%r8
lea    0x9a6(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0x80(%rbp),%rcx
movslq -0x1c(%rbp),%rax
cmp    %rcx,%rax
jb     1685 <copy+0x4b5>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    -0x78(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0x0,%rax
jge    16c8 <copy+0x4f8>
mov    -0x50(%rbp),%rdi
call   10b0 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
mov    -0x68(%rbp),%rsi
mov    -0x78(%rbp),%rdi
call   10c0 <copy@plt>
cmp    $0x0,%eax
jge    16f1 <copy+0x521>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    170d <copy+0x53d>
jmp    1592 <copy+0x3c2>
mov    -0x50(%rbp),%rdi
call   10b0 <closedir@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsp,-0x60(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %r12,%r13
test   %rax,%rax
je     126d <copy+0x9d>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %rbx,%r13
test   %eax,%eax
jne    126d <copy+0x9d>
mov    %r12,%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jl     1259 <copy+0x89>
mov    %eax,%eax
add    $0x1,%rax
lea    -0x2(%rax),%ecx
cmpb   $0x2f,(%r12,%rcx,1)
jne    1259 <copy+0x89>
movb   $0x0,(%r12,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1240 <copy+0x70>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1090 <strrchr@plt>
mov    %rax,%r13
add    $0x1,%r13
lea    -0x40(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10d0 <stat@plt>
test   %rax,%rax
je     12af <copy+0xdf>
mov    0x2d59(%rip),%rbx
mov    (%rbx),%esi
lea    0xd63(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
jmp    12e1 <copy+0x111>
mov    -0x40(%rbp),%edi
call   1070 <S_ISDIR@plt>
mov    0x2d32(%rip),%rbx
mov    (%rbx),%esi
lea    0xd39(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rcx
test   %rax,%rax
je     12d7 <copy+0x107>
mov    %r13,%r8
jmp    12da <copy+0x10a>
mov    %r12,%r8
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %eax,%r15d
mov    $0xffffffff,%eax
cmp    (%rbx),%r15d
jge    14d8 <copy+0x308>
mov    %r12,%rdi
mov    %r14,%rsi
call   10f0 <rename@plt>
test   %rax,%rax
je     14c6 <copy+0x2f6>
mov    0x2cbb(%rip),%rbx
mov    (%rbx),%rdx
mov    0x2cb9(%rip),%rcx
mov    $0xffffffff,%eax
cmp    (%rcx),%rdx
jne    14d8 <copy+0x308>
lea    -0x30(%rbp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10d0 <stat@plt>
test   %rax,%rax
js     14d3 <copy+0x303>
mov    -0x30(%rbp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     14a9 <copy+0x2d9>
mov    %rbx,%r13
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
mov    %rax,-0x58(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x30(%rbp),%esi
mov    %r14,%rdi
call   1040 <mkdir@plt>
test   %rax,%rax
js     14d3 <copy+0x303>
mov    %r12,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
jne    13b3 <copy+0x1e3>
mov    0x0(%r13),%rdx
mov    0x2c36(%rip),%rcx
cmp    (%rcx),%rdx
jne    14d3 <copy+0x303>
mov    %rbx,-0x50(%rbp)
mov    %rax,-0x38(%rbp)
mov    %rax,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     14bd <copy+0x2ed>
mov    %rax,%r13
movslq %r15d,%rax
mov    %rax,-0x48(%rbp)
jmp    13f5 <copy+0x225>
nopl   0x0(%rax,%rax,1)
mov    -0x38(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     14bd <copy+0x2ed>
mov    0x0(%r13),%rax
cmpb   $0x2e,(%rax)
jne    1420 <copy+0x250>
movzbl 0x1(%rax),%ecx
test   %cl,%cl
je     13e0 <copy+0x210>
cmp    $0x2e,%cl
jne    1420 <copy+0x250>
cmpb   $0x0,0x2(%rax)
je     13e0 <copy+0x210>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%r13),%rdi
call   1060 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
mov    0x2bb1(%rip),%rcx
mov    (%rcx),%ecx
add    $0xffffffff,%ecx
cmp    %ecx,%eax
jge    13e0 <copy+0x210>
mov    0x0(%r13),%r8
mov    -0x50(%rbp),%rbx
mov    %rbx,%rdi
mov    -0x58(%rbp),%r15
mov    %r15d,%esi
lea    0xb9f(%rip),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
cmp    %r15,-0x48(%rbp)
jae    14d3 <copy+0x303>
lea    -0x30(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   10a0 <memset@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <stat@plt>
test   %rax,%rax
js     14ca <copy+0x2fa>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10c0 <copy@plt>
test   %eax,%eax
jns    13e0 <copy+0x210>
jmp    14d3 <copy+0x303>
mov    -0x30(%rbp),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <copy_file@plt>
neg    %eax
sbb    %eax,%eax
jmp    14d8 <copy+0x308>
mov    -0x38(%rbp),%rdi
call   10b0 <closedir@plt>
xor    %eax,%eax
jmp    14d8 <copy+0x308>
mov    -0x38(%rbp),%rdi
call   10b0 <closedir@plt>
mov    $0xffffffff,%eax
mov    -0x60(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [3 x i8] c"%s\00"
@errno = global i64 0
@EXDEV = global i64 0
@EACCES = global i64 0
define i32 @copy(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca %struct.stat
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca %struct.dirent*
%15 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %9
%19 = alloca i8, i64 %17
store i64 %17, i64* %10
%20 = load i8*, i8** %4
%21 = call i8* @strrchr(i8* %20, i8 signext 47)
store i8* %21, i8** %11
%22 = load i8*, i8** %11
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %60
24: ; preds = %2
%25 = load i8*, i8** %11
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %11
%27 = load i8*, i8** %11
%28 = call i32 @strlen(i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %59
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = call i32 @strlen(i8* %31)
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %6
%34 = load i8*, i8** %4
store i8* %34, i8** %11
br label %35
35: ; preds = %48, %30
%36 = load i32, i32* %6
%37 = icmp slt i32 0, %36
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = load i8*, i8** %11
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 47
br label %46
46: ; preds = %38, %35
%47 = phi i1 [ false, %35 ], [ %45, %38 ]
br i1 %47, label %48, label %54
48: ; preds = %46
%49 = load i8*, i8** %11
%50 = load i32, i32* %6
%51 = add nsw i32 %50, -1
store i32 %51, i32* %6
%52 = sext i32 %50 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
store i8 0, i8* %53
br label %35
54: ; preds = %46
%55 = load i8*, i8** %11
%56 = call i8* @strrchr(i8* %55, i8 signext 47)
store i8* %56, i8** %11
%57 = load i8*, i8** %11
%58 = getelementptr inbounds i8, i8* %57, i32 1
store i8* %58, i8** %11
br label %59
59: ; preds = %54, %24
br label %62
60: ; preds = %2
%61 = load i8*, i8** %4
store i8* %61, i8** %11
br label %62
62: ; preds = %60, %59
%63 = call i32 @memset(%struct.stat* %7, i32 0, i32 4)
%64 = load i8*, i8** %5
%65 = call i64 @stat(i8* %64, %struct.stat* %7)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %93
67: ; preds = %62
%68 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i64 @S_ISDIR(i32 %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %82
72: ; preds = %67
%73 = load i32, i32* @PATH_MAX
%74 = load i8*, i8** %5
%75 = load i8*, i8** %11
%76 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %73, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %74, i8* %75)
store i32 %76, i32* %6
%77 = load i32, i32* %6
%78 = load i32, i32* @PATH_MAX
%79 = icmp sge i32 %77, %78
br i1 %79, label %80, label %81
80: ; preds = %72
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
81: ; preds = %72
br label %92
82: ; preds = %67
%83 = load i32, i32* @PATH_MAX
%84 = load i8*, i8** %5
%85 = load i8*, i8** %4
%86 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %83, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %84, i8* %85)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = load i32, i32* @PATH_MAX
%89 = icmp sge i32 %87, %88
br i1 %89, label %90, label %91
90: ; preds = %82
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
91: ; preds = %82
br label %92
92: ; preds = %91, %81
br label %102
93: ; preds = %62
%94 = load i32, i32* @PATH_MAX
%95 = load i8*, i8** %5
%96 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %95)
store i32 %96, i32* %6
%97 = load i32, i32* %6
%98 = load i32, i32* @PATH_MAX
%99 = icmp sge i32 %97, %98
br i1 %99, label %100, label %101
100: ; preds = %93
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
101: ; preds = %93
br label %102
102: ; preds = %101, %92
%103 = load i8*, i8** %4
%104 = call i64 @rename(i8* %103, i8* %19)
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %107
106: ; preds = %102
store i32 0, i32* %3
store i32 1, i32* %12
br label %230
107: ; preds = %102
%108 = load i64, i64* @errno
%109 = load i64, i64* @EXDEV
%110 = icmp ne i64 %108, %109
br i1 %110, label %111, label %112
111: ; preds = %107
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
112: ; preds = %107
br label %113
113: ; preds = %112
%114 = call i32 @memset(%struct.stat* %8, i32 0, i32 4)
%115 = load i8*, i8** %4
%116 = call i64 @stat(i8* %115, %struct.stat* %8)
%117 = icmp slt i64 %116, 0
br i1 %117, label %118, label %119
118: ; preds = %113
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
119: ; preds = %113
%120 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%121 = load i32, i32* %120
%122 = call i64 @S_ISDIR(i32 %121)
%123 = icmp ne i64 %122, 0
br i1 %123, label %133, label %124
124: ; preds = %119
%125 = load i8*, i8** %4
%126 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%127 = load i32, i32* %126
%128 = call i32 @copy_file(i8* %125, i8* %19, i32 %127)
store i32 %128, i32* %6
%129 = load i32, i32* %6
%130 = icmp eq i32 %129, 0
br i1 %130, label %131, label %132
131: ; preds = %124
store i32 0, i32* %3
store i32 1, i32* %12
br label %230
132: ; preds = %124
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
133: ; preds = %119
%134 = load i32, i32* @PATH_MAX
%135 = zext i32 %134 to i64
%136 = alloca i8, i64 %135
store i64 %135, i64* %15
%137 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%138 = load i32, i32* %137
%139 = call i64 @mkdir(i8* %19, i32 %138)
%140 = icmp slt i64 %139, 0
br i1 %140, label %141, label %142
141: ; preds = %133
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
142: ; preds = %133
%143 = load i8*, i8** %4
%144 = call i32* @opendir(i8* %143)
store i32* %144, i32** %13
%145 = load i32*, i32** %13
%146 = icmp ne i32* %145, null
br i1 %146, label %153, label %147
147: ; preds = %142
%148 = load i64, i64* @errno
%149 = load i64, i64* @EACCES
%150 = icmp ne i64 %148, %149
br i1 %150, label %151, label %152
151: ; preds = %147
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
152: ; preds = %147
br label %153
153: ; preds = %152, %142
br label %154
154: ; preds = %226, %203, %190, %153
%155 = load i32*, i32** %13
%156 = call %struct.dirent* @readdir(i32* %155)
store %struct.dirent* %156, %struct.dirent** %14
%157 = icmp ne %struct.dirent* %156, null
br i1 %157, label %158, label %227
158: ; preds = %154
%159 = load %struct.dirent*, %struct.dirent** %14
%160 = getelementptr inbounds %struct.dirent, %struct.dirent* %159, i32 0, i32 0
%161 = load i8*, i8** %160
%162 = getelementptr inbounds i8, i8* %161, i64 0
%163 = load i8, i8* %162
%164 = sext i8 %163 to i32
%165 = icmp eq i32 %164, 46
br i1 %165, label %166, label %191
166: ; preds = %158
%167 = load %struct.dirent*, %struct.dirent** %14
%168 = getelementptr inbounds %struct.dirent, %struct.dirent* %167, i32 0, i32 0
%169 = load i8*, i8** %168
%170 = getelementptr inbounds i8, i8* %169, i64 1
%171 = load i8, i8* %170
%172 = sext i8 %171 to i32
%173 = icmp eq i32 %172, 0
br i1 %173, label %190, label %174
174: ; preds = %166
%175 = load %struct.dirent*, %struct.dirent** %14
%176 = getelementptr inbounds %struct.dirent, %struct.dirent* %175, i32 0, i32 0
%177 = load i8*, i8** %176
%178 = getelementptr inbounds i8, i8* %177, i64 1
%179 = load i8, i8* %178
%180 = sext i8 %179 to i32
%181 = icmp eq i32 %180, 46
br i1 %181, label %182, label %191
182: ; preds = %174
%183 = load %struct.dirent*, %struct.dirent** %14
%184 = getelementptr inbounds %struct.dirent, %struct.dirent* %183, i32 0, i32 0
%185 = load i8*, i8** %184
%186 = getelementptr inbounds i8, i8* %185, i64 2
%187 = load i8, i8* %186
%188 = sext i8 %187 to i32
%189 = icmp eq i32 %188, 0
br i1 %189, label %190, label %191
190: ; preds = %182, %166
br label %154
191: ; preds = %182, %174, %158
%192 = load i8*, i8** %4
%193 = call i32 @strlen(i8* %192)
%194 = add nsw i32 %193, 1
%195 = load %struct.dirent*, %struct.dirent** %14
%196 = getelementptr inbounds %struct.dirent, %struct.dirent* %195, i32 0, i32 0
%197 = load i8*, i8** %196
%198 = call i32 @strlen(i8* %197)
%199 = add nsw i32 %194, %198
%200 = load i32, i32* @PATH_MAX
%201 = sub nsw i32 %200, 1
%202 = icmp sge i32 %199, %201
br i1 %202, label %203, label %204
203: ; preds = %191
br label %154
204: ; preds = %191
%205 = trunc i64 %135 to i32
%206 = load i8*, i8** %4
%207 = load %struct.dirent*, %struct.dirent** %14
%208 = getelementptr inbounds %struct.dirent, %struct.dirent* %207, i32 0, i32 0
%209 = load i8*, i8** %208
%210 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %136, i32 %205, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %206, i8* %209)
%211 = load i32, i32* %6
%212 = sext i32 %211 to i64
%213 = icmp uge i64 %212, %135
br i1 %213, label %214, label %215
214: ; preds = %204
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
215: ; preds = %204
%216 = call i32 @memset(%struct.stat* %8, i32 0, i32 4)
%217 = call i64 @stat(i8* %136, %struct.stat* %8)
%218 = icmp slt i64 %217, 0
br i1 %218, label %219, label %222
219: ; preds = %215
%220 = load i32*, i32** %13
%221 = call i32 @closedir(i32* %220)
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
222: ; preds = %215
%223 = call i32 @copy(i8* %136, i8* %19)
%224 = icmp slt i32 %223, 0
br i1 %224, label %225, label %226
225: ; preds = %222
store i32 -1, i32* %3
store i32 1, i32* %12
br label %230
226: ; preds = %222
br label %154
227: ; preds = %154
%228 = load i32*, i32** %13
%229 = call i32 @closedir(i32* %228)
store i32 0, i32* %3
store i32 1, i32* %12
br label %230
230: ; preds = %227, %225, %219, %214, %151, %141, %132, %131, %118, %111, %106, %100, %90, %80
%231 = load i8*, i8** %9
%232 = load i32, i32* %3
ret i32 %232
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [3 x i8] c"%s\00"
@errno = global i64 0
@EXDEV = global i64 0
@EACCES = global i64 0
define i32 @copy(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = load i32, i32* @PATH_MAX
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %34, label %13
13: ; preds = %2
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = tail call i32 @strlen(i8* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %13
%18 = tail call i32 @strlen(i8* %0)
%19 = icmp sgt i32 %18, 1
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = zext i32 %18 to i64
br label %22
22: ; preds = %20, %29
%23 = phi i64 [ %21, %20 ], [ %24, %29 ]
%24 = add nsw i64 %23, -1
%25 = and i64 %24, 4294967295
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 47
br i1 %28, label %29, label %31
29: ; preds = %22
store i8 0, i8* %26
%30 = icmp ugt i64 %23, 2
br i1 %30, label %22, label %31
31: ; preds = %22, %29, %17
%32 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%33 = getelementptr inbounds i8, i8* %32, i64 1
br label %34
34: ; preds = %2, %13, %31
%35 = phi i8* [ %33, %31 ], [ %14, %13 ], [ %0, %2 ]
%36 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%37 = call i64 @stat(i8* %1, %struct.stat* %3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %53
39: ; preds = %34
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%41 = load i32, i32* %40
%42 = call i64 @S_ISDIR(i32 %41)
%43 = icmp eq i64 %42, 0
%44 = load i32, i32* @PATH_MAX
br i1 %43, label %49, label %45
45: ; preds = %39
%46 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %35)
%47 = load i32, i32* @PATH_MAX
%48 = icmp slt i32 %46, %47
br i1 %48, label %58, label %139
49: ; preds = %39
%50 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %0)
%51 = load i32, i32* @PATH_MAX
%52 = icmp slt i32 %50, %51
br i1 %52, label %58, label %139
53: ; preds = %34
%54 = load i32, i32* @PATH_MAX
%55 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %10, i32 %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%56 = load i32, i32* @PATH_MAX
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %139
58: ; preds = %53, %45, %49
%59 = phi i32 [ %46, %45 ], [ %50, %49 ], [ %55, %53 ]
%60 = call i64 @rename(i8* %0, i8* %10)
%61 = icmp eq i64 %60, 0
br i1 %61, label %139, label %62
62: ; preds = %58
%63 = load i64, i64* @errno
%64 = load i64, i64* @EXDEV
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %139
66: ; preds = %62
%67 = call i32 @memset(%struct.stat* %4, i32 0, i32 4)
%68 = call i64 @stat(i8* %0, %struct.stat* %4)
%69 = icmp slt i64 %68, 0
br i1 %69, label %139, label %70
70: ; preds = %66
%71 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%72 = load i32, i32* %71
%73 = call i64 @S_ISDIR(i32 %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %80
75: ; preds = %70
%76 = load i32, i32* %71
%77 = call i32 @copy_file(i8* %0, i8* %10, i32 %76)
%78 = icmp ne i32 %77, 0
%79 = sext i1 %78 to i32
br label %139
80: ; preds = %70
%81 = load i32, i32* @PATH_MAX
%82 = zext i32 %81 to i64
%83 = alloca i8, i64 %82
%84 = load i32, i32* %71
%85 = call i64 @mkdir(i8* %10, i32 %84)
%86 = icmp slt i64 %85, 0
br i1 %86, label %139, label %87
87: ; preds = %80
%88 = call i32* @opendir(i8* %0)
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %94
90: ; preds = %87
%91 = load i64, i64* @errno
%92 = load i64, i64* @EACCES
%93 = icmp eq i64 %91, %92
br i1 %93, label %94, label %139
94: ; preds = %90, %87
%95 = call %struct.dirent* @readdir(i32* %88)
%96 = icmp eq %struct.dirent* %95, null
br i1 %96, label %137, label %97
97: ; preds = %94
%98 = sext i32 %59 to i64
%99 = icmp ult i64 %98, %82
br label %100
100: ; preds = %97, %113
%101 = phi %struct.dirent* [ %95, %97 ], [ %114, %113 ]
%102 = getelementptr inbounds %struct.dirent, %struct.dirent* %101, i64 0, i32 0
%103 = load i8*, i8** %102
%104 = load i8, i8* %103
%105 = icmp eq i8 %104, 46
br i1 %105, label %106, label %116
106: ; preds = %100
%107 = getelementptr inbounds i8, i8* %103, i64 1
%108 = load i8, i8* %107
switch i8 %108, label %116 [
i8 0, label %113
i8 46, label %109
]
109: ; preds = %106
%110 = getelementptr inbounds i8, i8* %103, i64 2
%111 = load i8, i8* %110
%112 = icmp eq i8 %111, 0
br i1 %112, label %113, label %116
113: ; preds = %109, %106, %116, %134
%114 = call %struct.dirent* @readdir(i32* %88)
%115 = icmp eq %struct.dirent* %114, null
br i1 %115, label %137, label %100
116: ; preds = %106, %109, %100
%117 = call i32 @strlen(i8* %0)
%118 = add nsw i32 %117, 1
%119 = load i8*, i8** %102
%120 = call i32 @strlen(i8* %119)
%121 = add nsw i32 %118, %120
%122 = load i32, i32* @PATH_MAX
%123 = add nsw i32 %122, -1
%124 = icmp slt i32 %121, %123
br i1 %124, label %125, label %113
125: ; preds = %116
%126 = load i8*, i8** %102
%127 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %83, i32 %81, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %126)
br i1 %99, label %128, label %139
128: ; preds = %125
%129 = call i32 @memset(%struct.stat* %4, i32 0, i32 4)
%130 = call i64 @stat(i8* %83, %struct.stat* %4)
%131 = icmp slt i64 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %128
%133 = call i32 @closedir(i32* %88)
br label %139
134: ; preds = %128
%135 = call i32 @copy(i8* %83, i8* %10)
%136 = icmp slt i32 %135, 0
br i1 %136, label %139, label %113
137: ; preds = %113, %94
%138 = call i32 @closedir(i32* %88)
br label %139
139: ; preds = %125, %134, %132, %137, %80, %90, %75, %66, %62, %58, %53, %49, %45
%140 = phi i32 [ -1, %45 ], [ -1, %49 ], [ -1, %53 ], [ 0, %58 ], [ -1, %62 ], [ -1, %66 ], [ %79, %75 ], [ -1, %132 ], [ 0, %137 ], [ -1, %80 ], [ -1, %90 ], [ -1, %134 ], [ -1, %125 ]
ret i32 %140
}