#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*/ F_OK;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ free(char *);
int mkdir(char *, int);
char *strsep(char **, char *);
char *xstrdup(char const *);
void mpkg_mkdirs(const char *path) {
  char *p, *p1, *s;
  p = p1 = xstrdup(path);
  while ((s = strsep(&p, "/"))) {
    if (*s == '\0') {
      if (p)
        *(p - 1) = '/';
      continue;
    }
    if (access(p1, F_OK) == -1) {
      if (mkdir(p1, 0755) == -1)
        err(1, "mkdir: %s", p1);
    }
    if (p)
      *(p - 1) = '/';
  }
  free(p1);
}


x86 assembly (clang, -O0):
<mpkg_mkdirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1227 <mpkg_mkdirs+0xc7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c3 <mpkg_mkdirs+0x63>
cmpq   $0x0,-0x10(%rbp)
je     11be <mpkg_mkdirs+0x5e>
mov    -0x10(%rbp),%rax
movb   $0x2f,-0x1(%rax)
jmp    117d <mpkg_mkdirs+0x1d>
mov    -0x18(%rbp),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    120f <mpkg_mkdirs+0xaf>
mov    -0x18(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    120a <mpkg_mkdirs+0xaa>
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
lea    0xdfd(%rip),%rsi
call   1060 <err@plt>
jmp    120f <mpkg_mkdirs+0xaf>
cmpq   $0x0,-0x10(%rbp)
je     1222 <mpkg_mkdirs+0xc2>
mov    -0x10(%rbp),%rax
movb   $0x2f,-0x1(%rax)
jmp    117d <mpkg_mkdirs+0x1d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpkg_mkdirs>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1050 <xstrdup@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
lea    0xe7f(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1070 <strsep@plt>
test   %rax,%rax
je     1210 <mpkg_mkdirs+0xb0>
lea    0xe65(%rip),%r14
lea    0x8(%rsp),%r15
mov    0x2e31(%rip),%r13
lea    0xe54(%rip),%r12
jmp    11c0 <mpkg_mkdirs+0x60>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     1210 <mpkg_mkdirs+0xb0>
cmpb   $0x0,(%rax)
je     1200 <mpkg_mkdirs+0xa0>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1080 <access@plt>
cmp    $0xffffffff,%eax
jne    1200 <mpkg_mkdirs+0xa0>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1200 <mpkg_mkdirs+0xa0>
mov    $0x1,%edi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <err@plt>
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
test   %rax,%rax
je     11b0 <mpkg_mkdirs+0x50>
movb   $0x2f,-0x1(%rax)
jmp    11b0 <mpkg_mkdirs+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@F_OK = global i32 0
@.str.1 = [10 x i8] c"mkdir: %s\00"
define void @mpkg_mkdirs(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @xstrdup(i8* %0)
store i8* %4, i8** %2
%5 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %1, %17
%8 = phi i8* [ %18, %17 ], [ %5, %1 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11, %29
%15 = phi i8* [ %30, %29 ], [ %12, %11 ]
%16 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 47, i8* %16
br label %17
17: ; preds = %14, %29, %11
%18 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %32, label %7
20: ; preds = %7
%21 = load i32, i32* @F_OK
%22 = call i32 @access(i8* %4, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = call i32 @mkdir(i8* %4, i32 493)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %29
29: ; preds = %24, %27, %20
%30 = load i8*, i8** %2
%31 = icmp eq i8* %30, null
br i1 %31, label %17, label %14
32: ; preds = %17, %1
%33 = call i32 @free(i8* %4)
ret void
}