#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 */
scalar_t__ EEXIST;
char *alloca(scalar_t__);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int mkdir(char *, int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strerror(scalar_t__);
scalar_t__ strlen(char const *);
int pmkdir(const char *path, int mode) {
  char *p;
  char *t;
  p = alloca(strlen(path) + 1);
  strcpy(p, path);
  t = p + 1;
  while (0 != (t = strchr(t, '/'))) {
    *t = 0;
    if (-1 == mkdir(p, mode) && errno != EEXIST) {
      fprintf(stderr, "Failed to create directory '%s': %s\n", p,
              strerror(errno));
      return -1;
    }
    *t++ = '/';
  }
  return 0;
}


x86 assembly (clang, -O0):
<pmkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1269 <pmkdir+0xf9>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <mkdir@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1252 <pmkdir+0xe2>
mov    0x2dd6(%rip),%rax
mov    (%rax),%rax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
je     1252 <pmkdir+0xe2>
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdbf(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <pmkdir+0x100>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x2f,(%rax)
jmp    11b1 <pmkdir+0x41>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pmkdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbp
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <alloca@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0x1(%rbx),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1233 <pmkdir+0xc3>
mov    %rax,%rbp
mov    0x2e0f(%rip),%r12
mov    0x2e18(%rip),%r13
jmp    11ed <pmkdir+0x7d>
nopw   0x0(%rax,%rax,1)
movb   $0x2f,0x0(%rbp)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1233 <pmkdir+0xc3>
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11d0 <pmkdir+0x60>
mov    (%r12),%rdi
cmp    0x0(%r13),%rdi
je     11d0 <pmkdir+0x60>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ebp
call   1090 <strerror@plt>
lea    0xde0(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"Failed to create directory '%s': %s\0A\00"
define i32 @pmkdir(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = call i8* @alloca(i64 %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %7
br label %17
17: ; preds = %37, %2
%18 = load i8*, i8** %7
%19 = call i8* @strchr(i8* %18, i8 signext 47)
store i8* %19, i8** %7
%20 = icmp ne i8* null, %19
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = load i8*, i8** %7
store i8 0, i8* %22
%23 = load i8*, i8** %6
%24 = load i32, i32* %5
%25 = call i32 @mkdir(i8* %23, i32 %24)
%26 = icmp eq i32 -1, %25
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i64, i64* @errno
%29 = load i64, i64* @EEXIST
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %6
%34 = load i64, i64* @errno
%35 = call i8* @strerror(i64 %34)
%36 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %35)
store i32 -1, i32* %3
br label %41
37: ; preds = %27, %21
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %7
store i8 47, i8* %38
br label %17
40: ; preds = %17
store i32 0, i32* %3
br label %41
41: ; preds = %40, %31
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [37 x i8] c"Failed to create directory '%s': %s\0A\00"
define i32 @pmkdir(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 1
%5 = tail call i8* @alloca(i64 %4)
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
%7 = getelementptr inbounds i8, i8* %5, i64 1
%8 = tail call i8* @strchr(i8* %7, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %26, label %10
10: ; preds = %2, %22
%11 = phi i8* [ %24, %22 ], [ %8, %2 ]
store i8 0, i8* %11
%12 = tail call i32 @mkdir(i8* %5, i32 %1)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @EEXIST
%17 = icmp eq i64 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* @stderr
%20 = tail call i8* @strerror(i64 %15)
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %20)
br label %26
22: ; preds = %14, %10
store i8 47, i8* %11
%23 = getelementptr inbounds i8, i8* %11, i64 1
%24 = tail call i8* @strchr(i8* %23, i8 signext 47)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %10
26: ; preds = %22, %2, %18
%27 = phi i32 [ -1, %18 ], [ 0, %2 ], [ 0, %22 ]
ret i32 %27
}