#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 *);
void mkpath(const char *dir) {
  char tmp[1024];
  char *p;
  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, 0755);
      *p = '/';
    }
  mkdir(tmp, 0755);
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x400,%esi
lea    0xeaa(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
sub    $0x1,%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    119d <mkpath+0x6d>
mov    -0x420(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
mov    -0x418(%rbp),%rax
cmpb   $0x0,(%rax)
je     1213 <mkpath+0xe3>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11f7 <mkpath+0xc7>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    -0x418(%rbp),%rax
movb   $0x2f,(%rax)
jmp    11fc <mkpath+0xcc>
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    11af <mkpath+0x7f>
lea    -0x410(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpath>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rcx
lea    0xebc(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1168 <mkpath+0x38>
movb   $0x0,-0x1(%rsp,%rax,1)
lea    0x1(%rsp),%rbx
mov    %rsp,%r14
jmp    1197 <mkpath+0x67>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
je     1180 <mkpath+0x50>
test   %al,%al
jne    1193 <mkpath+0x63>
mov    %rsp,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @mkpath(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [1024 x i8], [1024 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 [1024 x i8], [1024 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 [1024 x i8], [1024 x i8]* %3, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %17, %1
%22 = getelementptr inbounds [1024 x i8], [1024 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 = %39, %21
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %42
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 %38
33: ; preds = %28
%34 = load i8*, i8** %4
store i8 0, i8* %34
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%36 = call i32 @mkdir(i8* %35, i32 493)
%37 = load i8*, i8** %4
store i8 47, i8* %37
br label %38
38: ; preds = %33, %28
br label %39
39: ; preds = %38
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
br label %24
42: ; preds = %24
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%44 = call i32 @mkdir(i8* %43, i32 493)
ret void
}

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