#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*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ cctools_debug(long long, char *, char const *, ...);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ dir_entry(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ *strcpy(char *, char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int create_dir_subitems(const char *path, char *new_path, FILE *special_file) {
  DIR *dir;
  struct dirent *entry;
  char full_entrypath[PATH_MAX], dir_name[PATH_MAX];
  if (strcpy(dir_name, path) == NULL) {
    cctools_debug((1LL << 3), "create_dir_subitems(`%s`) error: %s\n", path,
                  strerror(errno));
    return -1;
  }
  cctools_debug((1LL << 3), "create_dir_subitems(`%s`) func\n", path);
  strcat(dir_name, "/");
  if ((dir = opendir(path)) != NULL) {
    while ((entry = readdir(dir))) {
      strcpy(full_entrypath, dir_name);
      strcat(full_entrypath, entry->d_name);
      dir_entry(full_entrypath, special_file);
    }
    closedir(dir);
  } else {
    cctools_debug((1LL << 3), "Couldn't open the directory `%s`.\n", path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_dir_subitems>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x40(%rbp)
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmp    $0x0,%rax
jne    1233 <create_dir_subitems+0xb3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x68(%rbp),%rdx
mov    %eax,%ecx
mov    $0x8,%edi
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1060 <cctools_debug@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    12ef <create_dir_subitems+0x16f>
mov    -0x10(%rbp),%rdx
mov    $0x8,%edi
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1060 <cctools_debug@plt>
mov    -0x58(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12ca <create_dir_subitems+0x14a>
jmp    1276 <create_dir_subitems+0xf6>
mov    -0x28(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12bc <create_dir_subitems+0x13c>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x60(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   1090 <strcat@plt>
mov    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <dir_entry@plt>
jmp    1276 <create_dir_subitems+0xf6>
mov    -0x28(%rbp),%rdi
call   1050 <closedir@plt>
jmp    12e1 <create_dir_subitems+0x161>
mov    -0x10(%rbp),%rdx
mov    $0x8,%edi
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1060 <cctools_debug@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dir_subitems>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
test   %rax,%rax
je     124b <create_dir_subitems+0xcb>
lea    0xe53(%rip),%rsi
mov    $0x8,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <cctools_debug@plt>
lea    0xe5d(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1278 <create_dir_subitems+0xf8>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1241 <create_dir_subitems+0xc1>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1090 <strcat@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <dir_entry@plt>
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1210 <create_dir_subitems+0x90>
mov    %r13,%rdi
call   1050 <closedir@plt>
jmp    128e <create_dir_subitems+0x10e>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xda0(%rip),%rsi
mov    $0x8,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <cctools_debug@plt>
mov    $0xffffffff,%eax
jmp    1290 <create_dir_subitems+0x110>
lea    0xdc8(%rip),%rsi
mov    $0x8,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <cctools_debug@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [37 x i8] c"create_dir_subitems(`%s`) error: %s\0A\00"
@errno = global i32 0
@.str.1 = [32 x i8] c"create_dir_subitems(`%s`) func\0A\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [35 x i8] c"Couldn't open the directory `%s`.\0A\00"
define i32 @create_dir_subitems(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %10
%17 = alloca i8, i64 %15
store i64 %15, i64* %11
%18 = load i32, i32* @PATH_MAX
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %12
%21 = load i8*, i8** %5
%22 = call i32* @strcpy(i8* %20, i8* %21)
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = load i8*, i8** %5
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %27)
store i32 -1, i32* %4
store i32 1, i32* %13
br label %56
29: ; preds = %3
%30 = load i8*, i8** %5
%31 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %5
%34 = call i32* @opendir(i8* %33)
store i32* %34, i32** %8
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %52
36: ; preds = %29
br label %37
37: ; preds = %41, %36
%38 = load i32*, i32** %8
%39 = call %struct.dirent* @readdir(i32* %38)
store %struct.dirent* %39, %struct.dirent** %9
%40 = icmp ne %struct.dirent* %39, null
br i1 %40, label %41, label %49
41: ; preds = %37
%42 = call i32* @strcpy(i8* %17, i8* %20)
%43 = load %struct.dirent*, %struct.dirent** %9
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i32 @strcat(i8* %17, i8* %45)
%47 = load i32*, i32** %7
%48 = call i32 @dir_entry(i8* %17, i32* %47)
br label %37
49: ; preds = %37
%50 = load i32*, i32** %8
%51 = call i32 @closedir(i32* %50)
br label %55
52: ; preds = %29
%53 = load i8*, i8** %5
%54 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %49
store i32 0, i32* %4
store i32 1, i32* %13
br label %56
56: ; preds = %55, %24
%57 = load i8*, i8** %10
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [37 x i8] c"create_dir_subitems(`%s`) error: %s\0A\00"
@errno = global i32 0
@.str.1 = [32 x i8] c"create_dir_subitems(`%s`) func\0A\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [35 x i8] c"Couldn't open the directory `%s`.\0A\00"
define i32 @create_dir_subitems(i8* %0, i8* nocapture readnone %1, i32* %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = call i32* @strcpy(i8* %7, i8* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = call i32 @strerror(i32 %11)
%13 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %12)
br label %35
14: ; preds = %3
%15 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%16 = call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32* @opendir(i8* %0)
%18 = icmp eq i32* %17, null
br i1 %18, label %33, label %19
19: ; preds = %14
%20 = call %struct.dirent* @readdir(i32* %17)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %31, label %22
22: ; preds = %19, %22
%23 = phi %struct.dirent* [ %29, %22 ], [ %20, %19 ]
%24 = call i32* @strcpy(i8* %6, i8* %7)
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 @strcat(i8* %6, i8* %26)
%28 = call i32 @dir_entry(i8* %6, i32* %2)
%29 = call %struct.dirent* @readdir(i32* %17)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %31, label %22
31: ; preds = %22, %19
%32 = call i32 @closedir(i32* %17)
br label %35
33: ; preds = %14
%34 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %35
35: ; preds = %31, %33, %10
%36 = phi i32 [ -1, %10 ], [ 0, %33 ], [ 0, %31 ]
ret i32 %36
}