#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;
  scalar_t__ d_type;
};
typedef int /*<<< orphan*/ new_src_dir;
typedef int /*<<< orphan*/ new_dst_dir;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_DIR;
scalar_t__ DT_REG;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ copy_file(char *, char *, char *);
int mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strncmp(char *, char *, int);
int file_porter(char *src_dir, char *dst_dir) {
  int ret;
  DIR *cur_dir;
  char new_src_dir[256] = {
      '\0',
  };
  char new_dst_dir[256] = {
      '\0',
  };
  struct dirent *dir_ptr = NULL;
  if (access(dst_dir, F_OK) != 0) {
    ret = mkdir(dst_dir, 0);
    if (ret) {
      printf("mkdir %s ERR\n", dst_dir);
      return ret;
    }
  }
  cur_dir = opendir(src_dir);
  while ((dir_ptr = (readdir(cur_dir))) != NULL) {
    if (strncmp(dir_ptr->d_name, ".", 1) == 0 ||
        strcmp(dir_ptr->d_name, "wakeup") == 0) {
      continue;
    }
    if (dir_ptr->d_type == DT_DIR) {
      snprintf(new_src_dir, sizeof(new_src_dir), "%s/%s", src_dir,
               dir_ptr->d_name);
      snprintf(new_dst_dir, sizeof(new_dst_dir), "%s/%s", dst_dir,
               dir_ptr->d_name);
      file_porter(new_src_dir, new_dst_dir);
    } else if (dir_ptr->d_type == DT_REG) {
      copy_file(src_dir, dst_dir, dir_ptr->d_name);
    }
  }
  closedir(cur_dir);
  return 0;
}


