#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 mode_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ mkdirv(char *, int const);
char *strdup(char const *);
void mkdirp(const char *path) {
  const mode_t mode = 0777;
  char *copy = NULL;
  char *c;
  copy = strdup(path);
  if (copy == NULL)
    err(EXIT_FAILURE, "strdup");
  for (c = copy; *c != '\0'; c++) {
    if (*c == '/')
      *c = '\0';
  }
  if (*copy)
    mkdirv(copy, mode);
  for (c = copy; *path != '\0'; path++, c++) {
    if (*path != '/')
      continue;
    *c = '/';
    mkdirv(copy, mode);
  }
  free(copy);
}


x86 assembly (clang, -O0):
<mkdirp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1ff,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1188 <mkdirp+0x48>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1050 <err@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cd <mkdirp+0x8d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b7 <mkdirp+0x77>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    11bc <mkdirp+0x7c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1190 <mkdirp+0x50>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e8 <mkdirp+0xa8>
mov    -0x18(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdirv@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1247 <mkdirp+0x107>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1215 <mkdirp+0xd5>
jmp    122a <mkdirp+0xea>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rdi
mov    $0x1ff,%esi
call   1040 <mkdirv@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11f0 <mkdirp+0xb0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdirp>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1060 <strdup@plt>
mov    %rax,%r15
test   %rax,%rax
jne    116a <mkdirp+0x2a>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xe9b(%rip),%rsi
call   1050 <err@plt>
mov    %r15,%rax
jmp    1177 <mkdirp+0x37>
nop
movb   $0x0,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x2f,%cl
je     1170 <mkdirp+0x30>
test   %cl,%cl
jne    1173 <mkdirp+0x33>
cmpb   $0x0,(%r15)
je     1196 <mkdirp+0x56>
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1040 <mkdirv@plt>
xor    %ebx,%ebx
jmp    11b6 <mkdirp+0x76>
nopw   0x0(%rax,%rax,1)
movb   $0x2f,(%r15,%rbx,1)
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1040 <mkdirv@plt>
add    $0x1,%rbx
movzbl (%r14,%rbx,1),%eax
cmp    $0x2f,%al
je     11a0 <mkdirp+0x60>
test   %al,%al
jne    11b2 <mkdirp+0x72>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [7 x i8] c"strdup\00"
define void @mkdirp(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @err(i32 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %4, %1
br label %8
8: ; preds = %7, %12
%9 = phi i8* [ %13, %12 ], [ %2, %7 ]
%10 = load i8, i8* %9
switch i8 %10, label %12 [
i8 0, label %14
i8 47, label %11
]
11: ; preds = %8
store i8 0, i8* %9
br label %12
12: ; preds = %8, %11
%13 = getelementptr inbounds i8, i8* %9, i64 1
br label %8
14: ; preds = %8
%15 = load i8, i8* %2
%16 = icmp eq i8 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @mkdirv(i8* %2, i32 511)
br label %19
19: ; preds = %17, %14
br label %20
20: ; preds = %19, %26
%21 = phi i8* [ %27, %26 ], [ %0, %19 ]
%22 = phi i8* [ %28, %26 ], [ %2, %19 ]
%23 = load i8, i8* %21
switch i8 %23, label %26 [
i8 0, label %29
i8 47, label %24
]
24: ; preds = %20
store i8 47, i8* %22
%25 = tail call i32 @mkdirv(i8* %2, i32 511)
br label %26
26: ; preds = %20, %24
%27 = getelementptr inbounds i8, i8* %21, i64 1
%28 = getelementptr inbounds i8, i8* %22, i64 1
br label %20
29: ; preds = %20
%30 = tail call i32 @free(i8* %2)
ret void
}