#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__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ mkdir(char const *, int /*<<< orphan*/);
char *qfile_get_dir(char const *);
bool qfile_mkdir(const char *dirpath, mode_t mode, bool recursive) {
  ;
  if (mkdir(dirpath, mode) == 0)
    return true;
  if (recursive == true && errno == ENOENT) {
    char *parentpath = qfile_get_dir(dirpath);
    if (qfile_mkdir(parentpath, mode, recursive) == true &&
        qfile_mkdir(dirpath, mode, recursive) == true) {
      free(parentpath);
      return true;
    }
    free(parentpath);
  }
  return false;
}


x86 assembly (clang, -O0):
<qfile_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jne    1174 <qfile_mkdir+0x34>
movl   $0x1,-0x4(%rbp)
jmp    11fa <qfile_mkdir+0xba>
cmpl   $0x1,-0x18(%rbp)
jne    11f3 <qfile_mkdir+0xb3>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%rax
jne    11f3 <qfile_mkdir+0xb3>
mov    -0x10(%rbp),%rdi
call   1050 <qfile_get_dir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <qfile_mkdir@plt>
cmp    $0x1,%eax
jne    11ea <qfile_mkdir+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <qfile_mkdir@plt>
cmp    $0x1,%eax
jne    11ea <qfile_mkdir+0xaa>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    11fa <qfile_mkdir+0xba>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qfile_mkdir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r12
call   1040 <mkdir@plt>
test   %rax,%rax
je     11bc <qfile_mkdir+0x7c>
xor    %ebp,%ebp
cmp    $0x1,%ebx
jne    11c1 <qfile_mkdir+0x81>
mov    0x2e78(%rip),%rax
mov    (%rax),%rax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%rax
jne    11c1 <qfile_mkdir+0x81>
mov    %r12,%rdi
call   1050 <qfile_get_dir@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
call   1060 <qfile_mkdir@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
jne    11b2 <qfile_mkdir+0x72>
mov    %r12,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
call   1060 <qfile_mkdir@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
sete   %bpl
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11c1 <qfile_mkdir+0x81>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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