#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 */
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int create_multi_dir(const char *path) {
  int i, len;
  len = strlen(path);
  char dir_path[len + 1];
  dir_path[len] = '\0';
  strncpy(dir_path, path, len);
  for (i = 0; i < len; i++) {
    if (dir_path[i] == '/' && i > 0) {
      dir_path[i] = '\0';
      if (access(dir_path, F_OK) < 0) {
        if (mkdir(dir_path, 0755) < 0) {
          printf("mkdir=%s:msg=%s\n", dir_path, strerror(errno));
          return -1;
        }
      }
      dir_path[i] = '/';
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_multi_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    127b <create_multi_dir+0x11b>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1268 <create_multi_dir+0x108>
cmpl   $0x0,-0x14(%rbp)
jle    1268 <create_multi_dir+0x108>
mov    -0x38(%rbp),%rdi
movslq -0x14(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jge    125c <create_multi_dir+0xfc>
mov    -0x38(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    1257 <create_multi_dir+0xf7>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1289 <create_multi_dir+0x129>
jmp    125c <create_multi_dir+0xfc>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
jmp    126d <create_multi_dir+0x10d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11bc <create_multi_dir+0x5c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_multi_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0x1(%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
movslq %r14d,%r12
movb   $0x0,(%r12,%r13,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
test   %r12d,%r12d
jle    122b <create_multi_dir+0xcb>
mov    %r14d,%r14d
xor    %ebx,%ebx
mov    0x2e17(%rip),%r15
jmp    11cf <create_multi_dir+0x6f>
nopl   0x0(%rax,%rax,1)
movb   $0x2f,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     122b <create_multi_dir+0xcb>
cmpb   $0x2f,0x0(%r13,%rbx,1)
jne    11c6 <create_multi_dir+0x66>
test   %rbx,%rbx
je     11c6 <create_multi_dir+0x66>
movb   $0x0,0x0(%r13,%rbx,1)
mov    (%r15),%esi
mov    %r13,%rdi
call   1070 <access@plt>
test   %rax,%rax
jns    11c0 <create_multi_dir+0x60>
mov    %r13,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
jns    11c0 <create_multi_dir+0x60>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xde7(%rip),%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1060 <printf@plt>
mov    $0xffffffff,%eax
jmp    122d <create_multi_dir+0xcd>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [17 x i8] c"mkdir=%s:msg=%s\0A\00"
@errno = global i32 0
define i32 @create_multi_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 1
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = call i32 @strncpy(i8* %15, i8* %19, i32 %20)
store i32 0, i32* %4
br label %22
22: ; preds = %56, %1
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %59
26: ; preds = %22
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %15, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 47
br i1 %32, label %33, label %55
33: ; preds = %26
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %55
36: ; preds = %33
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %15, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* @F_OK
%41 = call i64 @access(i8* %15, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %51
43: ; preds = %36
%44 = call i64 @mkdir(i8* %15, i32 493)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %43
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %48)
store i32 -1, i32* %2
store i32 1, i32* %8
br label %60
50: ; preds = %43
br label %51
51: ; preds = %50, %36
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %15, i64 %53
store i8 47, i8* %54
br label %55
55: ; preds = %51, %33, %26
br label %56
56: ; preds = %55
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %22
59: ; preds = %22
store i32 0, i32* %2
store i32 1, i32* %8
br label %60
60: ; preds = %59, %46
%61 = load i8*, i8** %6
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [17 x i8] c"mkdir=%s:msg=%s\0A\00"
@errno = global i32 0
define i32 @create_multi_dir(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = sext i32 %2 to i64
%7 = getelementptr inbounds i8, i8* %5, i64 %6
store i8 0, i8* %7
%8 = call i32 @strncpy(i8* %5, i8* %0, i32 %2)
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %34
10: ; preds = %1
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %10, %31
%13 = phi i64 [ 0, %10 ], [ %32, %31 ]
%14 = getelementptr inbounds i8, i8* %5, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
%17 = icmp ne i64 %13, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %31
19: ; preds = %12
store i8 0, i8* %14
%20 = load i32, i32* @F_OK
%21 = call i64 @access(i8* %5, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = call i64 @mkdir(i8* %5, i32 493)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %28)
br label %34
30: ; preds = %23, %19
store i8 47, i8* %14
br label %31
31: ; preds = %12, %30
%32 = add nuw nsw i64 %13, 1
%33 = icmp eq i64 %32, %11
br i1 %33, label %34, label %12
34: ; preds = %31, %1, %26
%35 = phi i32 [ -1, %26 ], [ 0, %1 ], [ 0, %31 ]
ret i32 %35
}