#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 */
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
scalar_t__ mkdir(char *, int /*<<< orphan*/);
size_t strlen(char const *);
int FwdLockGlue_CreateDirectories(const char *path, mode_t mode) {
  int result = 1;
  size_t partialPathLength = strlen(path);
  char *partialPath = malloc(partialPathLength + 1);
  if (partialPath == NULL) {
    result = 0;
  } else {
    size_t i;
    for (i = 0; i < partialPathLength; ++i) {
      if (path[i] == '/' && i > 0) {
        partialPath[i] = '\0';
        if (mkdir(partialPath, mode) != 0 && errno != EEXIST) {
          result = 0;
          break;
        }
      }
      partialPath[i] = path[i];
    }
    free(partialPath);
  }
  return result;
}


x86 assembly (clang, -O0):
<FwdLockGlue_CreateDirectories>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <FwdLockGlue_CreateDirectories+0x4b>
movl   $0x0,-0x10(%rbp)
jmp    123e <FwdLockGlue_CreateDirectories+0xfe>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1235 <FwdLockGlue_CreateDirectories+0xf5>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    120e <FwdLockGlue_CreateDirectories+0xce>
cmpq   $0x0,-0x28(%rbp)
jbe    120e <FwdLockGlue_CreateDirectories+0xce>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1209 <FwdLockGlue_CreateDirectories+0xc9>
mov    0x2dee(%rip),%rax
mov    (%rax),%rax
mov    0x2dec(%rip),%rcx
cmp    (%rcx),%rax
je     1209 <FwdLockGlue_CreateDirectories+0xc9>
movl   $0x0,-0x10(%rbp)
jmp    1235 <FwdLockGlue_CreateDirectories+0xf5>
jmp    120e <FwdLockGlue_CreateDirectories+0xce>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1193 <FwdLockGlue_CreateDirectories+0x53>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FwdLockGlue_CreateDirectories>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r13
call   1050 <strlen@plt>
mov    %rax,%r12
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11c6 <FwdLockGlue_CreateDirectories+0x86>
mov    %rax,%rbx
mov    $0x1,%ebp
test   %r12,%r12
je     11cf <FwdLockGlue_CreateDirectories+0x8f>
xor    %ebp,%ebp
mov    0x2e63(%rip),%r14
jmp    1192 <FwdLockGlue_CreateDirectories+0x52>
nop
movzbl 0x0(%r13,%rbp,1),%eax
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     11ca <FwdLockGlue_CreateDirectories+0x8a>
cmpb   $0x2f,0x0(%r13,%rbp,1)
jne    1180 <FwdLockGlue_CreateDirectories+0x40>
test   %rbp,%rbp
je     1180 <FwdLockGlue_CreateDirectories+0x40>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     1180 <FwdLockGlue_CreateDirectories+0x40>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
cmp    (%r14),%rax
je     1180 <FwdLockGlue_CreateDirectories+0x40>
xor    %ebp,%ebp
jmp    11cf <FwdLockGlue_CreateDirectories+0x8f>
xor    %ebp,%ebp
jmp    11d7 <FwdLockGlue_CreateDirectories+0x97>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @FwdLockGlue_CreateDirectories(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 1, i32* %5
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = add i64 %11, 1
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %5
br label %60
17: ; preds = %2
store i64 0, i64* %8
br label %18
18: ; preds = %54, %17
%19 = load i64, i64* %8
%20 = load i64, i64* %6
%21 = icmp ult i64 %19, %20
br i1 %21, label %22, label %57
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i64, i64* %8
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 47
br i1 %28, label %29, label %46
29: ; preds = %22
%30 = load i64, i64* %8
%31 = icmp ugt i64 %30, 0
br i1 %31, label %32, label %46
32: ; preds = %29
%33 = load i8*, i8** %7
%34 = load i64, i64* %8
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %7
%37 = load i32, i32* %4
%38 = call i64 @mkdir(i8* %36, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %32
%41 = load i64, i64* @errno
%42 = load i64, i64* @EEXIST
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %40
store i32 0, i32* %5
br label %57
45: ; preds = %40, %32
br label %46
46: ; preds = %45, %29, %22
%47 = load i8*, i8** %3
%48 = load i64, i64* %8
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = load i8, i8* %49
%51 = load i8*, i8** %7
%52 = load i64, i64* %8
%53 = getelementptr inbounds i8, i8* %51, i64 %52
store i8 %50, i8* %53
br label %54
54: ; preds = %46
%55 = load i64, i64* %8
%56 = add i64 %55, 1
store i64 %56, i64* %8
br label %18
57: ; preds = %44, %18
%58 = load i8*, i8** %7
%59 = call i32 @free(i8* %58)
br label %60
60: ; preds = %57, %16
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
@errno = global i64 0
@EEXIST = global i64 0
define i32 @FwdLockGlue_CreateDirectories(i8* nocapture %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, 1
%5 = tail call i8* @malloc(i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %32, label %7
7: ; preds = %2
%8 = icmp eq i64 %3, 0
br i1 %8, label %29, label %9
9: ; preds = %7, %24
%10 = phi i64 [ %27, %24 ], [ 0, %7 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
%14 = icmp ne i64 %10, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %24
16: ; preds = %9
%17 = getelementptr inbounds i8, i8* %5, i64 %10
store i8 0, i8* %17
%18 = tail call i64 @mkdir(i8* %5, i32 %1)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = load i64, i64* @errno
%22 = load i64, i64* @EEXIST
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %29
24: ; preds = %16, %20, %9
%25 = load i8, i8* %11
%26 = getelementptr inbounds i8, i8* %5, i64 %10
store i8 %25, i8* %26
%27 = add nuw i64 %10, 1
%28 = icmp eq i64 %27, %3
br i1 %28, label %29, label %9
29: ; preds = %24, %20, %7
%30 = phi i32 [ 1, %7 ], [ 0, %20 ], [ 1, %24 ]
%31 = tail call i32 @free(i8* %5)
br label %32
32: ; preds = %2, %29
%33 = phi i32 [ %30, %29 ], [ 0, %2 ]
ret i32 %33
}