#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 */
scalar_t__ S_ISREG(int /*<<< orphan*/);
scalar_t__ real_mkdir(char *, int);
int /*<<< orphan*/ real_unlink(char *);
int real_xstat(int, char *, struct stat *);
char *strrchr(char *, char);
int create_path(char *path) {
  char *path_bn;
  struct stat spath;
  if (!path)
    return -1;
  path_bn = strrchr(path, '/');
  if (!path_bn)
    return -1;
  *path_bn = '\0';
  if (real_xstat(1, path, &spath) == -1) {
    int id;
    if (S_ISREG(spath.st_mode)) {
      real_unlink(path);
    }
    id = create_path(path);
    if (id == -1 || real_mkdir(path, 0755))
      return -1;
    *path_bn = '/';
    return id;
  } else {
    if (S_ISREG(spath.st_mode)) {
      real_unlink(path);
      real_mkdir(path, 0755);
    }
  }
  *path_bn = '/';
  return 0;
}


x86 assembly (clang, -O0):
<create_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1183 <create_path+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <create_path+0x111>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ac <create_path+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <create_path+0x111>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
lea    -0x20(%rbp),%rdx
call   1080 <real_xstat@plt>
cmp    $0xffffffff,%eax
jne    1235 <create_path+0xd5>
mov    -0x20(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     11e9 <create_path+0x89>
mov    -0x10(%rbp),%rdi
call   1060 <real_unlink@plt>
mov    -0x10(%rbp),%rdi
call   1070 <create_path@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1217 <create_path+0xb7>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <real_mkdir@plt>
cmp    $0x0,%rax
je     1223 <create_path+0xc3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <create_path+0x111>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <create_path+0x111>
mov    -0x20(%rbp),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     125e <create_path+0xfe>
mov    -0x10(%rbp),%rdi
call   1060 <real_unlink@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <real_mkdir@plt>
jmp    1263 <create_path+0x103>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r15d
test   %rdi,%rdi
je     11fc <create_path+0x9c>
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     11fc <create_path+0x9c>
mov    %rax,%r14
movb   $0x0,(%rax)
mov    %rsp,%rdx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1080 <real_xstat@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
call   1050 <S_ISREG@plt>
cmp    $0xffffffff,%ebp
je     11c9 <create_path+0x69>
test   %rax,%rax
je     11f5 <create_path+0x95>
mov    %rbx,%rdi
call   1060 <real_unlink@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <real_mkdir@plt>
jmp    11f5 <create_path+0x95>
test   %rax,%rax
je     11d6 <create_path+0x76>
mov    %rbx,%rdi
call   1060 <real_unlink@plt>
mov    %rbx,%rdi
call   1070 <create_path@plt>
cmp    $0xffffffff,%eax
je     11fc <create_path+0x9c>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1040 <real_mkdir@plt>
test   %rax,%rax
jne    11fc <create_path+0x9c>
movb   $0x2f,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @create_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %1
store i32 -1, i32* %2
br label %55
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @strrchr(i8* %11, i8 signext 47)
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10
store i32 -1, i32* %2
br label %55
16: ; preds = %10
%17 = load i8*, i8** %4
store i8 0, i8* %17
%18 = load i8*, i8** %3
%19 = call i32 @real_xstat(i32 1, i8* %18, %struct.stat* %5)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %42
21: ; preds = %16
%22 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @S_ISREG(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = call i32 @real_unlink(i8* %27)
br label %29
29: ; preds = %26, %21
%30 = load i8*, i8** %3
%31 = call i32 @create_path(i8* %30)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, -1
br i1 %33, label %38, label %34
34: ; preds = %29
%35 = load i8*, i8** %3
%36 = call i64 @real_mkdir(i8* %35, i32 493)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34, %29
store i32 -1, i32* %2
br label %55
39: ; preds = %34
%40 = load i8*, i8** %4
store i8 47, i8* %40
%41 = load i32, i32* %6
store i32 %41, i32* %2
br label %55
42: ; preds = %16
%43 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @S_ISREG(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i8*, i8** %3
%49 = call i32 @real_unlink(i8* %48)
%50 = load i8*, i8** %3
%51 = call i64 @real_mkdir(i8* %50, i32 493)
br label %52
52: ; preds = %47, %42
br label %53
53: ; preds = %52
%54 = load i8*, i8** %4
store i8 47, i8* %54
store i32 0, i32* %2
br label %55
55: ; preds = %53, %39, %38, %15, %9
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @create_path(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %29, label %8
8: ; preds = %5
store i8 0, i8* %6
%9 = call i32 @real_xstat(i32 1, i8* %0, %struct.stat* %2)
%10 = icmp eq i32 %9, -1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISREG(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %10, label %15, label %24
15: ; preds = %8
br i1 %14, label %18, label %16
16: ; preds = %15
%17 = call i32 @real_unlink(i8* %0)
br label %18
18: ; preds = %16, %15
%19 = call i32 @create_path(i8* %0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = call i64 @real_mkdir(i8* %0, i32 493)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %29
24: ; preds = %8
br i1 %14, label %28, label %25
25: ; preds = %24
%26 = call i32 @real_unlink(i8* %0)
%27 = call i64 @real_mkdir(i8* %0, i32 493)
br label %28
28: ; preds = %25, %24, %21
store i8 47, i8* %6
br label %29
29: ; preds = %28, %21, %18, %5, %1
%30 = phi i32 [ -1, %1 ], [ -1, %5 ], [ -1, %21 ], [ -1, %18 ], [ 0, %28 ]
ret i32 %30
}