#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 */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ mkdir_recursive(char *, int);
char *strdup(char const *);
void create_parent_directory_hierarchy(const char *pathname, int mode) {
  char *parse, *parent, *mark = NULL, *stop = NULL;
  if ((parse = parent = strdup(pathname)) != NULL) {
    while (*parse) {
      stop = mark;
      while (*parse && (*parse != '/') && (*parse != '\\'))
        ++parse;
      if (*parse)
        mark = parse;
      while ((*parse == '/') || (*parse == '\\'))
        ++parse;
    }
    if (stop != NULL) {
      *stop = '\0';
      mkdir_recursive(parent, mode);
    }
    free(parent);
  }
}


x86 assembly (clang, -O0):
<create_parent_directory_hierarchy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     126b <create_parent_directory_hierarchy+0x13b>
jmp    116f <create_parent_directory_hierarchy+0x3f>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1244 <create_parent_directory_hierarchy+0x114>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11be <create_parent_directory_hierarchy+0x8e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x31(%rbp)
je     11be <create_parent_directory_hierarchy+0x8e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11ce <create_parent_directory_hierarchy+0x9e>
jmp    11df <create_parent_directory_hierarchy+0xaf>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1184 <create_parent_directory_hierarchy+0x54>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11f4 <create_parent_directory_hierarchy+0xc4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11f9 <create_parent_directory_hierarchy+0xc9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x2f,%ecx
mov    %al,-0x32(%rbp)
je     121e <create_parent_directory_hierarchy+0xee>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
sete   %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    122e <create_parent_directory_hierarchy+0xfe>
jmp    123f <create_parent_directory_hierarchy+0x10f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11f9 <create_parent_directory_hierarchy+0xc9>
jmp    116f <create_parent_directory_hierarchy+0x3f>
cmpq   $0x0,-0x30(%rbp)
je     1262 <create_parent_directory_hierarchy+0x132>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <mkdir_recursive@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_parent_directory_hierarchy>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
call   1040 <strdup@plt>
test   %rax,%rax
je     11ba <create_parent_directory_hierarchy+0x8a>
mov    %rax,%rbp
mov    (%rax),%dl
test   %dl,%dl
je     11ae <create_parent_directory_hierarchy+0x7e>
xor    %ecx,%ecx
mov    %rbp,%rsi
nop
mov    %rcx,%rax
mov    %edx,%ebx
mov    %rsi,%rcx
test   %bl,%bl
je     1176 <create_parent_directory_hierarchy+0x46>
nopl   0x0(%rax)
cmp    $0x2f,%bl
je     1176 <create_parent_directory_hierarchy+0x46>
cmp    $0x5c,%bl
je     1176 <create_parent_directory_hierarchy+0x46>
movzbl 0x1(%rcx),%ebx
add    $0x1,%rcx
test   %bl,%bl
jne    1160 <create_parent_directory_hierarchy+0x30>
mov    %rcx,%rsi
jmp    1184 <create_parent_directory_hierarchy+0x54>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rsi
movzbl (%rsi),%edx
cmp    $0x5c,%dl
je     1180 <create_parent_directory_hierarchy+0x50>
cmp    $0x2f,%dl
je     1180 <create_parent_directory_hierarchy+0x50>
test   %bl,%bl
cmove  %rax,%rcx
test   %dl,%dl
jne    1150 <create_parent_directory_hierarchy+0x20>
test   %rax,%rax
je     11ae <create_parent_directory_hierarchy+0x7e>
movb   $0x0,(%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <mkdir_recursive@plt>
mov    %rbp,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <free@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @create_parent_directory_hierarchy(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %7
store i8* null, i8** %8
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %6
store i8* %10, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %73
12: ; preds = %2
br label %13
13: ; preds = %61, %12
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %62
17: ; preds = %13
%18 = load i8*, i8** %7
store i8* %18, i8** %8
br label %19
19: ; preds = %36, %17
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %34
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 47
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 92
br label %34
34: ; preds = %29, %24, %19
%35 = phi i1 [ false, %24 ], [ false, %19 ], [ %33, %29 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
br label %19
39: ; preds = %34
%40 = load i8*, i8** %5
%41 = load i8, i8* %40
%42 = icmp ne i8 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i8*, i8** %5
store i8* %44, i8** %7
br label %45
45: ; preds = %43, %39
br label %46
46: ; preds = %58, %45
%47 = load i8*, i8** %5
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 47
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = load i8*, i8** %5
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 92
br label %56
56: ; preds = %51, %46
%57 = phi i1 [ true, %46 ], [ %55, %51 ]
br i1 %57, label %58, label %61
58: ; preds = %56
%59 = load i8*, i8** %5
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %5
br label %46
61: ; preds = %56
br label %13
62: ; preds = %13
%63 = load i8*, i8** %8
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load i8*, i8** %8
store i8 0, i8* %66
%67 = load i8*, i8** %6
%68 = load i32, i32* %4
%69 = call i32 @mkdir_recursive(i8* %67, i32 %68)
br label %70
70: ; preds = %65, %62
%71 = load i8*, i8** %6
%72 = call i32 @free(i8* %71)
br label %73
73: ; preds = %70, %2
ret void
}

LLVM IR (-O2):
define void @create_parent_directory_hierarchy(i8* nocapture %0, i32 %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %34, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %32, label %11
8: ; preds = %23
%9 = select i1 %22, i8* %13, i8* %17
%10 = icmp eq i8 %25, 0
br i1 %10, label %28, label %11
11: ; preds = %5, %8
%12 = phi i8 [ %25, %8 ], [ %6, %5 ]
%13 = phi i8* [ %9, %8 ], [ null, %5 ]
%14 = phi i8* [ %24, %8 ], [ %3, %5 ]
br label %15
15: ; preds = %11, %18
%16 = phi i8 [ %20, %18 ], [ %12, %11 ]
%17 = phi i8* [ %19, %18 ], [ %14, %11 ]
switch i8 %16, label %18 [
i8 0, label %21
i8 47, label %21
i8 92, label %21
]
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = load i8, i8* %19
br label %15
21: ; preds = %15, %15, %15
%22 = icmp eq i8 %16, 0
br label %23
23: ; preds = %26, %21
%24 = phi i8* [ %17, %21 ], [ %27, %26 ]
%25 = load i8, i8* %24
switch i8 %25, label %8 [
i8 47, label %26
i8 92, label %26
]
26: ; preds = %23, %23
%27 = getelementptr inbounds i8, i8* %24, i64 1
br label %23
28: ; preds = %8
%29 = icmp eq i8* %13, null
br i1 %29, label %32, label %30
30: ; preds = %28
store i8 0, i8* %13
%31 = tail call i32 @mkdir_recursive(i8* %3, i32 %1)
br label %32
32: ; preds = %5, %30, %28
%33 = tail call i32 @free(i8* %3)
br label %34
34: ; preds = %32, %2
ret void
}