#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__);
scalar_t__ mkdirIfNone(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int mkdirChain(char *origChain) {
  char *chain;
  char *chptr;
  chain = alloca(strlen(origChain) + 1);
  strcpy(chain, origChain);
  chptr = chain;
  while ((chptr = strchr(chptr, '/'))) {
    *chptr = '\0';
    if (mkdirIfNone(chain)) {
      *chptr = '/';
      return 1;
    }
    *chptr = '/';
    chptr++;
  }
  if (mkdirIfNone(chain))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<mkdirChain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11eb <mkdirChain+0x9b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
call   1060 <mkdirIfNone@plt>
cmp    $0x0,%rax
je     11d3 <mkdirChain+0x83>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1211 <mkdirChain+0xc1>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118a <mkdirChain+0x3a>
mov    -0x18(%rbp),%rdi
call   1060 <mkdirIfNone@plt>
cmp    $0x0,%rax
je     120a <mkdirChain+0xba>
movl   $0x1,-0x4(%rbp)
jmp    1211 <mkdirChain+0xc1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdirChain>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1070 <alloca@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11bc <mkdirChain+0x6c>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
mov    %r14,%rdi
call   1060 <mkdirIfNone@plt>
movb   $0x2f,(%rbx)
test   %rax,%rax
jne    11d1 <mkdirChain+0x81>
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <mkdirChain+0x40>
mov    %r14,%rdi
call   1060 <mkdirIfNone@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    11d6 <mkdirChain+0x86>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @mkdirChain(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = call i8* @alloca(i64 %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = load i8*, i8** %3
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %4
store i8* %13, i8** %5
br label %14
14: ; preds = %25, %1
%15 = load i8*, i8** %5
%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 %29
18: ; preds = %14
%19 = load i8*, i8** %5
store i8 0, i8* %19
%20 = load i8*, i8** %4
%21 = call i64 @mkdirIfNone(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = load i8*, i8** %5
store i8 47, i8* %24
store i32 1, i32* %2
br label %35
25: ; preds = %18
%26 = load i8*, i8** %5
store i8 47, i8* %26
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %14
29: ; preds = %14
%30 = load i8*, i8** %4
%31 = call i64 @mkdirIfNone(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 1, i32* %2
br label %35
34: ; preds = %29
store i32 0, i32* %2
br label %35
35: ; preds = %34, %33, %23
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @mkdirChain(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 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %4, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %16, label %8
8: ; preds = %1, %12
%9 = phi i8* [ %14, %12 ], [ %6, %1 ]
store i8 0, i8* %9
%10 = tail call i64 @mkdirIfNone(i8* %4)
%11 = icmp eq i64 %10, 0
store i8 47, i8* %9
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = tail call i8* @strchr(i8* dereferenceable(1) %13, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %8
16: ; preds = %12, %1
%17 = tail call i64 @mkdirIfNone(i8* %4)
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %8, %16
%21 = phi i32 [ %19, %16 ], [ 1, %8 ]
ret i32 %21
}