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

/* Variables and functions */
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
size_t strlen(char *);
int rmkdir(const char *path, int mode) {
  char tmp[260];
  char *p = NULL;
  size_t len;
  snprintf(tmp, sizeof(tmp), "%s", path);
  len = strlen(tmp);
  if (len >= sizeof(tmp)) {
    return -1;
  }
  if (tmp[len - 1] == '/') {
    tmp[len - 1] = 0;
  }
  for (p = tmp + 1; *p; p++) {
    if (*p != '/')
      continue;
    if (*(p - 1) == ':')
      continue;
    *p = 0;
    mkdir(tmp, mode);
    *p = '/';
  }
  mkdir(tmp, mode);
  return 0;
}


x86 assembly (clang, -O0):
<rmkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x104,%esi
lea    0xe9c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x104,-0x130(%rbp)
jb     1199 <rmkdir+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <rmkdir+0x13b>
mov    -0x130(%rbp),%rax
sub    $0x1,%rax
movsbl -0x120(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11c8 <rmkdir+0x98>
mov    -0x130(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rax
cmpb   $0x0,(%rax)
je     1255 <rmkdir+0x125>
mov    -0x128(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1202 <rmkdir+0xd2>
jmp    123e <rmkdir+0x10e>
mov    -0x128(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x3a,%eax
jne    121b <rmkdir+0xeb>
jmp    123e <rmkdir+0x10e>
mov    -0x128(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mkdir@plt>
mov    -0x128(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
jmp    11da <rmkdir+0xaa>
lea    -0x120(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <mkdir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmkdir>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %esi,%ebp
mov    %rdi,%rcx
lea    0xeb9(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x104,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0xffffffff,%ecx
cmp    $0x103,%rax
ja     11c3 <rmkdir+0x93>
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    1179 <rmkdir+0x49>
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0x1(%rsp),%rbx
mov    %rsp,%r14
jmp    1198 <rmkdir+0x68>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %al,%al
je     11b7 <rmkdir+0x87>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    1190 <rmkdir+0x60>
cmpb   $0x3a,-0x1(%rbx)
je     1194 <rmkdir+0x64>
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
jmp    1194 <rmkdir+0x64>
mov    %rsp,%rdi
mov    %ebp,%esi
call   1030 <mkdir@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i32 @rmkdir(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [260 x i8]
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* null, i8** %7
%9 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 @snprintf(i8* %9, i32 260, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = icmp uge i64 %14, 260
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 -1, i32* %3
br label %61
17: ; preds = %2
%18 = load i64, i64* %8
%19 = sub i64 %18, 1
%20 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i64, i64* %8
%26 = sub i64 %25, 1
%27 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %24, %17
%29 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 0
%30 = getelementptr inbounds i8, i8* %29, i64 1
store i8* %30, i8** %7
br label %31
31: ; preds = %54, %28
%32 = load i8*, i8** %7
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %57
35: ; preds = %31
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 47
br i1 %39, label %40, label %41
40: ; preds = %35
br label %54
41: ; preds = %35
%42 = load i8*, i8** %7
%43 = getelementptr inbounds i8, i8* %42, i64 -1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 58
br i1 %46, label %47, label %48
47: ; preds = %41
br label %54
48: ; preds = %41
%49 = load i8*, i8** %7
store i8 0, i8* %49
%50 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 0
%51 = load i32, i32* %5
%52 = call i32 @mkdir(i8* %50, i32 %51)
%53 = load i8*, i8** %7
store i8 47, i8* %53
br label %54
54: ; preds = %48, %47, %40
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %7
br label %31
57: ; preds = %31
%58 = getelementptr inbounds [260 x i8], [260 x i8]* %6, i64 0, i64 0
%59 = load i32, i32* %5
%60 = call i32 @mkdir(i8* %58, i32 %59)
store i32 0, i32* %3
br label %61
61: ; preds = %57, %16
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @rmkdir(i8* %0, i32 %1) {
%3 = alloca [260 x i8]
%4 = getelementptr inbounds [260 x i8], [260 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 260, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = call i64 @strlen(i8* %4)
%7 = icmp ugt i64 %6, 259
br i1 %7, label %29, label %8
8: ; preds = %2
%9 = add nsw i64 %6, -1
%10 = getelementptr inbounds [260 x i8], [260 x i8]* %3, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %14
13: ; preds = %8
store i8 0, i8* %10
br label %14
14: ; preds = %13, %8
%15 = getelementptr inbounds [260 x i8], [260 x i8]* %3, i64 0, i64 1
br label %16
16: ; preds = %25, %14
%17 = phi i8* [ %15, %14 ], [ %26, %25 ]
%18 = load i8, i8* %17
switch i8 %18, label %25 [
i8 0, label %27
i8 47, label %19
]
19: ; preds = %16
%20 = getelementptr inbounds i8, i8* %17, i64 -1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 58
br i1 %22, label %25, label %23
23: ; preds = %19
store i8 0, i8* %17
%24 = call i32 @mkdir(i8* %4, i32 %1)
store i8 47, i8* %17
br label %25
25: ; preds = %16, %19, %23
%26 = getelementptr inbounds i8, i8* %17, i64 1
br label %16
27: ; preds = %16
%28 = call i32 @mkdir(i8* %4, i32 %1)
br label %29
29: ; preds = %2, %27
%30 = phi i32 [ 0, %27 ], [ -1, %2 ]
ret i32 %30
}