#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 */
char *alloca(scalar_t__);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int mkdir(char *, int);
char *strchr(char const *, char);
scalar_t__ strlen(char const *);
int create_path(const char *path) {
  char *buf = alloca(strlen(path) + 1);
  const char *slash = path;
  size_t len;
  int err;
  while ((slash = strchr(slash + 1, '/'))) {
    len = slash - path + 1;
    memcpy(buf, path, len);
    buf[len] = 0;
    err = mkdir(buf, 0777);
    if (err)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<create_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f9 <create_path+0xa9>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11f4 <create_path+0xa4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1200 <create_path+0xb0>
jmp    117d <create_path+0x2d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <alloca@plt>
mov    %rax,%r15
mov    %r14,%rbx
nop
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11bd <create_path+0x6d>
mov    %rax,%rbx
mov    %rax,%r12
sub    %r14,%r12
lea    0x1(%r12),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <memcpy@plt>
movb   $0x0,0x1(%r15,%r12,1)
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     1170 <create_path+0x20>
mov    $0xffffffff,%eax
jmp    11bf <create_path+0x6f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @create_path(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = call i8* @alloca(i64 %10)
store i8* %11, i8** %4
%12 = load i8*, i8** %3
store i8* %12, i8** %5
br label %13
13: ; preds = %37, %1
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i8* @strchr(i8* %15, i8 signext 47)
store i8* %16, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i8*, i8** %3
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = add nsw i64 %23, 1
store i64 %24, i64* %6
%25 = load i8*, i8** %4
%26 = load i8*, i8** %3
%27 = load i64, i64* %6
%28 = call i32 @memcpy(i8* %25, i8* %26, i64 %27)
%29 = load i8*, i8** %4
%30 = load i64, i64* %6
%31 = getelementptr inbounds i8, i8* %29, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %4
%33 = call i32 @mkdir(i8* %32, i32 511)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %18
store i32 -1, i32* %2
br label %39
37: ; preds = %18
br label %13
38: ; preds = %13
store i32 0, i32* %2
br label %39
39: ; preds = %38, %36
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
define i32 @create_path(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @alloca(i64 %3)
%5 = ptrtoint i8* %0 to i64
br label %6
6: ; preds = %11, %1
%7 = phi i8* [ %0, %1 ], [ %9, %11 ]
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = tail call i8* @strchr(i8* %8, i8 signext 47)
%10 = icmp eq i8* %9, null
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = ptrtoint i8* %9 to i64
%13 = sub i64 %12, %5
%14 = add nsw i64 %13, 1
%15 = tail call i32 @memcpy(i8* %4, i8* %0, i64 %14)
%16 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 0, i8* %16
%17 = tail call i32 @mkdir(i8* %4, i32 511)
%18 = icmp eq i32 %17, 0
br i1 %18, label %6, label %19
19: ; preds = %6, %11
%20 = phi i32 [ -1, %11 ], [ 0, %6 ]
ret i32 %20
}