#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*/ path_buffer;

/* Variables and functions */
scalar_t__ EEXIST;
int PATH_MAX;
int /*<<< orphan*/ _conf_existdir(char *);
int /*<<< orphan*/ err_log(int, int, char *, ...);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ os_chown(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ strerror(scalar_t__);
int strlen(char *);
char *strsep(char **, char *);
int _conf_makedir(char *path, char *user) {
  char *token, *next_token;
  char *pathdup;
  char path_buffer[PATH_MAX];
  int retval = 0;
  err_log(9, 0x00000001, "Creating %s\n", path);
  pathdup = strdup(path);
  if (!pathdup) {
    err_log(0, 0x00000001, "Malloc error\n");
  }
  next_token = pathdup;
  while (*next_token && (*next_token != '/'))
    next_token++;
  if (*next_token)
    next_token++;
  memset(path_buffer, 0, sizeof(path_buffer));
  while ((token = strsep(&next_token, "/"))) {
    if ((strlen(path_buffer) + strlen(token)) < PATH_MAX) {
      strcat(path_buffer, "/");
      strcat(path_buffer, token);
      if (!_conf_existdir(path_buffer)) {
        err_log(9, 0x00000001, "Making %s\n", path_buffer);
        if ((mkdir(path_buffer, 0700)) && (errno != EEXIST)) {
          free(pathdup);
          err_log(1, 0x00000001, "Could not make dirctory %s: %s\n",
                  path_buffer, strerror(errno));
          return 0;
        }
        os_chown(path_buffer, user);
      }
      retval = 1;
    }
  }
  free(pathdup);
  return retval;
}


x86 assembly (clang, -O0):
<_conf_makedir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x10(%rbp),%rcx
mov    $0x9,%edi
mov    $0x1,%esi
lea    0xdf4(%rip),%rdx
mov    $0x0,%al
call   1050 <err_log@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1240 <_conf_makedir+0x90>
xor    %edi,%edi
mov    $0x1,%esi
lea    0xdd4(%rip),%rdx
mov    $0x0,%al
call   1050 <err_log@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x59(%rbp)
je     126d <_conf_makedir+0xbd>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    127d <_conf_makedir+0xcd>
jmp    128e <_conf_makedir+0xde>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1248 <_conf_makedir+0x98>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a7 <_conf_makedir+0xf7>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1070 <memset@plt>
lea    -0x28(%rbp),%rdi
lea    0xd58(%rip),%rsi
call   1080 <strsep@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     13de <_conf_makedir+0x22e>
mov    -0x50(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x60(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
add    %ecx,%eax
mov    0x2cf7(%rip),%rcx
cmp    (%rcx),%eax
jge    13d9 <_conf_makedir+0x229>
mov    -0x50(%rbp),%rdi
lea    0xd0f(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x50(%rbp),%rdi
call   10a0 <_conf_existdir@plt>
cmp    $0x0,%eax
jne    13d2 <_conf_makedir+0x222>
mov    -0x50(%rbp),%rcx
mov    $0x9,%edi
mov    $0x1,%esi
lea    0xcd8(%rip),%rdx
mov    $0x0,%al
call   1050 <err_log@plt>
mov    -0x50(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     13c5 <_conf_makedir+0x215>
mov    0x2c65(%rip),%rax
mov    (%rax),%rax
mov    0x2c63(%rip),%rcx
cmp    (%rcx),%rax
je     13c5 <_conf_makedir+0x215>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0x50(%rbp),%rcx
mov    %eax,%r8d
mov    $0x1,%esi
lea    0xc7f(%rip),%rdx
mov    %esi,%edi
mov    $0x0,%al
call   1050 <err_log@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13f4 <_conf_makedir+0x244>
mov    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <os_chown@plt>
movl   $0x1,-0x44(%rbp)
jmp    12b8 <_conf_makedir+0x108>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_conf_makedir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,-0x48(%rbp)
mov    %rdi,%r15
mov    %rsp,%r12
mov    0x2e1e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe13(%rip),%rdx
mov    $0x9,%edi
mov    $0x1,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <err_log@plt>
mov    %r15,%rdi
call   10c0 <strdup@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1226 <_conf_makedir+0x76>
lea    0xdf5(%rip),%rdx
xor    %edi,%edi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <err_log@plt>
mov    %r15,%rax
mov    %r12,-0x40(%rbp)
mov    %r15,-0x30(%rbp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
test   %cl,%cl
je     1250 <_conf_makedir+0xa0>
add    $0x1,%rax
cmp    $0x2f,%cl
jne    1240 <_conf_makedir+0x90>
mov    %rax,-0x38(%rbp)
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1070 <memset@plt>
lea    0xdb0(%rip),%rsi
lea    -0x38(%rbp),%rdi
call   1080 <strsep@plt>
test   %rax,%rax
je     1380 <_conf_makedir+0x1d0>
mov    %rax,%r15
lea    0xd94(%rip),%r13
xor    %r12d,%r12d
jmp    12b8 <_conf_makedir+0x108>
mov    %rbx,%rdi
mov    -0x48(%rbp),%rsi
call   10b0 <os_chown@plt>
nopl   0x0(%rax,%rax,1)
lea    -0x38(%rbp),%rdi
mov    %r13,%rsi
call   1080 <strsep@plt>
mov    %rax,%r15
test   %rax,%rax
je     1380 <_conf_makedir+0x1d0>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1060 <strlen@plt>
add    %r14d,%eax
mov    0x2d1b(%rip),%rcx
cmp    (%rcx),%eax
jge    12a0 <_conf_makedir+0xf0>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   10a0 <_conf_existdir@plt>
mov    $0x1,%r12d
test   %eax,%eax
jne    12a0 <_conf_makedir+0xf0>
mov    $0x9,%edi
mov    $0x1,%esi
lea    0xd0b(%rip),%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <err_log@plt>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     128c <_conf_makedir+0xdc>
mov    0x2c97(%rip),%rax
mov    (%rax),%r15
mov    0x2c95(%rip),%rax
cmp    (%rax),%r15
je     128c <_conf_makedir+0xdc>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   10d0 <strerror@plt>
lea    0xcc4(%rip),%rdx
xor    %r12d,%r12d
mov    $0x1,%edi
mov    $0x1,%esi
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <err_log@plt>
jmp    1389 <_conf_makedir+0x1d9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rsp
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [13 x i8] c"Creating %s\0A\00"
@.str.1 = [14 x i8] c"Malloc error\0A\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [11 x i8] c"Making %s\0A\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.4 = [32 x i8] c"Could not make dirctory %s: %s\0A\00"
define i32 @_conf_makedir(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %9
%16 = alloca i8, i64 %14
store i64 %14, i64* %10
store i32 0, i32* %11
%17 = load i8*, i8** %4
%18 = call i32 (i32, i32, i8*, ...) @err_log(i32 9, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %4
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %8
%21 = load i8*, i8** %8
%22 = icmp ne i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %2
%24 = call i32 (i32, i32, i8*, ...) @err_log(i32 0, i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %2
%26 = load i8*, i8** %8
store i8* %26, i8** %7
br label %27
27: ; preds = %39, %25
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 47
br label %37
37: ; preds = %32, %27
%38 = phi i1 [ false, %27 ], [ %36, %32 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %7
br label %27
42: ; preds = %37
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
br label %49
49: ; preds = %46, %42
%50 = trunc i64 %14 to i32
%51 = call i32 @memset(i8* %16, i32 0, i32 %50)
br label %52
52: ; preds = %86, %49
%53 = call i8* @strsep(i8** %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %53, i8** %6
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %87
55: ; preds = %52
%56 = call i32 @strlen(i8* %16)
%57 = load i8*, i8** %6
%58 = call i32 @strlen(i8* %57)
%59 = add nsw i32 %56, %58
%60 = load i32, i32* @PATH_MAX
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %86
62: ; preds = %55
%63 = call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%64 = load i8*, i8** %6
%65 = call i32 @strcat(i8* %16, i8* %64)
%66 = call i32 @_conf_existdir(i8* %16)
%67 = icmp ne i32 %66, 0
br i1 %67, label %85, label %68
68: ; preds = %62
%69 = call i32 (i32, i32, i8*, ...) @err_log(i32 9, i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%70 = call i64 @mkdir(i8* %16, i32 448)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %82
72: ; preds = %68
%73 = load i64, i64* @errno
%74 = load i64, i64* @EEXIST
%75 = icmp ne i64 %73, %74
br i1 %75, label %76, label %82
76: ; preds = %72
%77 = load i8*, i8** %8
%78 = call i32 @free(i8* %77)
%79 = load i64, i64* @errno
%80 = call i32 @strerror(i64 %79)
%81 = call i32 (i32, i32, i8*, ...) @err_log(i32 1, i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %16, i32 %80)
store i32 0, i32* %3
store i32 1, i32* %12
br label %91
82: ; preds = %72, %68
%83 = load i8*, i8** %5
%84 = call i32 @os_chown(i8* %16, i8* %83)
br label %85
85: ; preds = %82, %62
store i32 1, i32* %11
br label %86
86: ; preds = %85, %55
br label %52
87: ; preds = %52
%88 = load i8*, i8** %8
%89 = call i32 @free(i8* %88)
%90 = load i32, i32* %11
store i32 %90, i32* %3
store i32 1, i32* %12
br label %91
91: ; preds = %87, %76
%92 = load i8*, i8** %9
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [13 x i8] c"Creating %s\0A\00"
@.str.1 = [14 x i8] c"Malloc error\0A\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [11 x i8] c"Making %s\0A\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.4 = [32 x i8] c"Could not make dirctory %s: %s\0A\00"
define i32 @_conf_makedir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = tail call i32 (i32, i32, i8*, ...) @err_log(i32 9, i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = tail call i8* @strdup(i8* %0)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 (i32, i32, i8*, ...) @err_log(i32 0, i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
br label %15
15: ; preds = %14, %18
%16 = phi i8* [ %19, %18 ], [ %10, %14 ]
%17 = load i8, i8* %16
switch i8 %17, label %18 [
i8 0, label %22
i8 47, label %20
]
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %16, i64 1
br label %15
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %16, i64 1
br label %22
22: ; preds = %15, %20
%23 = phi i8* [ %21, %20 ], [ %16, %15 ]
store i8* %23, i8** %3
%24 = call i32 @memset(i8* %8, i32 0, i32 %5)
%25 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %58, label %27
27: ; preds = %22, %54
%28 = phi i8* [ %56, %54 ], [ %25, %22 ]
%29 = phi i32 [ %55, %54 ], [ 0, %22 ]
%30 = call i32 @strlen(i8* %8)
%31 = call i32 @strlen(i8* %28)
%32 = add nsw i32 %31, %30
%33 = load i32, i32* @PATH_MAX
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %54
35: ; preds = %27
%36 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @strcat(i8* %8, i8* %28)
%38 = call i32 @_conf_existdir(i8* %8)
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %54
40: ; preds = %35
%41 = call i32 (i32, i32, i8*, ...) @err_log(i32 9, i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%42 = call i64 @mkdir(i8* %8, i32 448)
%43 = icmp eq i64 %42, 0
br i1 %43, label %52, label %44
44: ; preds = %40
%45 = load i64, i64* @errno
%46 = load i64, i64* @EEXIST
%47 = icmp eq i64 %45, %46
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = call i32 @free(i8* %10)
%50 = call i32 @strerror(i64 %45)
%51 = call i32 (i32, i32, i8*, ...) @err_log(i32 1, i32 1, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %8, i32 %50)
br label %61
52: ; preds = %44, %40
%53 = call i32 @os_chown(i8* %8, i8* %1)
br label %54
54: ; preds = %35, %52, %27
%55 = phi i32 [ %29, %27 ], [ 1, %52 ], [ 1, %35 ]
%56 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %27
58: ; preds = %54, %22
%59 = phi i32 [ 0, %22 ], [ %55, %54 ]
%60 = call i32 @free(i8* %10)
br label %61
61: ; preds = %58, %48
%62 = phi i32 [ 0, %48 ], [ %59, %58 ]
ret i32 %62
}