#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 *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stat_file(char *);
char *strchr(char *, char);
int make_dir(char *path, int full) {
  char buf[4096];
  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, 0755)) {
        logger(-1, errno, "Can't create directory %s", buf);
        return 1;
      }
    }
  }
  if (!full)
    return 0;
  if (!stat_file(path)) {
    if (mkdir(path, 0755)) {
      logger(-1, errno, "Can't create directory %s", path);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <make_dir+0x29>
movl   $0x0,-0x4(%rbp)
jmp    12ce <make_dir+0x17e>
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     1258 <make_dir+0x108>
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    0xe3d(%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    1253 <make_dir+0x103>
lea    -0x1020(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     124e <make_dir+0xfe>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    -0x1020(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xdc3(%rip),%rdx
call   1070 <logger@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <make_dir+0x17e>
jmp    1253 <make_dir+0x103>
jmp    1188 <make_dir+0x38>
cmpl   $0x0,-0x14(%rbp)
jne    126e <make_dir+0x11e>
movl   $0x0,-0x4(%rbp)
jmp    12ce <make_dir+0x17e>
mov    -0x10(%rbp),%rdi
call   1060 <stat_file@plt>
cmp    $0x0,%eax
jne    12c7 <make_dir+0x177>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     12c2 <make_dir+0x172>
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
mov    $0xffffffff,%edi
lea    0xd4f(%rip),%rdx
call   1070 <logger@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <make_dir+0x17e>
jmp    12c7 <make_dir+0x177>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
xor    %r15d,%r15d
test   %rdi,%rdi
je     1237 <make_dir+0xe7>
mov    %esi,%r14d
mov    %rdi,%rbx
add    $0x1,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f1 <make_dir+0xa1>
mov    %rax,%rbp
lea    0xe87(%rip),%r13
mov    %rsp,%r12
jmp    11b9 <make_dir+0x69>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11f1 <make_dir+0xa1>
mov    %ebp,%esi
sub    %ebx,%esi
add    $0x1,%esi
mov    %r12,%rdi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1060 <stat_file@plt>
test   %eax,%eax
jne    11a0 <make_dir+0x50>
mov    %r12,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     11a0 <make_dir+0x50>
mov    %r12,%rbx
jmp    1214 <make_dir+0xc4>
test   %r14d,%r14d
je     1237 <make_dir+0xe7>
mov    %rbx,%rdi
call   1060 <stat_file@plt>
test   %eax,%eax
jne    1237 <make_dir+0xe7>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1237 <make_dir+0xe7>
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
lea    0xddc(%rip),%rdx
mov    $0xffffffff,%edi
mov    %rbx,%rcx
call   1070 <logger@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x1008,%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(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %65
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
store i8* %15, i8** %7
br label %16
16: ; preds = %46, %13
%17 = load i8*, i8** %7
%18 = call i8* @strchr(i8* %17, i8 signext 47)
store i8* %18, i8** %8
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = load i8*, i8** %4
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = add nsw i64 %25, 1
%27 = trunc i64 %26 to i32
store i32 %27, i32* %9
%28 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%29 = load i32, i32* %9
%30 = load i8*, i8** %4
%31 = call i32 @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8* %33, i8** %7
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%35 = call i32 @stat_file(i8* %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %20
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%39 = call i64 @mkdir(i8* %38, i32 493)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* @errno
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%44 = call i32 @logger(i32 -1, i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %43)
store i32 1, i32* %3
br label %65
45: ; preds = %37
br label %46
46: ; preds = %45, %20
br label %16
47: ; preds = %16
%48 = load i32, i32* %5
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %47
store i32 0, i32* %3
br label %65
51: ; preds = %47
%52 = load i8*, i8** %4
%53 = call i32 @stat_file(i8* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %64, label %55
55: ; preds = %51
%56 = load i8*, i8** %4
%57 = call i64 @mkdir(i8* %56, i32 493)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* @errno
%61 = load i8*, i8** %4
%62 = call i32 @logger(i32 -1, i32 %60, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %61)
store i32 1, i32* %3
br label %65
63: ; preds = %55
br label %64
64: ; preds = %63, %51
store i32 0, i32* %3
br label %65
65: ; preds = %64, %59, %50, %41, %12
%66 = load i32, i32* %3
ret i32 %66
}

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(i8* %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %40, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = call i8* @strchr(i8* %7, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %28, label %10
10: ; preds = %6
%11 = ptrtoint i8* %0 to i64
br label %12
12: ; preds = %10, %24
%13 = phi i8* [ %8, %10 ], [ %26, %24 ]
%14 = ptrtoint i8* %13 to i64
%15 = sub i64 %14, %11
%16 = trunc i64 %15 to i32
%17 = add i32 %16, 1
%18 = call i32 @snprintf(i8* %4, i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = call i32 @stat_file(i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = call i64 @mkdir(i8* %4, i32 493)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %21, %12
%25 = getelementptr inbounds i8, i8* %13, i64 1
%26 = call i8* @strchr(i8* %25, i8 signext 47)
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %12
28: ; preds = %24, %6
%29 = icmp eq i32 %1, 0
br i1 %29, label %40, label %30
30: ; preds = %28
%31 = call i32 @stat_file(i8* %0)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = call i64 @mkdir(i8* %0, i32 493)
%35 = icmp eq i64 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %21, %33
%37 = phi i8* [ %0, %33 ], [ %4, %21 ]
%38 = load i32, i32* @errno
%39 = call i32 @logger(i32 -1, i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %40
40: ; preds = %36, %30, %33, %28, %2
%41 = phi i32 [ 0, %2 ], [ 0, %28 ], [ 0, %33 ], [ 0, %30 ], [ 1, %36 ]
ret i32 %41
}