#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct stat *, int /*<<< orphan*/, int);
scalar_t__ mkdir(char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcpy(char *, char *);
int logger_mkdir(char *path) {
  char fullpath[1024];
  int level = -1, ret = -1;
  char *p = NULL;
  struct stat st;
  if (path) {
    strcpy(fullpath, path);
    p = fullpath;
    while (*p != '\0') {
      if (*p == '/') {
        while (*p != '\0' && *p == '/' && *(p + 1) == '/')
          ++p;
        if (level > 0) {
          *p = '\0';
          memset(&st, 0, sizeof(struct stat));
          ret = stat(fullpath, &st);
          if (ret == 0 && !S_ISDIR(st.st_mode))
            return -1;
          if (ret != 0 && mkdir(fullpath, 0755) != 0)
            return -1;
          *p = '/';
        }
        level++;
      }
      ++p;
    }
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<logger_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
movl   $0xffffffff,-0x418(%rbp)
ff ff ff
movq   $0x0,-0x420(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1329 <logger_mkdir+0x1d9>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     131d <logger_mkdir+0x1cd>
mov    -0x420(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1306 <logger_mkdir+0x1b6>
jmp    11d2 <logger_mkdir+0x82>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x429(%rbp)
je     121f <logger_mkdir+0xcf>
mov    -0x420(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x429(%rbp)
jne    121f <logger_mkdir+0xcf>
mov    -0x420(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x429(%rbp)
mov    -0x429(%rbp),%al
test   $0x1,%al
jne    1232 <logger_mkdir+0xe2>
jmp    1249 <logger_mkdir+0xf9>
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
jmp    11d2 <logger_mkdir+0x82>
cmpl   $0x0,-0x414(%rbp)
jle    12f7 <logger_mkdir+0x1a7>
mov    -0x420(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x428(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    -0x410(%rbp),%rdi
lea    -0x428(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
jne    12b9 <logger_mkdir+0x169>
mov    -0x428(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    12b9 <logger_mkdir+0x169>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <logger_mkdir+0x1e0>
cmpl   $0x0,-0x418(%rbp)
je     12ed <logger_mkdir+0x19d>
lea    -0x410(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     12ed <logger_mkdir+0x19d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1330 <logger_mkdir+0x1e0>
mov    -0x420(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
mov    -0x420(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x420(%rbp)
jmp    11a7 <logger_mkdir+0x57>
movl   $0x0,-0x4(%rbp)
jmp    1330 <logger_mkdir+0x1e0>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logger_mkdir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
test   %rdi,%rdi
je     120a <logger_mkdir+0xba>
mov    %rdi,%rsi
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1030 <strcpy@plt>
mov    $0xffffffff,%ebx
lea    0x8(%rsp),%r12
xor    %r14d,%r14d
mov    %r15,%rbp
jmp    1198 <logger_mkdir+0x48>
nopw   0x0(%rax,%rax,1)
test   %al,%al
je     1210 <logger_mkdir+0xc0>
add    $0x1,%rbp
mov    0x0(%rbp),%al
cmp    $0x2f,%al
jne    1190 <logger_mkdir+0x40>
add    $0xffffffffffffffff,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x2f,0x2(%rbp)
lea    0x1(%rbp),%rbp
je     11b0 <logger_mkdir+0x60>
test   %ebx,%ebx
jle    1205 <logger_mkdir+0xb5>
movb   $0x0,0x0(%rbp)
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <stat@plt>
test   %eax,%eax
je     11f4 <logger_mkdir+0xa4>
mov    %r15,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     1201 <logger_mkdir+0xb1>
jmp    120a <logger_mkdir+0xba>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
je     120a <logger_mkdir+0xba>
movb   $0x2f,0x0(%rbp)
add    $0x1,%ebx
jmp    1194 <logger_mkdir+0x44>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @logger_mkdir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.stat
store i8* %0, i8** %3
store i32 -1, i32* %5
store i32 -1, i32* %6
store i8* null, i8** %7
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %81
11: ; preds = %1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @strcpy(i8* %12, i8* %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8* %15, i8** %7
br label %16
16: ; preds = %77, %11
%17 = load i8*, i8** %7
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %80
21: ; preds = %16
%22 = load i8*, i8** %7
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 47
br i1 %25, label %26, label %77
26: ; preds = %21
br label %27
27: ; preds = %45, %26
%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 %43
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 47
br i1 %36, label %37, label %43
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 47
br label %43
43: ; preds = %37, %32, %27
%44 = phi i1 [ false, %32 ], [ false, %27 ], [ %42, %37 ]
br i1 %44, label %45, label %48
45: ; preds = %43
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %7
br label %27
48: ; preds = %43
%49 = load i32, i32* %5
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %74
51: ; preds = %48
%52 = load i8*, i8** %7
store i8 0, i8* %52
%53 = call i32 @memset(%struct.stat* %8, i32 0, i32 4)
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%55 = call i32 @stat(i8* %54, %struct.stat* %8)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %51
%59 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @S_ISDIR(i32 %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %58
store i32 -1, i32* %2
br label %82
64: ; preds = %58, %51
%65 = load i32, i32* %6
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%69 = call i64 @mkdir(i8* %68, i32 493)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %67
store i32 -1, i32* %2
br label %82
72: ; preds = %67, %64
%73 = load i8*, i8** %7
store i8 47, i8* %73
br label %74
74: ; preds = %72, %48
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 1
store i32 %76, i32* %5
br label %77
77: ; preds = %74, %21
%78 = load i8*, i8** %7
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %7
br label %16
80: ; preds = %16
store i32 0, i32* %2
br label %82
81: ; preds = %1
store i32 -1, i32* %2
br label %82
82: ; preds = %81, %80, %71, %63
%83 = load i32, i32* %2
ret i32 %83
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @logger_mkdir(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = bitcast %struct.stat* %3 to i8*
%6 = icmp eq i8* %0, null
br i1 %6, label %39, label %7
7: ; preds = %1
%8 = call i32 @strcpy(i8* %4, i8* %0)
%9 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %10
10: ; preds = %35, %7
%11 = phi i32 [ -1, %7 ], [ %36, %35 ]
%12 = phi i8* [ %4, %7 ], [ %38, %35 ]
%13 = load i8, i8* %12
switch i8 %13, label %35 [
i8 0, label %39
i8 47, label %14
]
14: ; preds = %10, %14
%15 = phi i8* [ %16, %14 ], [ %12, %10 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 47
br i1 %18, label %14, label %19
19: ; preds = %14
%20 = icmp sgt i32 %11, 0
br i1 %20, label %21, label %33
21: ; preds = %19
store i8 0, i8* %15
%22 = call i32 @memset(%struct.stat* %3, i32 0, i32 4)
%23 = call i32 @stat(i8* %4, %struct.stat* %3)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = load i32, i32* %9
%27 = call i32 @S_ISDIR(i32 %26)
%28 = icmp eq i32 %27, 0
br i1 %28, label %39, label %32
29: ; preds = %21
%30 = call i64 @mkdir(i8* %4, i32 493)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %25, %29
store i8 47, i8* %15
br label %33
33: ; preds = %32, %19
%34 = add nsw i32 %11, 1
br label %35
35: ; preds = %10, %33
%36 = phi i32 [ %34, %33 ], [ %11, %10 ]
%37 = phi i8* [ %15, %33 ], [ %12, %10 ]
%38 = getelementptr inbounds i8, i8* %37, i64 1
br label %10
39: ; preds = %10, %29, %25, %1
%40 = phi i32 [ -1, %1 ], [ 0, %10 ], [ -1, %29 ], [ -1, %25 ]
ret i32 %40
}