#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 stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ src;

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ chmod(char *, int);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ mc_path_valid(char const *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strtok_r(char *, char *, char **);
int mc_path_mkdir(const char *path) {
  char *token;
  char *last_buf = NULL;
  char seps[] = "/\\";
  char src[256] = {0};
  char dir[256] = {0};
  int depth = 0;
  if (!mc_path_valid(path)) {
    return -1;
  }
  strncpy(src, path, sizeof(src));
  if ('/' == src[0] || '\\' == src[0]) {
    dir[0] = src[0];
  }
  token = strtok_r(src, seps, &last_buf);
  while (token) {
    int is_driver = 0;
    strcat(dir, token);
    if (!is_driver) {
      if (0 != access(dir, 0)) {
        if (0 != mkdir(dir, 0755)) {
          return -1;
        }
        chmod(dir, (7 * 8 * 8) + (5 * 8) + 5);
      } else {
        struct stat st;
        if (0 != lstat(dir, &st)) {
          return -1;
        }
        if (!S_ISDIR(st.st_mode)) {
          return -1;
        }
      }
    }
    strcat(dir, "/");
    depth += 1;
    token = strtok_r(0, seps, &last_buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<mc_path_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0xe42(%rip),%ax
mov    %ax,-0x23(%rbp)
mov    0xe3a(%rip),%al
mov    %al,-0x21(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
movl   $0x0,-0x234(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <mc_path_valid@plt>
cmp    $0x0,%eax
jne    1219 <mc_path_mkdir+0x79>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a3 <mc_path_mkdir+0x203>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1040 <strncpy@plt>
movsbl -0x130(%rbp),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
je     1256 <mc_path_mkdir+0xb6>
movsbl -0x130(%rbp),%ecx
mov    $0x5c,%eax
cmp    %ecx,%eax
jne    1262 <mc_path_mkdir+0xc2>
mov    -0x130(%rbp),%al
mov    %al,-0x230(%rbp)
lea    -0x130(%rbp),%rdi
lea    -0x23(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1080 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     139c <mc_path_mkdir+0x1fc>
movl   $0x0,-0x238(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <strcat@plt>
cmpl   $0x0,-0x238(%rbp)
jne    1360 <mc_path_mkdir+0x1c0>
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
call   10b0 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1309 <mc_path_mkdir+0x169>
lea    -0x230(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     12f3 <mc_path_mkdir+0x153>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a3 <mc_path_mkdir+0x203>
lea    -0x230(%rbp),%rdi
mov    $0x1ed,%esi
call   10a0 <chmod@plt>
jmp    135b <mc_path_mkdir+0x1bb>
lea    -0x230(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   1090 <lstat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1336 <mc_path_mkdir+0x196>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a3 <mc_path_mkdir+0x203>
mov    -0x240(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1356 <mc_path_mkdir+0x1b6>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a3 <mc_path_mkdir+0x203>
jmp    135b <mc_path_mkdir+0x1bb>
jmp    1360 <mc_path_mkdir+0x1c0>
lea    -0x230(%rbp),%rdi
lea    0xc95(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
lea    -0x23(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rdx
call   1080 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
jmp    127a <mc_path_mkdir+0xda>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_path_mkdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdi,%rbx
movq   $0x0,0x18(%rsp)
movb   $0x0,0xe(%rsp)
movw   $0x5c2f,0xc(%rsp)
xorps  %xmm0,%xmm0
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,0x210(%rsp)
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)
call   1030 <mc_path_valid@plt>
test   %eax,%eax
je     139a <mc_path_mkdir+0x20a>
lea    0x20(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    0x20(%rsp),%al
cmp    $0x5c,%al
je     12d5 <mc_path_mkdir+0x145>
cmp    $0x2f,%al
jne    12dc <mc_path_mkdir+0x14c>
mov    %al,0x120(%rsp)
lea    0x20(%rsp),%rdi
lea    0xc(%rsp),%rsi
lea    0x18(%rsp),%rdx
call   1070 <strtok_r@plt>
test   %rax,%rax
je     13a1 <mc_path_mkdir+0x211>
lea    0x120(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0xcf6(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x18(%rsp),%r13
jmp    133f <mc_path_mkdir+0x1af>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   10b0 <strcat@plt>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <strtok_r@plt>
test   %rax,%rax
je     13a3 <mc_path_mkdir+0x213>
mov    %rbx,%rdi
mov    %rax,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <access@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     1380 <mc_path_mkdir+0x1f0>
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
test   %rax,%rax
jne    139a <mc_path_mkdir+0x20a>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1090 <chmod@plt>
jmp    1320 <mc_path_mkdir+0x190>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rsi
call   1080 <lstat@plt>
test   %rax,%rax
jne    139a <mc_path_mkdir+0x20a>
mov    0x10(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
jne    1320 <mc_path_mkdir+0x190>
mov    $0xffffffff,%ebp
jmp    13a3 <mc_path_mkdir+0x213>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@__const.mc_path_mkdir.seps = [3 x i8] c"/\\\00"
@.str = [2 x i8] c"/\00"
define i32 @mc_path_mkdir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [3 x i8]
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.stat
store i8* %0, i8** %3
store i8* null, i8** %5
%12 = bitcast [3 x i8]* %6 to i8*
%13 = bitcast [256 x i8]* %7 to i8*
%14 = bitcast [256 x i8]* %8 to i8*
store i32 0, i32* %9
%15 = load i8*, i8** %3
%16 = call i32 @mc_path_valid(i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %1
store i32 -1, i32* %2
br label %82
19: ; preds = %1
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %3
%22 = call i32 @strncpy(i8* %20, i8* %21, i32 256)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 47, %25
br i1 %26, label %32, label %27
27: ; preds = %19
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 92, %30
br i1 %31, label %32, label %36
32: ; preds = %27, %19
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%34 = load i8, i8* %33
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8 %34, i8* %35
br label %36
36: ; preds = %32, %27
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%39 = call i8* @strtok_r(i8* %37, i8* %38, i8** %5)
store i8* %39, i8** %4
br label %40
40: ; preds = %74, %36
%41 = load i8*, i8** %4
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %81
43: ; preds = %40
store i32 0, i32* %10
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%45 = load i8*, i8** %4
%46 = call i32 @strcat(i8* %44, i8* %45)
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, 0
br i1 %48, label %74, label %49
49: ; preds = %43
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%51 = call i64 @access(i8* %50, i32 0)
%52 = icmp ne i64 0, %51
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = call i64 @mkdir(i8* %54, i32 493)
%56 = icmp ne i64 0, %55
br i1 %56, label %57, label %58
57: ; preds = %53
store i32 -1, i32* %2
br label %82
58: ; preds = %53
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%60 = call i32 @chmod(i8* %59, i32 493)
br label %73
61: ; preds = %49
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%63 = call i64 @lstat(i8* %62, %struct.stat* %11)
%64 = icmp ne i64 0, %63
br i1 %64, label %65, label %66
65: ; preds = %61
store i32 -1, i32* %2
br label %82
66: ; preds = %61
%67 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%68 = load i32, i32* %67
%69 = call i32 @S_ISDIR(i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %72, label %71
71: ; preds = %66
store i32 -1, i32* %2
br label %82
72: ; preds = %66
br label %73
73: ; preds = %72, %58
br label %74
74: ; preds = %73, %43
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%76 = call i32 @strcat(i8* %75, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%77 = load i32, i32* %9
%78 = add nsw i32 %77, 1
store i32 %78, i32* %9
%79 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%80 = call i8* @strtok_r(i8* null, i8* %79, i8** %5)
store i8* %80, i8** %4
br label %40
81: ; preds = %40
store i32 0, i32* %2
br label %82
82: ; preds = %81, %71, %65, %57, %18
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@__const.mc_path_mkdir.seps = [3 x i8] c"/\\\00"
@.str = [2 x i8] c"/\00"
define i32 @mc_path_mkdir(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca %struct.stat
%7 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%11 = tail call i32 @mc_path_valid(i8* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %45, label %13
13: ; preds = %1
%14 = call i32 @strncpy(i8* %9, i8* %0, i32 256)
%15 = load i8, i8* %9
switch i8 %15, label %17 [
i8 92, label %16
i8 47, label %16
]
16: ; preds = %13, %13
store i8 %15, i8* %10
br label %17
17: ; preds = %13, %16
%18 = call i8* @strtok_r(i8* %9, i8* %8, i8** %2)
%19 = icmp eq i8* %18, null
br i1 %19, label %45, label %20
20: ; preds = %17
%21 = bitcast %struct.stat* %6 to i8*
%22 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
br label %23
23: ; preds = %20, %41
%24 = phi i8* [ %18, %20 ], [ %43, %41 ]
%25 = call i32 @strcat(i8* %10, i8* %24)
%26 = call i64 @access(i8* %10, i32 0)
%27 = icmp eq i64 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %23
%29 = call i64 @mkdir(i8* %10, i32 493)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %45
31: ; preds = %28
%32 = call i32 @chmod(i8* %10, i32 493)
br label %41
33: ; preds = %23
%34 = call i64 @lstat(i8* %10, %struct.stat* %6)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* %22
%38 = call i32 @S_ISDIR(i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %45, label %41
40: ; preds = %33
br label %45
41: ; preds = %36, %31
%42 = call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%43 = call i8* @strtok_r(i8* null, i8* %8, i8** %2)
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %23
45: ; preds = %41, %36, %28, %17, %40, %1
%46 = phi i32 [ -1, %1 ], [ -1, %40 ], [ 0, %17 ], [ 0, %41 ], [ -1, %36 ], [ -1, %28 ]
ret i32 %46
}