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


x86 assembly (clang, -O0):
<mkdir_f_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
or     %eax,%esi
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    0x2e5c(%rip),%rcx
or     (%rcx),%eax
or     %eax,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1292 <mkdir_f_+0x152>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
sub    $0x80,%eax
je     11cc <mkdir_f_+0x8c>
jmp    11b6 <mkdir_f_+0x76>
mov    -0x11c(%rbp),%eax
sub    $0x81,%eax
je     126f <mkdir_f_+0x12f>
jmp    127e <mkdir_f_+0x13e>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@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     1236 <mkdir_f_+0xf6>
mov    -0x118(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x118(%rbp)
jmp    120c <mkdir_f_+0xcc>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <mkdir_f_@plt>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    126a <mkdir_f_+0x12a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <mkdir_f_@plt>
jmp    126f <mkdir_f_+0x12f>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    128d <mkdir_f_+0x14d>
mov    0x2d43(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    129c <mkdir_f_+0x15c>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdir_f_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e8e(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e6e(%rip),%rcx
mov    0x2e47(%rip),%rdx
mov    0x2e68(%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     11fd <mkdir_f_+0xbd>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
cmp    $0x81,%eax
je     11fd <mkdir_f_+0xbd>
cmp    $0x80,%eax
jne    11fb <mkdir_f_+0xbb>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
add    %r15,%rax
add    $0x1,%rax
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x2f,-0x1(%rax)
lea    -0x1(%rax),%rax
jne    11d0 <mkdir_f_+0x90>
movb   $0x0,(%rax)
mov    %rsp,%rdi
mov    %r14,%rsi
call   1060 <mkdir_f_@plt>
cmpl   $0x0,(%r14)
jne    11fd <mkdir_f_+0xbd>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <mkdir_f_@plt>
jmp    11fd <mkdir_f_+0xbd>
mov    %eax,%ebp
mov    %ebp,(%r14)
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
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 void @mkdir_f_(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [256 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i8*, i8** %3
%8 = load i32, i32* @S_IRWXU
%9 = load i32, i32* @S_IRGRP
%10 = load i32, i32* @S_IXGRP
%11 = or i32 %9, %10
%12 = or i32 %8, %11
%13 = load i32, i32* @S_IROTH
%14 = load i32, i32* @S_IXOTH
%15 = or i32 %13, %14
%16 = or i32 %12, %15
%17 = call i64 @mkdir(i8* %7, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %55
19: ; preds = %2
%20 = load i32, i32* @errno
switch i32 %20, label %51 [
i32 128, label %21
i32 129, label %49
]
21: ; preds = %19
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8* %29, i8** %6
br label %30
30: ; preds = %35, %21
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 47
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %6
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %6
br label %30
38: ; preds = %30
%39 = load i8*, i8** %6
store i8 0, i8* %39
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%41 = load i32*, i32** %4
%42 = load i32*, i32** %4
%43 = load i32, i32* %42
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %38
%46 = load i8*, i8** %3
%47 = load i32*, i32** %4
br label %48
48: ; preds = %45, %38
br label %49
49: ; preds = %19, %48
%50 = load i32*, i32** %4
store i32 0, i32* %50
br label %54
51: ; preds = %19
%52 = load i32, i32* @errno
%53 = load i32*, i32** %4
store i32 %52, i32* %53
br label %54
54: ; preds = %51, %49
br label %57
55: ; preds = %2
%56 = load i32*, i32** %4
store i32 0, i32* %56
br label %57
57: ; preds = %55, %54
ret void
}

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