#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);
int /*<<< orphan*/ free(char *);
char *strdup(char const *);
char *strrchr(char *, char);
int create_dir_parents(const char *path, int mode) {
  int result = 0;
  char *tmp = strdup(path);
  char *slash = strrchr(tmp, '/');
  if (slash && slash > tmp) {
    *slash = 0;
    result = create_dir(tmp, mode);
  } else {
    result = 1;
  }
  free(tmp);
  return result;
}


x86 assembly (clang, -O0):
<create_dir_parents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a9 <create_dir_parents+0x69>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11a9 <create_dir_parents+0x69>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <create_dir@plt>
mov    %eax,-0x10(%rbp)
jmp    11b0 <create_dir_parents+0x70>
movl   $0x1,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dir_parents>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
call   1060 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    $0x1,%ebp
cmp    %rbx,%rax
jbe    1176 <create_dir_parents+0x36>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <create_dir@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @create_dir_parents(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i8*, i8** %7
%16 = load i8*, i8** %6
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %7
store i8 0, i8* %19
%20 = load i8*, i8** %6
%21 = load i32, i32* %4
%22 = call i32 @create_dir(i8* %20, i32 %21)
store i32 %22, i32* %5
br label %24
23: ; preds = %14, %2
store i32 1, i32* %5
br label %24
24: ; preds = %23, %18
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @create_dir_parents(i8* nocapture %0, i32 %1) {
%3 = tail call i8* @strdup(i8* %0)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 47)
%5 = icmp ugt i8* %4, %3
br i1 %5, label %6, label %8
6: ; preds = %2
store i8 0, i8* %4
%7 = tail call i32 @create_dir(i8* %3, i32 %1)
br label %8
8: ; preds = %2, %6
%9 = phi i32 [ %7, %6 ], [ 1, %2 ]
%10 = tail call i32 @free(i8* %3)
ret i32 %9
}