#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 */
int mkdir(char const *, int /*<<< orphan*/);
scalar_t__ path_isdir(char const *);
int /*<<< orphan*/ perror(char *);
bool path_mkdir(const char *path, mode_t mode) {
  int ret;
  if (path_isdir(path)) {
    return (true);
  } else {
    ret = mkdir(path, mode);
    if (ret < 0) {
      perror("mkdir");
      return (false);
    }
  }
  return (true);
}


x86 assembly (clang, -O0):
<path_mkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <path_isdir@plt>
cmp    $0x0,%rax
je     115e <path_mkdir+0x2e>
movl   $0x1,-0x4(%rbp)
jmp    119b <path_mkdir+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <mkdir@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    118f <path_mkdir+0x5f>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    119b <path_mkdir+0x6b>
jmp    1194 <path_mkdir+0x64>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_mkdir>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <path_isdir@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1158 <path_mkdir+0x28>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <mkdir@plt>
test   %eax,%eax
js     115f <path_mkdir+0x2f>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe9a(%rip),%rdi
call   1050 <perror@plt>
xor    %ebx,%ebx
jmp    1158 <path_mkdir+0x28>

LLVM IR (-O0):
@.str = [6 x i8] c"mkdir\00"
define i32 @path_mkdir(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i64 @path_isdir(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %21
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = call i32 @mkdir(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %21
19: ; preds = %11
br label %20
20: ; preds = %19
store i32 1, i32* %3
br label %21
21: ; preds = %20, %17, %10
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [6 x i8] c"mkdir\00"
define i32 @path_mkdir(i8* %0, i32 %1) {
%3 = tail call i64 @path_isdir(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = tail call i32 @mkdir(i8* %0, i32 %1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32 [ 0, %8 ], [ 1, %2 ], [ 1, %5 ]
ret i32 %11
}