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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *fs_concat_path(char const *, char *);
int fs_cp(char const *, char const *);
int /*<<< orphan*/ fs_exsists(char const *);
int /*<<< orphan*/ fs_is_dir(char const *);
int /*<<< orphan*/ fs_mkdir(char const *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int fs_recursive_copy(const char *restrict source,
                      const char *restrict destination) {
  int return_value = 0;
  DIR *source_directory;
  struct dirent *source_directory_list_item;
  char *restrict new_source;
  char *restrict new_destination;
  if (!fs_exsists(source))
    return 0;
  if (!fs_is_dir(source))
    return fs_cp(source, destination);
  fs_mkdir(destination);
  source_directory = opendir(source);
  while ((source_directory_list_item = readdir(source_directory))) {
    if ((source_directory_list_item->d_name)[0] != '.') {
      new_source = fs_concat_path(source, source_directory_list_item->d_name);
      new_destination =
          fs_concat_path(destination, source_directory_list_item->d_name);
      return_value = fs_recursive_copy(new_source, new_destination);
      free(new_source);
      free(new_destination);
    }
  }
  closedir(source_directory);
  return return_value;
}


x86 assembly (clang, -O0):
<fs_recursive_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   10c0 <fs_exsists@plt>
cmp    $0x0,%eax
jne    11d5 <fs_recursive_copy+0x35>
movl   $0x0,-0x4(%rbp)
jmp    129a <fs_recursive_copy+0xfa>
mov    -0x10(%rbp),%rdi
call   1080 <fs_is_dir@plt>
cmp    $0x0,%eax
jne    11fc <fs_recursive_copy+0x5c>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <fs_cp@plt>
mov    %eax,-0x4(%rbp)
jmp    129a <fs_recursive_copy+0xfa>
mov    -0x18(%rbp),%rdi
call   1090 <fs_mkdir@plt>
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     128b <fs_recursive_copy+0xeb>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1286 <fs_recursive_copy+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1040 <fs_concat_path@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1040 <fs_concat_path@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <fs_recursive_copy@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    1212 <fs_recursive_copy+0x72>
mov    -0x28(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fs_recursive_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   10c0 <fs_exsists@plt>
test   %eax,%eax
je     1253 <fs_recursive_copy+0xb3>
mov    %r15,%rdi
call   1080 <fs_is_dir@plt>
test   %eax,%eax
je     1258 <fs_recursive_copy+0xb8>
mov    %r14,%rdi
call   1090 <fs_mkdir@plt>
mov    %r15,%rdi
call   1060 <opendir@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     1271 <fs_recursive_copy+0xd1>
mov    %rax,%rbp
xor    %r12d,%r12d
jmp    1210 <fs_recursive_copy+0x70>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1274 <fs_recursive_copy+0xd4>
mov    0x0(%rbp),%rsi
cmpb   $0x2e,(%rsi)
je     1200 <fs_recursive_copy+0x60>
mov    %r15,%rdi
call   1040 <fs_concat_path@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rsi
mov    %r14,%rdi
call   1040 <fs_concat_path@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <fs_recursive_copy@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    1200 <fs_recursive_copy+0x60>
xor    %r12d,%r12d
jmp    127c <fs_recursive_copy+0xdc>
mov    %r15,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <fs_cp@plt>
xor    %r12d,%r12d
mov    %r13,%rdi
call   1070 <closedir@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
define i32 @fs_recursive_copy(i8* noalias %0, i8* noalias %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @fs_exsists(i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 0, i32* %3
br label %63
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32 @fs_is_dir(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 @fs_cp(i8* %20, i8* %21)
store i32 %22, i32* %3
br label %63
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = call i32 @fs_mkdir(i8* %24)
%26 = load i8*, i8** %4
%27 = call i32* @opendir(i8* %26)
store i32* %27, i32** %7
br label %28
28: ; preds = %58, %23
%29 = load i32*, i32** %7
%30 = call %struct.dirent* @readdir(i32* %29)
store %struct.dirent* %30, %struct.dirent** %8
%31 = icmp ne %struct.dirent* %30, null
br i1 %31, label %32, label %59
32: ; preds = %28
%33 = load %struct.dirent*, %struct.dirent** %8
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 46
br i1 %39, label %40, label %58
40: ; preds = %32
%41 = load i8*, i8** %4
%42 = load %struct.dirent*, %struct.dirent** %8
%43 = getelementptr inbounds %struct.dirent, %struct.dirent* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i8* @fs_concat_path(i8* %41, i8* %44)
store i8* %45, i8** %9
%46 = load i8*, i8** %5
%47 = load %struct.dirent*, %struct.dirent** %8
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i8* @fs_concat_path(i8* %46, i8* %49)
store i8* %50, i8** %10
%51 = load i8*, i8** %9
%52 = load i8*, i8** %10
%53 = call i32 @fs_recursive_copy(i8* %51, i8* %52)
store i32 %53, i32* %6
%54 = load i8*, i8** %9
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %10
%57 = call i32 @free(i8* %56)
br label %58
58: ; preds = %40, %32
br label %28
59: ; preds = %28
%60 = load i32*, i32** %7
%61 = call i32 @closedir(i32* %60)
%62 = load i32, i32* %6
store i32 %62, i32* %3
br label %63
63: ; preds = %59, %19, %14
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
define i32 @fs_recursive_copy(i8* noalias %0, i8* noalias %1) {
%3 = tail call i32 @fs_exsists(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %36, label %5
5: ; preds = %2
%6 = tail call i32 @fs_is_dir(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @fs_cp(i8* %0, i8* %1)
br label %36
10: ; preds = %5
%11 = tail call i32 @fs_mkdir(i8* %1)
%12 = tail call i32* @opendir(i8* %0)
%13 = tail call %struct.dirent* @readdir(i32* %12)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %33, label %15
15: ; preds = %10, %29
%16 = phi %struct.dirent* [ %31, %29 ], [ %13, %10 ]
%17 = phi i32 [ %30, %29 ], [ 0, %10 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 46
br i1 %21, label %29, label %22
22: ; preds = %15
%23 = tail call i8* @fs_concat_path(i8* %0, i8* %19)
%24 = load i8*, i8** %18
%25 = tail call i8* @fs_concat_path(i8* %1, i8* %24)
%26 = tail call i32 @fs_recursive_copy(i8* %23, i8* %25)
%27 = tail call i32 @free(i8* %23)
%28 = tail call i32 @free(i8* %25)
br label %29
29: ; preds = %22, %15
%30 = phi i32 [ %26, %22 ], [ %17, %15 ]
%31 = tail call %struct.dirent* @readdir(i32* %12)
%32 = icmp eq %struct.dirent* %31, null
br i1 %32, label %33, label %15
33: ; preds = %29, %10
%34 = phi i32 [ 0, %10 ], [ %30, %29 ]
%35 = tail call i32 @closedir(i32* %12)
br label %36
36: ; preds = %2, %33, %8
%37 = phi i32 [ %34, %33 ], [ %9, %8 ], [ 0, %2 ]
ret i32 %37
}