#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*/ S_IRWXU;
int /*<<< orphan*/ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
size_t strlen(char *);
void recursive_mkdir(const char *dir) {
  char tmp[256];
  char *p = NULL;
  size_t len;
  snprintf(tmp, sizeof(tmp), "%s", dir);
  len = strlen(tmp);
  if (tmp[len - 1] == '/')
    tmp[len - 1] = 0;
  for (p = tmp + 1; *p; p++) {
    if (*p == '/') {
      *p = 0;
      mkdir(tmp, S_IRWXU);
      *p = '/';
    }
  }
  mkdir(tmp, S_IRWXU);
}


x86 assembly (clang, -O0):
<recursive_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe9f(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11a8 <recursive_mkdir+0x78>
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
cmpb   $0x0,(%rax)
je     1222 <recursive_mkdir+0xf2>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1206 <recursive_mkdir+0xd6>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
mov    -0x118(%rbp),%rax
movb   $0x2f,(%rax)
jmp    120b <recursive_mkdir+0xdb>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    11ba <recursive_mkdir+0x8a>
lea    -0x110(%rbp),%rdi
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_mkdir>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rcx
lea    0xeba(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    116a <recursive_mkdir+0x3a>
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0x1(%rsp),%rbx
mov    0x2e72(%rip),%r14
mov    %rsp,%r15
jmp    1195 <recursive_mkdir+0x65>
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
mov    (%r14),%esi
mov    %r15,%rdi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     1180 <recursive_mkdir+0x50>
test   %al,%al
jne    1191 <recursive_mkdir+0x61>
mov    (%r14),%esi
mov    %rsp,%rdi
call   1030 <mkdir@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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