#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__ folder_exists(char const *);
int /*<<< orphan*/ free(char *);
scalar_t__ mkdir(char const *, int);
scalar_t__ split_path(char const *, char *, char *);
char *strdup(char const *);
int folder_create(const char *fname) {
  char *parent_folder;
  char *sub_folder;
  int ok = !0;
  if (folder_exists(fname))
    return !0;
  parent_folder = strdup(fname);
  sub_folder = strdup(fname);
  if (split_path(fname, parent_folder, sub_folder)) {
    if (!folder_exists(parent_folder)) {
      ok = folder_create(parent_folder);
    }
  }
  if (ok) {
    ok = mkdir(fname, 0775) == 0;
  }
  free(parent_folder);
  free(sub_folder);
  return ok;
}


x86 assembly (clang, -O0):
<folder_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <folder_exists@plt>
cmp    $0x0,%rax
je     1192 <folder_create+0x32>
movl   $0x1,-0x4(%rbp)
jmp    122a <folder_create+0xca>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <split_path@plt>
cmp    $0x0,%rax
je     11eb <folder_create+0x8b>
mov    -0x18(%rbp),%rdi
call   1070 <folder_exists@plt>
cmp    $0x0,%rax
jne    11e6 <folder_create+0x86>
mov    -0x18(%rbp),%rdi
call   1050 <folder_create@plt>
mov    %eax,-0x24(%rbp)
jmp    11eb <folder_create+0x8b>
cmpl   $0x0,-0x24(%rbp)
je     1212 <folder_create+0xb2>
mov    -0x10(%rbp),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<folder_create>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1070 <folder_exists@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11e1 <folder_create+0x81>
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rax,%rdx
call   1060 <split_path@plt>
test   %rax,%rax
je     11bb <folder_create+0x5b>
mov    %r15,%rdi
call   1070 <folder_exists@plt>
test   %rax,%rax
jne    11bb <folder_create+0x5b>
mov    %r15,%rdi
call   1050 <folder_create@plt>
test   %eax,%eax
je     11ee <folder_create+0x8e>
mov    %rbx,%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11d1 <folder_create+0x71>

LLVM IR (-O0):
define i32 @folder_create(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %6
%7 = load i8*, i8** %3
%8 = call i64 @folder_exists(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %43
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %4
%14 = load i8*, i8** %3
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = load i8*, i8** %5
%19 = call i64 @split_path(i8* %16, i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %11
%22 = load i8*, i8** %4
%23 = call i64 @folder_exists(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i8*, i8** %4
%27 = call i32 @folder_create(i8* %26)
store i32 %27, i32* %6
br label %28
28: ; preds = %25, %21
br label %29
29: ; preds = %28, %11
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8*, i8** %3
%34 = call i64 @mkdir(i8* %33, i32 509)
%35 = icmp eq i64 %34, 0
%36 = zext i1 %35 to i32
store i32 %36, i32* %6
br label %37
37: ; preds = %32, %29
%38 = load i8*, i8** %4
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %5
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %6
store i32 %42, i32* %2
br label %43
43: ; preds = %37, %10
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
define i32 @folder_create(i8* %0) {
%2 = tail call i64 @folder_exists(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %23
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %0)
%6 = tail call i8* @strdup(i8* %0)
%7 = tail call i64 @split_path(i8* %0, i8* %5, i8* %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i64 @folder_exists(i8* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @folder_create(i8* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %4, %9, %12
%16 = tail call i64 @mkdir(i8* %0, i32 509)
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %15, %12
%20 = phi i32 [ %18, %15 ], [ 0, %12 ]
%21 = tail call i32 @free(i8* %5)
%22 = tail call i32 @free(i8* %6)
br label %23
23: ; preds = %1, %19
%24 = phi i32 [ %20, %19 ], [ 1, %1 ]
ret i32 %24
}