#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 */
scalar_t__ EEXIST;
scalar_t__ errno;
scalar_t__ mkdir(char *, int);
int init_directory(char *path) {
  char *p = path;
  for (p = &path[1]; *p; p++) {
    if (*p == '/') {
      *p = 0;
      if (mkdir(path, 0700) && (errno != EEXIST))
        return -1;
      *p = '/';
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<init_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11af <init_directory+0x9f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1199 <init_directory+0x89>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1192 <init_directory+0x82>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    0x2e63(%rip),%rcx
cmp    (%rcx),%rax
je     1192 <init_directory+0x82>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <init_directory+0xa6>
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
jmp    119e <init_directory+0x8e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1130 <init_directory+0x20>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_directory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x1(%rdi),%rbx
mov    0x2eb2(%rip),%r15
mov    0x2eb3(%rip),%r12
jmp    1138 <init_directory+0x28>
nop
test   %al,%al
je     1162 <init_directory+0x52>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    1130 <init_directory+0x20>
movb   $0x0,(%rbx)
mov    %r14,%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     115d <init_directory+0x4d>
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1166 <init_directory+0x56>
movb   $0x2f,(%rbx)
jmp    1134 <init_directory+0x24>
xor    %eax,%eax
jmp    116b <init_directory+0x5b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @init_directory(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 1
store i8* %7, i8** %4
br label %8
8: ; preds = %30, %1
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = load i8*, i8** %4
store i8 0, i8* %18
%19 = load i8*, i8** %3
%20 = call i64 @mkdir(i8* %19, i32 448)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i64, i64* @errno
%24 = load i64, i64* @EEXIST
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %2
br label %34
27: ; preds = %22, %17
%28 = load i8*, i8** %4
store i8 47, i8* %28
br label %29
29: ; preds = %27, %12
br label %30
30: ; preds = %29
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
br label %8
33: ; preds = %8
store i32 0, i32* %2
br label %34
34: ; preds = %33, %26
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @init_directory(i8* nocapture %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i8* [ %0, %1 ], [ %4, %6 ]
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 0, label %15
i8 47, label %7
]
6: ; preds = %2, %14
br label %2
7: ; preds = %2
store i8 0, i8* %4
%8 = tail call i64 @mkdir(i8* %0, i32 448)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EEXIST
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10, %7
store i8 47, i8* %4
br label %6
15: ; preds = %2, %10
%16 = phi i32 [ -1, %10 ], [ 0, %2 ]
ret i32 %16
}