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

/* Variables and functions */
int /*<<< orphan*/ do_mkdir(char *);
char *full2rela(char *);
char *strchr(char *, char);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
void mkdir_p(const char *fullname) {
  char *ptr = NULL;
  size_t len = strlen(fullname) + 1;
  char fname[len];
  strncpy(fname, fullname, len);
  ptr = full2rela(fname);
  while ((ptr = strchr(ptr, '/'))) {
    *ptr = 0;
    do_mkdir(fname);
    *ptr++ = '/';
    while (*ptr == '/')
      ptr++;
  }
  do_mkdir(fname);
}


x86 assembly (clang, -O0):
<mkdir_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%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,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <strncpy@plt>
mov    -0x30(%rbp),%rdi
call   1030 <full2rela@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     121b <mkdir_p+0xcb>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
call   1050 <do_mkdir@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x2f,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1216 <mkdir_p+0xc6>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11f5 <mkdir_p+0xa5>
jmp    11b7 <mkdir_p+0x67>
mov    -0x30(%rbp),%rdi
call   1050 <do_mkdir@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdir_p>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1060 <strlen@plt>
cltq
lea    0x1(%rax),%rdx
mov    %rsp,%r14
add    $0x10,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strncpy@plt>
mov    %r14,%rdi
call   1030 <full2rela@plt>
mov    %rax,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
test   %rax,%rax
je     11cf <mkdir_p+0x7f>
mov    %rax,%rbx
xchg   %ax,%ax
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1050 <do_mkdir@plt>
movb   $0x2f,(%rbx)
xchg   %ax,%ax
cmpb   $0x2f,0x1(%rbx)
lea    0x1(%rbx),%rbx
je     11b0 <mkdir_p+0x60>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1070 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a0 <mkdir_p+0x50>
mov    %r14,%rdi
call   1050 <do_mkdir@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @mkdir_p(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
store i64 %10, i64* %4
%11 = load i64, i64* %4
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i8*, i8** %2
%15 = load i64, i64* %4
%16 = call i32 @strncpy(i8* %13, i8* %14, i64 %15)
%17 = call i8* @full2rela(i8* %13)
store i8* %17, i8** %3
br label %18
18: ; preds = %35, %1
%19 = load i8*, i8** %3
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %36
22: ; preds = %18
%23 = load i8*, i8** %3
store i8 0, i8* %23
%24 = call i32 @do_mkdir(i8* %13)
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %3
store i8 47, i8* %25
br label %27
27: ; preds = %32, %22
%28 = load i8*, i8** %3
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 47
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %27
35: ; preds = %27
br label %18
36: ; preds = %18
%37 = call i32 @do_mkdir(i8* %13)
%38 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
define void @mkdir_p(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = sext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @strncpy(i8* %5, i8* %0, i64 %4)
%7 = call i8* @full2rela(i8* %5)
%8 = call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %21, label %13
10: ; preds = %16
%11 = call i8* @strchr(i8* dereferenceable(1) %18, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %1, %10
%14 = phi i8* [ %11, %10 ], [ %8, %1 ]
store i8 0, i8* %14
%15 = call i32 @do_mkdir(i8* %5)
store i8 47, i8* %14
br label %16
16: ; preds = %16, %13
%17 = phi i8* [ %14, %13 ], [ %18, %16 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 47
br i1 %20, label %16, label %10
21: ; preds = %10, %1
%22 = call i32 @do_mkdir(i8* %5)
ret void
}