#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 PATH_MAX;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
size_t strlen(char *);
void _mkdir(const char *dir) {
  char tmp[PATH_MAX];
  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):
<_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
lea    0xe83(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11bb <_mkdir+0x8b>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     121a <_mkdir+0xea>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1204 <_mkdir+0xd4>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
jmp    1209 <_mkdir+0xd9>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c7 <_mkdir+0x97>
mov    -0x30(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mkdir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rcx
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r15
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xe9f(%rip),%rdx
mov    %r15,%rdi
call   1050 <snprintf@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%r15,1)
jne    117f <_mkdir+0x4f>
movb   $0x0,-0x1(%r15,%rax,1)
lea    0x1(%r15),%rbx
mov    0x2e56(%rip),%r14
jmp    11a5 <_mkdir+0x75>
nopl   0x0(%rax)
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     1190 <_mkdir+0x60>
test   %al,%al
je     11b6 <_mkdir+0x86>
add    $0x1,%rbx
jmp    11a5 <_mkdir+0x75>
mov    (%r14),%esi
mov    %r15,%rdi
call   1030 <mkdir@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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