#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 */
scalar_t__ EEXIST;
scalar_t__ errno;
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strtok(char *, char *);
int /*<<< orphan*/ ui_print(char *, char *, scalar_t__);
int recursive_mkdir(const char *path) {
  char pathCpy[512];
  char wholePath[512];
  strcpy(pathCpy, path);
  strcpy(wholePath, "/");
  char *tok = strtok(pathCpy, "/");
  while (tok) {
    strcat(wholePath, tok);
    if (mkdir(wholePath, 0777) && errno != EEXIST) {
      ui_print("E:"
               "Unable to create folder: %s  (errno=%d)\n",
               wholePath, errno);
      return -1;
    }
    strcat(wholePath, "/");
    tok = strtok(NULL, "/");
  }
  if (mkdir(wholePath, 0777) && errno != EEXIST)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<recursive_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     124a <recursive_mkdir+0xfa>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x410(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     121b <recursive_mkdir+0xcb>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
je     121b <recursive_mkdir+0xcb>
lea    -0x410(%rbp),%rsi
mov    0x2dd8(%rip),%rax
mov    (%rax),%rdx
lea    0xdf8(%rip),%rdi
call   1050 <ui_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1292 <recursive_mkdir+0x142>
lea    -0x410(%rbp),%rdi
lea    0xdd7(%rip),%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc7(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x418(%rbp)
jmp    119c <recursive_mkdir+0x4c>
lea    -0x410(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     128b <recursive_mkdir+0x13b>
mov    0x2d6c(%rip),%rax
mov    (%rax),%rax
mov    0x2d6a(%rip),%rcx
cmp    (%rcx),%rax
je     128b <recursive_mkdir+0x13b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1292 <recursive_mkdir+0x142>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_mkdir>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rsi
lea    0x200(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xe88(%rip),%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     1206 <recursive_mkdir+0xb6>
mov    %rsp,%rbx
lea    0xe63(%rip),%r14
mov    0x2e34(%rip),%r15
mov    0x2e35(%rip),%r12
jmp    11ca <recursive_mkdir+0x7a>
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     1206 <recursive_mkdir+0xb6>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     11b0 <recursive_mkdir+0x60>
mov    (%r15),%rdx
cmp    (%r12),%rdx
je     11b0 <recursive_mkdir+0x60>
lea    0xe0b(%rip),%rdi
mov    %rsp,%rsi
call   1050 <ui_print@plt>
mov    $0xffffffff,%eax
jmp    1235 <recursive_mkdir+0xe5>
mov    %rsp,%rdi
mov    $0x1ff,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     1233 <recursive_mkdir+0xe3>
mov    0x2db9(%rip),%rax
mov    (%rax),%rcx
mov    0x2db7(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    1235 <recursive_mkdir+0xe5>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [43 x i8] c"E:Unable to create folder: %s (errno=%d)\0A\00"
define i32 @recursive_mkdir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%13 = call i8* @strtok(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %6
br label %14
14: ; preds = %32, %1
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%22 = call i64 @mkdir(i8* %21, i32 511)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %17
%25 = load i64, i64* @errno
%26 = load i64, i64* @EEXIST
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%30 = load i64, i64* @errno
%31 = call i32 @ui_print(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %29, i64 %30)
store i32 -1, i32* %2
br label %46
32: ; preds = %24, %17
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %6
br label %14
36: ; preds = %14
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%38 = call i64 @mkdir(i8* %37, i32 511)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i64, i64* @errno
%42 = load i64, i64* @EEXIST
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 -1, i32* %2
br label %46
45: ; preds = %40, %36
store i32 0, i32* %2
br label %46
46: ; preds = %45, %44, %28
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [43 x i8] c"E:Unable to create folder: %s (errno=%d)\0A\00"
define i32 @recursive_mkdir(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = call i32 @strcpy(i8* %4, i8* %0)
%7 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %1, %21
%11 = phi i8* [ %23, %21 ], [ %8, %1 ]
%12 = call i32 @strcat(i8* %5, i8* %11)
%13 = call i64 @mkdir(i8* %5, i32 511)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp eq i64 %16, %17
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @ui_print(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i8* %5, i64 %16)
br label %33
21: ; preds = %15, %10
%22 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %10
25: ; preds = %21, %1
%26 = call i64 @mkdir(i8* %5, i32 511)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = load i64, i64* @errno
%30 = load i64, i64* @EEXIST
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %28, %25
br label %33
33: ; preds = %28, %32, %19
%34 = phi i32 [ -1, %19 ], [ 0, %32 ], [ -1, %28 ]
ret i32 %34
}