#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;
scalar_t__ errno;
int mkdir(char *, int);
int mkpath(const char *path) {
  char const *p;
  char npath[32767 + 1] = {0};
  int len = 0;
  for (p = path; *p && len < 32767; p++) {
    if (((*p) == '/') && len > 0) {
      if (mkdir(npath, 0755) == -1)
        if (errno != EEXIST)
          return -1;
    }
    npath[len++] = *p;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mkpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8030,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x8020(%rbp),%rdi
xor    %esi,%esi
mov    $0x8000,%edx
call   1040 <memset@plt>
movl   $0x0,-0x8024(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x8025(%rbp)
je     117f <mkpath+0x5f>
cmpl   $0x7fff,-0x8024(%rbp)
setl   %al
mov    %al,-0x8025(%rbp)
mov    -0x8025(%rbp),%al
test   $0x1,%al
jne    1192 <mkpath+0x72>
jmp    122a <mkpath+0x10a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11f9 <mkpath+0xd9>
cmpl   $0x0,-0x8024(%rbp)
jle    11f9 <mkpath+0xd9>
lea    -0x8020(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11f4 <mkpath+0xd4>
mov    0x2e08(%rip),%rax
mov    (%rax),%rax
mov    0x2e06(%rip),%rcx
cmp    (%rcx),%rax
je     11ef <mkpath+0xcf>
movl   $0xffffffff,-0x4(%rbp)
jmp    1231 <mkpath+0x111>
jmp    11f4 <mkpath+0xd4>
jmp    11f9 <mkpath+0xd9>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8024(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8024(%rbp)
cltq
mov    %cl,-0x8020(%rbp,%rax,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1154 <mkpath+0x34>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8008,%rsp
mov    %rdi,%r15
mov    %rsp,%rdi
xor    %ebp,%ebp
mov    $0x8000,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%r15),%al
test   %al,%al
je     11c9 <mkpath+0xa9>
xor    %ebx,%ebx
mov    %rsp,%r14
mov    0x2e80(%rip),%r12
mov    0x2e81(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x2f,%al
jne    11a0 <mkpath+0x80>
test   %rbx,%rbx
je     11a0 <mkpath+0x80>
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11a0 <mkpath+0x80>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    11c4 <mkpath+0xa4>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbx,1),%eax
mov    %al,(%rsp,%rbx,1)
movzbl 0x1(%r15,%rbx,1),%eax
test   %al,%al
je     11c9 <mkpath+0xa9>
lea    0x1(%rbx),%rcx
cmp    $0x7ffe,%rbx
mov    %rcx,%rbx
jb     1170 <mkpath+0x50>
jmp    11c9 <mkpath+0xa9>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8008,%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
define i32 @mkpath(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [32768 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = bitcast [32768 x i8]* %5 to i8*
store i32 0, i32* %6
%8 = load i8*, i8** %3
store i8* %8, i8** %4
br label %9
9: ; preds = %45, %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 32767
br label %17
17: ; preds = %14, %9
%18 = phi i1 [ false, %9 ], [ %16, %14 ]
br i1 %18, label %19, label %48
19: ; preds = %17
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 47
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %24
%28 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%29 = call i32 @mkdir(i8* %28, i32 493)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = load i64, i64* @EEXIST
%34 = icmp ne i64 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 -1, i32* %2
br label %49
36: ; preds = %31
br label %37
37: ; preds = %36, %27
br label %38
38: ; preds = %37, %24, %19
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 %43
store i8 %40, i8* %44
br label %45
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
br label %9
48: ; preds = %17
store i32 0, i32* %2
br label %49
49: ; preds = %48, %35
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @mkpath(i8* nocapture %0) {
%2 = alloca [32768 x i8]
%3 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %29, label %6
6: ; preds = %1, %20
%7 = phi i64 [ %22, %20 ], [ 0, %1 ]
%8 = phi i8 [ %25, %20 ], [ %4, %1 ]
%9 = phi i8* [ %24, %20 ], [ %0, %1 ]
%10 = icmp eq i8 %8, 47
%11 = icmp ne i64 %7, 0
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %20
13: ; preds = %6
%14 = call i32 @mkdir(i8* %3, i32 493)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EEXIST
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %13, %16, %6
%21 = load i8, i8* %9
%22 = add nuw nsw i64 %7, 1
%23 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %7
store i8 %21, i8* %23
%24 = getelementptr inbounds i8, i8* %9, i64 1
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
%27 = icmp ult i64 %7, 32766
%28 = select i1 %26, i1 %27, i1 false
br i1 %28, label %6, label %29
29: ; preds = %16, %20, %1
%30 = phi i32 [ 0, %1 ], [ 0, %20 ], [ -1, %16 ]
ret i32 %30
}