#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__ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
void createPath(const char *name, int mode) {
  char *cp;
  char *cpOld;
  char buf[100];
  strcpy(buf, name);
  cp = strchr(buf, '/');
  while (cp) {
    cpOld = cp;
    cp = strchr(cp + 1, '/');
    *cpOld = '\0';
    if (mkdir(buf, cp ? 0777 : mode) == 0)
      printf("Directory \"%s\" created\n", buf);
    *cpOld = '/';
  }
}


x86 assembly (clang, -O0):
<createPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1214 <createPath+0xd4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d0 <createPath+0x90>
mov    $0x1ff,%eax
mov    %eax,-0x9c(%rbp)
jmp    11d9 <createPath+0x99>
mov    -0xc(%rbp),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0x9c(%rbp),%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jne    1208 <createPath+0xc8>
lea    -0x90(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
jmp    1177 <createPath+0x37>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createPath>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %esi,%r12d
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c5 <createPath+0x85>
mov    %rax,%rbx
mov    %rsp,%r14
lea    0xe84(%rip),%r15
jmp    118b <createPath+0x4b>
xchg   %ax,%ax
movb   $0x2f,(%rbx)
mov    %rbp,%rbx
test   %rbp,%rbp
je     11c5 <createPath+0x85>
lea    0x1(%rbx),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
movb   $0x0,(%rbx)
test   %rax,%rax
mov    $0x1ff,%esi
cmove  %r12d,%esi
mov    %r14,%rdi
call   1040 <mkdir@plt>
test   %rax,%rax
jne    1180 <createPath+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
jmp    1180 <createPath+0x40>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Directory \22%s\22 created\0A\00"
define void @createPath(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [100 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%12 = call i8* @strchr(i8* %11, i8 signext 47)
store i8* %12, i8** %5
br label %13
13: ; preds = %35, %2
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %37
16: ; preds = %13
%17 = load i8*, i8** %5
store i8* %17, i8** %6
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %5
%21 = load i8*, i8** %6
store i8 0, i8* %21
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %16
br label %28
26: ; preds = %16
%27 = load i32, i32* %4
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ 511, %25 ], [ %27, %26 ]
%30 = call i64 @mkdir(i8* %22, i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%34 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %28
%36 = load i8*, i8** %6
store i8 47, i8* %36
br label %13
37: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Directory \22%s\22 created\0A\00"
define void @createPath(i8* %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* %0)
%6 = call i8* @strchr(i8* %4, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %19, label %8
8: ; preds = %2, %18
%9 = phi i8* [ %11, %18 ], [ %6, %2 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = call i8* @strchr(i8* %10, i8 signext 47)
store i8 0, i8* %9
%12 = icmp eq i8* %11, null
%13 = select i1 %12, i32 %1, i32 511
%14 = call i64 @mkdir(i8* %4, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %18
18: ; preds = %16, %8
store i8 47, i8* %9
br i1 %12, label %19, label %8
19: ; preds = %18, %2
ret void
}