#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 */
typedef int /*<<< orphan*/ opath;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int /*<<< orphan*/ S_IRWXU;
scalar_t__ access(char *, int /*<<< orphan*/);
unsigned int mkdir(char *, int /*<<< orphan*/);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
unsigned int __mkdir(const char *path) {
  char opath[256];
  char *p;
  size_t len;
  strncpy(opath, path, sizeof(opath));
  len = strlen(opath);
  if (opath[len - 1] == '/')
    opath[len - 1] = '\0';
  for (p = opath; *p; p++)
    if (*p == '/') {
      *p = '\0';
      if (access(opath, F_OK))
        mkdir(opath, S_IRWXU);
      *p = '/';
    }
  if (access(opath, F_OK))
    return mkdir(opath, S_IRWXU);
  else
    return -1;
}


x86 assembly (clang, -O0):
<__mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movsbl -0x110(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    11a6 <__mkdir+0x66>
mov    -0x120(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
cmpb   $0x0,(%rax)
je     123b <__mkdir+0xfb>
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    121f <__mkdir+0xdf>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x110(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     1215 <__mkdir+0xd5>
lea    -0x110(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1040 <mkdir@plt>
mov    -0x118(%rbp),%rax
movb   $0x2f,(%rax)
jmp    1224 <__mkdir+0xe4>
mov    -0x118(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x118(%rbp)
jmp    11b4 <__mkdir+0x74>
lea    -0x110(%rbp),%rdi
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     1277 <__mkdir+0x137>
lea    -0x110(%rbp),%rdi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x4(%rbp)
jmp    127e <__mkdir+0x13e>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mkdir>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x100,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
cmpb   $0x2f,-0x1(%rax,%r12,1)
jne    1176 <__mkdir+0x36>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    0x2e53(%rip),%r15
mov    0x2e64(%rip),%r14
mov    %r12,%rbx
jmp    1198 <__mkdir+0x58>
nopl   0x0(%rax)
test   %al,%al
je     11c2 <__mkdir+0x82>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    1190 <__mkdir+0x50>
movb   $0x0,(%rbx)
mov    (%r15),%esi
mov    %r12,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11bd <__mkdir+0x7d>
mov    (%r14),%esi
mov    %r12,%rdi
call   1040 <mkdir@plt>
movb   $0x2f,(%rbx)
jmp    1194 <__mkdir+0x54>
mov    (%r15),%esi
mov    %rsp,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11df <__mkdir+0x9f>
mov    (%r14),%esi
mov    %rsp,%rdi
call   1040 <mkdir@plt>
jmp    11e4 <__mkdir+0xa4>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@F_OK = global i32 0
@S_IRWXU = global i32 0
define i32 @__mkdir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strncpy(i8* %7, i8* %8, i32 256)
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = sub i64 %12, 1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %22
18: ; preds = %1
%19 = load i64, i64* %6
%20 = sub i64 %19, 1
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %18, %1
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8* %23, i8** %5
br label %24
24: ; preds = %46, %22
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %49
28: ; preds = %24
%29 = load i8*, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %45
33: ; preds = %28
%34 = load i8*, i8** %5
store i8 0, i8* %34
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%36 = load i32, i32* @F_OK
%37 = call i64 @access(i8* %35, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%41 = load i32, i32* @S_IRWXU
%42 = call i32 @mkdir(i8* %40, i32 %41)
br label %43
43: ; preds = %39, %33
%44 = load i8*, i8** %5
store i8 47, i8* %44
br label %45
45: ; preds = %43, %28
br label %46
46: ; preds = %45
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %5
br label %24
49: ; preds = %24
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%51 = load i32, i32* @F_OK
%52 = call i64 @access(i8* %50, i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %49
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%56 = load i32, i32* @S_IRWXU
%57 = call i32 @mkdir(i8* %55, i32 %56)
store i32 %57, i32* %2
br label %59
58: ; preds = %49
store i32 -1, i32* %2
br label %59
59: ; preds = %58, %54
%60 = load i32, i32* %2
ret i32 %60
}

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