#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 create_dir(char *);
int /*<<< orphan*/ free(char *);
char *strchr(char *, char);
char *xstrdup(char const *);
int create_path(char const *path) {
  int ret = 0;
  char *str = xstrdup(path);
  char *pos = str[0] == '/' ? str + 1 : str;
  for (; (pos = strchr(pos, '/')) != NULL; ++pos) {
    *pos = '\0';
    ret = create_dir(str);
    *pos = '/';
    if (ret)
      break;
  }
  free(str);
  return ret;
}


x86 assembly (clang, -O0):
<create_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1181 <create_path+0x41>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1189 <create_path+0x49>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ec <create_path+0xac>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1060 <create_dir@plt>
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
cmpl   $0x0,-0xc(%rbp)
je     11d6 <create_path+0x96>
jmp    11ec <create_path+0xac>
jmp    11db <create_path+0x9b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1191 <create_path+0x51>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_path>:
push   %rbp
push   %r14
push   %rbx
call   1050 <xstrdup@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpb   $0x2f,(%rax)
sete   %dil
add    %rax,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11a2 <create_path+0x62>
mov    %rax,%rbp
nopl   (%rax)
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
call   1060 <create_dir@plt>
movb   $0x2f,0x0(%rbp)
test   %eax,%eax
jne    119f <create_path+0x5f>
add    $0x1,%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1170 <create_path+0x30>
jmp    11a2 <create_path+0x62>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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