#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*/ errno;
int /*<<< orphan*/ logger(int, int /*<<< orphan*/, char *, char const *);
scalar_t__ mkdir(char const *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stat_file(char const *);
char *strchr(char const *, char);
int make_dir_mode(const char *path, int full, int mode) {
  char buf[4096];
  const char *ps, *p;
  int len;
  if (path == NULL)
    return 0;
  ps = path + 1;
  while ((p = strchr(ps, '/'))) {
    len = p - path + 1;
    snprintf(buf, len, "%s", path);
    ps = p + 1;
    if (!stat_file(buf)) {
      if (mkdir(buf, mode)) {
        logger(-1, errno, "Can't create directory %s", buf);
        return 1;
      }
    }
  }
  if (!full)
    return 0;
  if (!stat_file(path)) {
    if (mkdir(path, mode)) {
      logger(-1, errno, "Can't create directory %s", path);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_dir_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117c <make_dir_mode+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    12cd <make_dir_mode+0x17d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
je     1259 <make_dir_mode+0x109>
mov    -0x1030(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x1034(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1034(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xe3a(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x1030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
lea    -0x1020(%rbp),%rdi
call   1060 <stat_file@plt>
cmp    $0x0,%eax
jne    1254 <make_dir_mode+0x104>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     124f <make_dir_mode+0xff>
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
lea    -0x1020(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xdc2(%rip),%rdx
call   1070 <logger@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cd <make_dir_mode+0x17d>
jmp    1254 <make_dir_mode+0x104>
jmp    118b <make_dir_mode+0x3b>
cmpl   $0x0,-0x14(%rbp)
jne    126f <make_dir_mode+0x11f>
movl   $0x0,-0x4(%rbp)
jmp    12cd <make_dir_mode+0x17d>
mov    -0x10(%rbp),%rdi
call   1060 <stat_file@plt>
cmp    $0x0,%eax
jne    12c6 <make_dir_mode+0x176>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     12c1 <make_dir_mode+0x171>
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xd50(%rip),%rdx
call   1070 <logger@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cd <make_dir_mode+0x17d>
jmp    12c6 <make_dir_mode+0x176>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dir_mode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
xor    %r14d,%r14d
test   %rdi,%rdi
je     1235 <make_dir_mode+0xe5>
mov    %edx,%r12d
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11ef <make_dir_mode+0x9f>
mov    %rax,%rbp
lea    0xe83(%rip),%r15
lea    0x10(%rsp),%r13
jmp    11b9 <make_dir_mode+0x69>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11ef <make_dir_mode+0x9f>
mov    %ebp,%esi
sub    %ebx,%esi
add    $0x1,%esi
mov    %r13,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r13,%rdi
call   1060 <stat_file@plt>
test   %eax,%eax
jne    11a0 <make_dir_mode+0x50>
mov    %r13,%rdi
mov    %r12d,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     11a0 <make_dir_mode+0x50>
mov    %r13,%rbx
jmp    1212 <make_dir_mode+0xc2>
cmpl   $0x0,0xc(%rsp)
je     1235 <make_dir_mode+0xe5>
mov    %rbx,%rdi
call   1060 <stat_file@plt>
test   %eax,%eax
jne    1235 <make_dir_mode+0xe5>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1235 <make_dir_mode+0xe5>
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
lea    0xdde(%rip),%rdx
mov    $0xffffffff,%edi
mov    %rbx,%rcx
call   1070 <logger@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"Can't create directory %s\00"
define i32 @make_dir_mode(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %69
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %9
br label %18
18: ; preds = %49, %15
%19 = load i8*, i8** %9
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %10
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i8*, i8** %10
%24 = load i8*, i8** %5
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = add nsw i64 %27, 1
%29 = trunc i64 %28 to i32
store i32 %29, i32* %11
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%31 = load i32, i32* %11
%32 = load i8*, i8** %5
%33 = call i32 @snprintf(i8* %30, i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %10
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %35, i8** %9
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%37 = call i32 @stat_file(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %49, label %39
39: ; preds = %22
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %7
%42 = call i64 @mkdir(i8* %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load i32, i32* @errno
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%47 = call i32 @logger(i32 -1, i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %46)
store i32 1, i32* %4
br label %69
48: ; preds = %39
br label %49
49: ; preds = %48, %22
br label %18
50: ; preds = %18
%51 = load i32, i32* %6
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %50
store i32 0, i32* %4
br label %69
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = call i32 @stat_file(i8* %55)
%57 = icmp ne i32 %56, 0
br i1 %57, label %68, label %58
58: ; preds = %54
%59 = load i8*, i8** %5
%60 = load i32, i32* %7
%61 = call i64 @mkdir(i8* %59, i32 %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %58
%64 = load i32, i32* @errno
%65 = load i8*, i8** %5
%66 = call i32 @logger(i32 -1, i32 %64, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %65)
store i32 1, i32* %4
br label %69
67: ; preds = %58
br label %68
68: ; preds = %67, %54
store i32 0, i32* %4
br label %69
69: ; preds = %68, %63, %53, %44, %14
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
@.str.1 = [26 x i8] c"Can't create directory %s\00"
define i32 @make_dir_mode(i8* %0, i32 %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %41, label %7
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = call i8* @strchr(i8* %8, i8 signext 47)
%10 = icmp eq i8* %9, null
br i1 %10, label %29, label %11
11: ; preds = %7
%12 = ptrtoint i8* %0 to i64
br label %13
13: ; preds = %11, %25
%14 = phi i8* [ %9, %11 ], [ %27, %25 ]
%15 = ptrtoint i8* %14 to i64
%16 = sub i64 %15, %12
%17 = trunc i64 %16 to i32
%18 = add i32 %17, 1
%19 = call i32 @snprintf(i8* %5, i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%20 = call i32 @stat_file(i8* %5)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = call i64 @mkdir(i8* %5, i32 %2)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %22, %13
%26 = getelementptr inbounds i8, i8* %14, i64 1
%27 = call i8* @strchr(i8* %26, i8 signext 47)
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %13
29: ; preds = %25, %7
%30 = icmp eq i32 %1, 0
br i1 %30, label %41, label %31
31: ; preds = %29
%32 = call i32 @stat_file(i8* %0)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = call i64 @mkdir(i8* %0, i32 %2)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %22, %34
%38 = phi i8* [ %0, %34 ], [ %5, %22 ]
%39 = load i32, i32* @errno
%40 = call i32 @logger(i32 -1, i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %41
41: ; preds = %37, %31, %34, %29, %3
%42 = phi i32 [ 0, %3 ], [ 0, %29 ], [ 0, %34 ], [ 0, %31 ], [ 1, %37 ]
ret i32 %42
}