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

/* Variables and functions */
int /*<<< orphan*/ copy_dir_entries(char const *, char const *);
int copy_recursive_exec(char *, char *);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
int copy_recursive_dirs(const char *oldpath, const char *cachepath) {
  char *dup_path = NULL;
  char *dup_cachepath = NULL;
  int ret = 0;
  dup_path = strdup(oldpath);
  if (!dup_path)
    return -1;
  dup_cachepath = strdup(cachepath);
  if (!dup_cachepath) {
    free(dup_path);
    return -1;
  }
  ret = copy_recursive_exec(dup_path, dup_cachepath);
  free(dup_path);
  free(dup_cachepath);
  if (ret != -2)
    copy_dir_entries(oldpath, cachepath);
  return ret;
}


x86 assembly (clang, -O0):
<copy_recursive_dirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <copy_recursive_dirs+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <copy_recursive_dirs+0xb7>
mov    -0x18(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b8 <copy_recursive_dirs+0x78>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <copy_recursive_dirs+0xb7>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <copy_recursive_exec@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0xfffffffe,-0x2c(%rbp)
je     11f1 <copy_recursive_dirs+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <copy_dir_entries@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_recursive_dirs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strdup@plt>
mov    $0xffffffff,%r13d
test   %rax,%rax
je     11b6 <copy_recursive_dirs+0x76>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strdup@plt>
test   %rax,%rax
je     11ae <copy_recursive_dirs+0x6e>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <copy_recursive_exec@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0xfffffffe,%r13d
cmp    $0xfffffffe,%r12d
je     11b6 <copy_recursive_dirs+0x76>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <copy_dir_entries@plt>
mov    %r12d,%r13d
jmp    11b6 <copy_recursive_dirs+0x76>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @copy_recursive_dirs(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 -1, i32* %3
br label %38
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i8*, i8** %6
%21 = call i32 @free(i8* %20)
store i32 -1, i32* %3
br label %38
22: ; preds = %14
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32 @copy_recursive_exec(i8* %23, i8* %24)
store i32 %25, i32* %8
%26 = load i8*, i8** %6
%27 = call i32 @free(i8* %26)
%28 = load i8*, i8** %7
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, -2
br i1 %31, label %32, label %36
32: ; preds = %22
%33 = load i8*, i8** %4
%34 = load i8*, i8** %5
%35 = call i32 @copy_dir_entries(i8* %33, i8* %34)
br label %36
36: ; preds = %32, %22
%37 = load i32, i32* %8
store i32 %37, i32* %3
br label %38
38: ; preds = %36, %19, %13
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @copy_recursive_dirs(i8* %0, i8* %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = tail call i8* @strdup(i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @free(i8* %3)
br label %17
10: ; preds = %5
%11 = tail call i32 @copy_recursive_exec(i8* %3, i8* %6)
%12 = tail call i32 @free(i8* %3)
%13 = tail call i32 @free(i8* %6)
%14 = icmp eq i32 %11, -2
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @copy_dir_entries(i8* %0, i8* %1)
br label %17
17: ; preds = %10, %15, %2, %8
%18 = phi i32 [ -1, %8 ], [ -1, %2 ], [ %11, %15 ], [ -2, %10 ]
ret i32 %18
}