#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 EEXIST;
int /*<<< orphan*/ X_OK;
int /*<<< orphan*/ access(char *, int /*<<< orphan*/);
int errno;
int mkdir(char *, int);
int mkdirIfNone(char *directory) {
  int rc, mkerr;
  char *chptr;
  if (!access(directory, X_OK))
    return 0;
  for (chptr = directory; *chptr; chptr++)
    if (*chptr != '/')
      break;
  if (!*chptr)
    return 0;
  rc = mkdir(directory, 0755);
  mkerr = errno;
  if (!rc || mkerr == EEXIST)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<mkdirIfNone>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
cmp    $0x0,%eax
jne    1153 <mkdirIfNone+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <mkdirIfNone+0xd8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1193 <mkdirIfNone+0x73>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     117d <mkdirIfNone+0x5d>
jmp    1193 <mkdirIfNone+0x73>
jmp    1182 <mkdirIfNone+0x62>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115b <mkdirIfNone+0x3b>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11ac <mkdirIfNone+0x8c>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <mkdirIfNone+0xd8>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11e5 <mkdirIfNone+0xc5>
mov    -0x18(%rbp),%eax
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <mkdirIfNone+0xd1>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <mkdirIfNone+0xd8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkdirIfNone>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ebb(%rip),%rax
mov    (%rax),%esi
call   1040 <access@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     117b <mkdirIfNone+0x5b>
mov    %rbx,%rax
nopl   (%rax)
movzbl (%rax),%ecx
cmp    $0x2f,%cl
jne    114e <mkdirIfNone+0x2e>
add    $0x1,%rax
jmp    1140 <mkdirIfNone+0x20>
test   %cl,%cl
je     117b <mkdirIfNone+0x5b>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     117b <mkdirIfNone+0x5b>
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    0x2e65(%rip),%rcx
xor    %ebp,%ebp
cmp    (%rcx),%eax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@X_OK = global i32 0
@errno = global i32 0
@EEXIST = global i32 0
define i32 @mkdirIfNone(i8* nocapture %0) {
%2 = load i32, i32* @X_OK
%3 = tail call i32 @access(i8* %0, i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %1, %8
%6 = phi i8* [ %9, %8 ], [ %0, %1 ]
%7 = load i8, i8* %6
switch i8 %7, label %10 [
i8 47, label %8
i8 0, label %18
]
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 1
br label %5
10: ; preds = %5
%11 = tail call i32 @mkdir(i8* %0, i32 493)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = load i32, i32* @errno
%15 = load i32, i32* @EEXIST
%16 = icmp ne i32 %14, %15
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %5, %13, %10, %1
%19 = phi i32 [ 0, %1 ], [ 0, %10 ], [ %17, %13 ], [ 0, %5 ]
ret i32 %19
}