x86 assembly (clang, -O0):
<file_porter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
movq   $0x0,-0x238(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   10e0 <access@plt>
cmp    $0x0,%rax
je     1258 <file_porter+0x98>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1050 <mkdir@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1253 <file_porter+0x93>
mov    -0x18(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1070 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1394 <file_porter+0x1d4>
jmp    1258 <file_porter+0x98>
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x238(%rbp)
cmp    $0x0,%rax
je     1384 <file_porter+0x1c4>
mov    -0x238(%rbp),%rax
mov    (%rax),%rdi
lea    0xd7e(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     12c4 <file_porter+0x104>
mov    -0x238(%rbp),%rax
mov    (%rax),%rdi
lea    0xd5b(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    12c9 <file_porter+0x109>
jmp    1265 <file_porter+0xa5>
mov    -0x238(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2cfd(%rip),%rcx
cmp    (%rcx),%rax
jne    1348 <file_porter+0x188>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x238(%rbp),%rax
mov    (%rax),%r8
mov    $0x100,%esi
lea    0xd12(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x238(%rbp),%rax
mov    (%rax),%r8
mov    $0x100,%esi
lea    0xcec(%rip),%rdx
call   1080 <snprintf@plt>
lea    -0x130(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   10d0 <file_porter@plt>
jmp    137f <file_porter+0x1bf>
mov    -0x238(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2c86(%rip),%rcx
cmp    (%rcx),%rax
jne    137a <file_porter+0x1ba>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x238(%rbp),%rax
mov    (%rax),%rdx
call   1030 <copy_file@plt>
jmp    137f <file_porter+0x1bf>
jmp    1265 <file_porter+0xa5>
mov    -0x28(%rbp),%rdi
call   10a0 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_porter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r13
mov    %rdi,0x8(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   10d0 <access@plt>
test   %rax,%rax
je     12f1 <file_porter+0x141>
mov    %r13,%rdi
xor    %esi,%esi
call   1050 <mkdir@plt>
test   %eax,%eax
je     12f1 <file_porter+0x141>
mov    %eax,%ebx
lea    0xd1c(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
jmp    1404 <file_porter+0x254>
mov    0x8(%rsp),%rdi
call   1060 <opendir@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     13fa <file_porter+0x24a>
mov    %rax,%rbp
lea    0xcf5(%rip),%r15
lea    0xcf0(%rip),%rbx
jmp    13a0 <file_porter+0x1f0>
mov    0x0(%rbp),%r8
mov    %r12,%rbx
mov    %r15,%r12
lea    0x110(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
lea    0xcd4(%rip),%r14
mov    %r14,%rdx
mov    0x8(%rsp),%rcx
call   1080 <snprintf@plt>
mov    0x0(%rbp),%r8
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
mov    %r13,%rcx
call   1080 <snprintf@plt>
mov    %r15,%rdi
mov    %r12,%r15
mov    %rbx,%r12
lea    0xc94(%rip),%rbx
mov    %rbp,%rsi
call   10c0 <file_porter@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     13fa <file_porter+0x24a>
mov    0x0(%rbp),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1390 <file_porter+0x1e0>
mov    0x0(%rbp),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1390 <file_porter+0x1e0>
mov    0x8(%rbp),%rax
mov    0x2c06(%rip),%rcx
cmp    (%rcx),%rax
je     1322 <file_porter+0x172>
mov    0x2bfe(%rip),%rcx
cmp    (%rcx),%rax
jne    1390 <file_porter+0x1e0>
mov    0x0(%rbp),%rdx
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1030 <copy_file@plt>
jmp    1390 <file_porter+0x1e0>
mov    %r12,%rdi
call   1090 <closedir@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@F_OK = global i32 0
@.str = [14 x i8] c"mkdir %s ERR\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [7 x i8] c"wakeup\00"
@DT_DIR = global i64 0
@.str.3 = [6 x i8] c"%s/%s\00"
@DT_REG = global i64 0
define i32 @file_porter(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca [256 x i8]
%10 = alloca %struct.dirent*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = bitcast [256 x i8]* %8 to i8*
%12 = bitcast [256 x i8]* %9 to i8*
store %struct.dirent* null, %struct.dirent** %10
%13 = load i8*, i8** %5
%14 = load i32, i32* @F_OK
%15 = call i64 @access(i8* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %2
%18 = load i8*, i8** %5
%19 = call i32 @mkdir(i8* %18, i32 0)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %87
26: ; preds = %17
br label %27
27: ; preds = %26, %2
%28 = load i8*, i8** %4
%29 = call i32* @opendir(i8* %28)
store i32* %29, i32** %7
br label %30
30: ; preds = %83, %46, %27
%31 = load i32*, i32** %7
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %10
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %84
34: ; preds = %30
%35 = load %struct.dirent*, %struct.dirent** %10
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%39 = icmp eq i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %34
%41 = load %struct.dirent*, %struct.dirent** %10
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40, %34
br label %30
47: ; preds = %40
%48 = load %struct.dirent*, %struct.dirent** %10
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 1
%50 = load i64, i64* %49
%51 = load i64, i64* @DT_DIR
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %69
53: ; preds = %47
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = load i8*, i8** %4
%56 = load %struct.dirent*, %struct.dirent** %10
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i32 @snprintf(i8* %54, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %55, i8* %58)
%60 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%61 = load i8*, i8** %5
%62 = load %struct.dirent*, %struct.dirent** %10
%63 = getelementptr inbounds %struct.dirent, %struct.dirent* %62, i32 0, i32 0
%64 = load i8*, i8** %63
%65 = call i32 @snprintf(i8* %60, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %61, i8* %64)
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%68 = call i32 @file_porter(i8* %66, i8* %67)
br label %83
69: ; preds = %47
%70 = load %struct.dirent*, %struct.dirent** %10
%71 = getelementptr inbounds %struct.dirent, %struct.dirent* %70, i32 0, i32 1
%72 = load i64, i64* %71
%73 = load i64, i64* @DT_REG
%74 = icmp eq i64 %72, %73
br i1 %74, label %75, label %82
75: ; preds = %69
%76 = load i8*, i8** %4
%77 = load i8*, i8** %5
%78 = load %struct.dirent*, %struct.dirent** %10
%79 = getelementptr inbounds %struct.dirent, %struct.dirent* %78, i32 0, i32 0
%80 = load i8*, i8** %79
%81 = call i32 @copy_file(i8* %76, i8* %77, i8* %80)
br label %82
82: ; preds = %75, %69
br label %83
83: ; preds = %82, %53
br label %30
84: ; preds = %30
%85 = load i32*, i32** %7
%86 = call i32 @closedir(i32* %85)
store i32 0, i32* %3
br label %87
87: ; preds = %84, %22
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i64 }
@F_OK = global i32 0
@.str = [14 x i8] c"mkdir %s ERR\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [7 x i8] c"wakeup\00"
@DT_DIR = global i64 0
@.str.3 = [6 x i8] c"%s/%s\00"
@DT_REG = global i64 0
define i32 @file_porter(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @F_OK
%8 = tail call i64 @access(i8* %1, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = tail call i32 @mkdir(i8* %1, i32 0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %51
15: ; preds = %10, %2
%16 = tail call i32* @opendir(i8* %0)
%17 = call %struct.dirent* @readdir(i32* %16)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %49, label %19
19: ; preds = %15, %29
%20 = phi %struct.dirent* [ %30, %29 ], [ %17, %15 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i8*, i8** %21
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %37, %46, %43, %19, %25
%30 = call %struct.dirent* @readdir(i32* %16)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %49, label %19
32: ; preds = %25
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 1
%34 = load i64, i64* %33
%35 = load i64, i64* @DT_DIR
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i8*, i8** %21
%39 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %38)
%40 = load i8*, i8** %21
%41 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %40)
%42 = call i32 @file_porter(i8* %5, i8* %6)
br label %29
43: ; preds = %32
%44 = load i64, i64* @DT_REG
%45 = icmp eq i64 %34, %44
br i1 %45, label %46, label %29
46: ; preds = %43
%47 = load i8*, i8** %21
%48 = call i32 @copy_file(i8* %0, i8* %1, i8* %47)
br label %29
49: ; preds = %29, %15
%50 = call i32 @closedir(i32* %16)
br label %51
51: ; preds = %49, %13
%52 = phi i32 [ %11, %13 ], [ 0, %49 ]
ret i32 %52
}