#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 */
#define EEXIST 129
#define ENOENT 128
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
int S_IXGRP;
int S_IXOTH;
int errno;
scalar_t__ mkdir(char const *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int create_path(const char path[]) {
  char uppath[256], *p;
  int ierr = 0;
  if (mkdir(path, S_IRWXU | (S_IRGRP | S_IXGRP) | (S_IROTH | S_IXOTH))) {
    switch (errno) {
    case ENOENT:
      strncpy(uppath, path, 256);
      p = uppath + strlen(uppath);
      while (*p != '/')
        p--;
      *p = 0;
      if (!create_path(uppath))
        ierr = create_path(path);
      break;
    case EEXIST:
      ierr = 0;
      break;
    default:
      ierr = errno;
    }
  }
  return ierr;
}


x86 assembly (clang, -O0):
<create_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x11c(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
or     %eax,%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    0x2e56(%rip),%rcx
or     (%rcx),%eax
or     %eax,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1297 <create_path+0x157>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x120(%rbp)
sub    $0x80,%eax
je     11d2 <create_path+0x92>
jmp    11bc <create_path+0x7c>
mov    -0x120(%rbp),%eax
sub    $0x81,%eax
je     1274 <create_path+0x134>
jmp    1283 <create_path+0x143>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x128(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1241 <create_path+0x101>
mov    -0x118(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x118(%rbp)
jmp    1217 <create_path+0xd7>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
call   1060 <create_path@plt>
cmp    $0x0,%eax
jne    126f <create_path+0x12f>
mov    -0x8(%rbp),%rdi
call   1060 <create_path@plt>
mov    %eax,-0x11c(%rbp)
jmp    1292 <create_path+0x152>
movl   $0x0,-0x11c(%rbp)
jmp    1292 <create_path+0x152>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
jmp    1297 <create_path+0x157>
mov    -0x11c(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_path>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rbx
mov    0x2e93(%rip),%rax
mov    0x2e64(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e73(%rip),%rcx
mov    0x2e4c(%rip),%rdx
mov    0x2e6d(%rip),%rdi
or     (%rax),%esi
or     (%rcx),%esi
or     (%rdx),%esi
or     (%rdi),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11f3 <create_path+0xb3>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
cmp    $0x81,%eax
je     11f3 <create_path+0xb3>
cmp    $0x80,%eax
jne    11f1 <create_path+0xb1>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
add    %r14,%rax
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x2f,-0x1(%rax)
lea    -0x1(%rax),%rax
jne    11d0 <create_path+0x90>
movb   $0x0,(%rax)
mov    %rsp,%rdi
call   1060 <create_path@plt>
test   %eax,%eax
jne    11f3 <create_path+0xb3>
mov    %rbx,%rdi
call   1060 <create_path@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@errno = global i32 0
define i32 @create_path(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = load i32, i32* @S_IRWXU
%8 = load i32, i32* @S_IRGRP
%9 = load i32, i32* @S_IXGRP
%10 = or i32 %8, %9
%11 = or i32 %7, %10
%12 = load i32, i32* @S_IROTH
%13 = load i32, i32* @S_IXOTH
%14 = or i32 %12, %13
%15 = or i32 %11, %14
%16 = call i64 @mkdir(i8* %6, i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %50
18: ; preds = %1
%19 = load i32, i32* @errno
switch i32 %19, label %47 [
i32 128, label %20
i32 129, label %46
]
20: ; preds = %18
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%22 = load i8*, i8** %2
%23 = call i32 @strncpy(i8* %21, i8* %22, i32 256)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8* %28, i8** %4
br label %29
29: ; preds = %34, %20
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 47
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %4
br label %29
37: ; preds = %29
%38 = load i8*, i8** %4
store i8 0, i8* %38
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%40 = call i32 @create_path(i8* %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = load i8*, i8** %2
%44 = call i32 @create_path(i8* %43)
store i32 %44, i32* %5
br label %45
45: ; preds = %42, %37
br label %49
46: ; preds = %18
store i32 0, i32* %5
br label %49
47: ; preds = %18
%48 = load i32, i32* @errno
store i32 %48, i32* %5
br label %49
49: ; preds = %47, %46, %45
br label %50
50: ; preds = %49, %1
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@errno = global i32 0
define i32 @create_path(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @S_IRWXU
%5 = load i32, i32* @S_IRGRP
%6 = load i32, i32* @S_IXGRP
%7 = load i32, i32* @S_IROTH
%8 = load i32, i32* @S_IXOTH
%9 = or i32 %5, %4
%10 = or i32 %9, %6
%11 = or i32 %10, %7
%12 = or i32 %11, %8
%13 = tail call i64 @mkdir(i8* %0, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %33, label %15
15: ; preds = %1
%16 = load i32, i32* @errno
switch i32 %16, label %32 [
i32 128, label %17
i32 129, label %33
]
17: ; preds = %15
%18 = call i32 @strncpy(i8* %3, i8* %0, i32 256)
%19 = call i32 @strlen(i8* %3)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 %20
br label %22
22: ; preds = %22, %17
%23 = phi i8* [ %21, %17 ], [ %26, %22 ]
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 47
%26 = getelementptr inbounds i8, i8* %23, i64 -1
br i1 %25, label %27, label %22
27: ; preds = %22
store i8 0, i8* %23
%28 = call i32 @create_path(i8* %3)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = call i32 @create_path(i8* %0)
br label %33
32: ; preds = %15
br label %33
33: ; preds = %15, %32, %30, %27, %1
%34 = phi i32 [ %16, %32 ], [ 0, %27 ], [ %31, %30 ], [ 0, %1 ], [ 0, %15 ]
ret i32 %34
}