#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*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
size_t strlen(char *);
void prv_mkdir(const char *dir) {
  DIR *_dir = opendir(dir);
  if (_dir) {
    closedir(_dir);
    return;
  }
  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, 0777);
      *p = '/';
    }
  }
  mkdir(tmp, 0777);
}


x86 assembly (clang, -O0):
<prv_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1185 <prv_mkdir+0x35>
mov    -0x10(%rbp),%rdi
call   1070 <closedir@plt>
jmp    1275 <prv_mkdir+0x125>
movq   $0x0,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe59(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11ee <prv_mkdir+0x9e>
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     1264 <prv_mkdir+0x114>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1248 <prv_mkdir+0xf8>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    -0x118(%rbp),%rax
movb   $0x2f,(%rax)
jmp    124d <prv_mkdir+0xfd>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    1200 <prv_mkdir+0xb0>
lea    -0x110(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prv_mkdir>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rbx
call   1040 <opendir@plt>
test   %rax,%rax
je     1179 <prv_mkdir+0x29>
mov    %rax,%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1070 <closedir@plt>
lea    0xe80(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    11a8 <prv_mkdir+0x58>
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0x1(%rsp),%rbx
mov    %rsp,%r14
jmp    11d7 <prv_mkdir+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     11c0 <prv_mkdir+0x70>
test   %al,%al
jne    11d3 <prv_mkdir+0x83>
mov    %rsp,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

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