#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 utimbuf {
  int /*<<< orphan*/ modtime;
  int /*<<< orphan*/ actime;
};
struct stat {
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_atime;
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ real_mkdir(char *, int);
int real_xstat(int, char *, struct stat *);
char *strrchr(char *, char);
int /*<<< orphan*/ utime(char *, struct utimbuf *);
int copy_recursive_exec(const char *oldpath, const char *cachepath) {
  char *path_bn;
  char *cache_bn;
  char *cpath = (char *)cachepath;
  char *ppath = (char *)oldpath;
  struct stat pathstat;
  struct stat cachepathstat;
  struct utimbuf dtime;
  if (real_xstat(1, cpath, &cachepathstat) == -1) {
    path_bn = strrchr(ppath, '/');
    cache_bn = strrchr(cpath, '/');
    if (real_xstat(1, ppath, &pathstat) == -1) {
      return -2;
    }
    *path_bn = '\0';
    *cache_bn = '\0';
    copy_recursive_exec(ppath, cpath);
    *path_bn = '/';
    *cache_bn = '/';
    if (S_ISDIR(pathstat.st_mode)) {
      if (!real_mkdir(cpath, 040711)) {
        dtime.actime = pathstat.st_atime;
        dtime.modtime = pathstat.st_mtime;
        utime(cpath, &dtime);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_recursive_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    $0x1,%edi
lea    -0x58(%rbp),%rdx
call   1080 <real_xstat@plt>
cmp    $0xffffffff,%eax
jne    125b <copy_recursive_exec+0xfb>
mov    -0x38(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rsi
mov    $0x1,%edi
lea    -0x48(%rbp),%rdx
call   1080 <real_xstat@plt>
cmp    $0xffffffff,%eax
jne    11e6 <copy_recursive_exec+0x86>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1262 <copy_recursive_exec+0x102>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <copy_recursive_exec@plt>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x40(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1256 <copy_recursive_exec+0xf6>
mov    -0x30(%rbp),%rdi
mov    $0x41c9,%esi
call   1070 <real_mkdir@plt>
cmp    $0x0,%eax
jne    1251 <copy_recursive_exec+0xf1>
mov    -0x44(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <utime@plt>
jmp    1256 <copy_recursive_exec+0xf6>
jmp    125b <copy_recursive_exec+0xfb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_recursive_exec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x20(%rsp),%rdx
mov    $0x1,%edi
call   1080 <real_xstat@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     1199 <copy_recursive_exec+0x39>
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,%r12
lea    0x10(%rsp),%rdx
mov    $0x1,%edi
mov    %rbp,%rsi
call   1080 <real_xstat@plt>
cmp    $0xffffffff,%eax
je     122c <copy_recursive_exec+0xcc>
movb   $0x0,(%r15)
movb   $0x0,(%r12)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <copy_recursive_exec@plt>
movb   $0x2f,(%r15)
movb   $0x2f,(%r12)
mov    0x18(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     1189 <copy_recursive_exec+0x29>
mov    %rbx,%rdi
mov    $0x41c9,%esi
call   1070 <real_mkdir@plt>
test   %eax,%eax
jne    1189 <copy_recursive_exec+0x29>
mov    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <utime@plt>
jmp    1189 <copy_recursive_exec+0x29>
mov    $0xfffffffe,%r14d
jmp    1189 <copy_recursive_exec+0x29>

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
%struct.utimbuf = type { i32, i32 }
define i32 @copy_recursive_exec(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca %struct.stat
%12 = alloca %struct.utimbuf
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i8*, i8** %5
store i8* %13, i8** %8
%14 = load i8*, i8** %4
store i8* %14, i8** %9
%15 = load i8*, i8** %8
%16 = call i32 @real_xstat(i32 1, i8* %15, %struct.stat* %11)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %54
18: ; preds = %2
%19 = load i8*, i8** %9
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %6
%21 = load i8*, i8** %8
%22 = call i8* @strrchr(i8* %21, i8 signext 47)
store i8* %22, i8** %7
%23 = load i8*, i8** %9
%24 = call i32 @real_xstat(i32 1, i8* %23, %struct.stat* %10)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %18
store i32 -2, i32* %3
br label %55
27: ; preds = %18
%28 = load i8*, i8** %6
store i8 0, i8* %28
%29 = load i8*, i8** %7
store i8 0, i8* %29
%30 = load i8*, i8** %9
%31 = load i8*, i8** %8
%32 = call i32 @copy_recursive_exec(i8* %30, i8* %31)
%33 = load i8*, i8** %6
store i8 47, i8* %33
%34 = load i8*, i8** %7
store i8 47, i8* %34
%35 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i64 @S_ISDIR(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %53
39: ; preds = %27
%40 = load i8*, i8** %8
%41 = call i32 @real_mkdir(i8* %40, i32 16841)
%42 = icmp ne i32 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39
%44 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %12, i32 0, i32 1
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %12, i32 0, i32 0
store i32 %48, i32* %49
%50 = load i8*, i8** %8
%51 = call i32 @utime(i8* %50, %struct.utimbuf* %12)
br label %52
52: ; preds = %43, %39
br label %53
53: ; preds = %52, %27
br label %54
54: ; preds = %53, %2
store i32 0, i32* %3
br label %55
55: ; preds = %54, %26
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.utimbuf = type { i32, i32 }
define i32 @copy_recursive_exec(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca %struct.utimbuf
%6 = bitcast %struct.stat* %3 to i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = bitcast %struct.utimbuf* %5 to i8*
%9 = call i32 @real_xstat(i32 1, i8* %1, %struct.stat* %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %33
11: ; preds = %2
%12 = call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%13 = call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%14 = call i32 @real_xstat(i32 1, i8* %0, %struct.stat* %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %33, label %16
16: ; preds = %11
store i8 0, i8* %12
store i8 0, i8* %13
%17 = call i32 @copy_recursive_exec(i8* %0, i8* %1)
store i8 47, i8* %12
store i8 47, i8* %13
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%19 = load i32, i32* %18
%20 = call i64 @S_ISDIR(i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %33, label %22
22: ; preds = %16
%23 = call i32 @real_mkdir(i8* %1, i32 16841)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %5, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.utimbuf, %struct.utimbuf* %5, i64 0, i32 0
store i32 %30, i32* %31
%32 = call i32 @utime(i8* %1, %struct.utimbuf* %5)
br label %33
33: ; preds = %2, %22, %25, %16, %11
%34 = phi i32 [ -2, %11 ], [ 0, %16 ], [ 0, %25 ], [ 0, %22 ], [ 0, %2 ]
ret i32 %34
}