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

/* 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 _mkdir(const char *dir, mode_t mode) {
  char tmp[512];
  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, mode);
      *p = '/';
    }
  mkdir(tmp, S_IRWXU);
}


x86 assembly (clang, -O0):
<_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
lea    0xe9c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x210(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
sub    $0x1,%rax
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11ab <_mkdir+0x7b>
mov    -0x220(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rax
cmpb   $0x0,(%rax)
je     121f <_mkdir+0xef>
mov    -0x218(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1203 <_mkdir+0xd3>
mov    -0x218(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x210(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <mkdir@plt>
mov    -0x218(%rbp),%rax
movb   $0x2f,(%rax)
jmp    1208 <_mkdir+0xd8>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x218(%rbp)
jmp    11bd <_mkdir+0x8d>
lea    -0x210(%rbp),%rdi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
call   1030 <mkdir@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mkdir>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %esi,%ebp
mov    %rdi,%rcx
lea    0xeb9(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    116c <_mkdir+0x3c>
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0x1(%rsp),%rbx
mov    %rsp,%r14
jmp    1194 <_mkdir+0x64>
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     1180 <_mkdir+0x50>
test   %al,%al
jne    1190 <_mkdir+0x60>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <mkdir@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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