#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__ EEXIST;
int /*<<< orphan*/ FILENAME_MAX;
scalar_t__ errno;
char *gettext(char *);
scalar_t__ isdirectory(char *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strerror(scalar_t__);
int /*<<< orphan*/ warning(char *);
void ensuredirectory(char *directory) {
  char buffer[FILENAME_MAX + 4096];
  if (isdirectory(directory))
    return;
  errno = 0;
  if (mkdir(directory, 0755) && errno != EEXIST) {
    sprintf(buffer, gettext("Unable to create directory '%s': %s"), directory,
            strerror(errno));
    warning(buffer);
  }
}


x86 assembly (clang, -O0):
<ensuredirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
add    $0x1000,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <isdirectory@plt>
cmp    $0x0,%rax
je     11bc <ensuredirectory+0x5c>
movl   $0x1,-0x1c(%rbp)
jmp    1247 <ensuredirectory+0xe7>
mov    0x2e0d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1240 <ensuredirectory+0xe0>
mov    0x2de7(%rip),%rax
mov    (%rax),%rax
mov    0x2de5(%rip),%rcx
cmp    (%rcx),%rax
je     1240 <ensuredirectory+0xe0>
lea    0xdfd(%rip),%rdi
call   1060 <gettext@plt>
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rdi
mov    %rax,%rcx
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <warning@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ensuredirectory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2e73(%rip),%rax
mov    $0x1000,%ecx
add    (%rax),%ecx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
call   1050 <isdirectory@plt>
test   %rax,%rax
je     11a4 <ensuredirectory+0x44>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e25(%rip),%r12
movq   $0x0,(%r12)
mov    %r14,%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     1197 <ensuredirectory+0x37>
mov    (%r12),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
je     1197 <ensuredirectory+0x37>
lea    0xe24(%rip),%rdi
call   1060 <gettext@plt>
mov    %rax,%r15
mov    (%r12),%rdi
call   1080 <strerror@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <warning@plt>
jmp    1197 <ensuredirectory+0x37>

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str = [36 x i8] c"Unable to create directory '%s': %s\00"
define void @ensuredirectory(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i32, i32* @FILENAME_MAX
%7 = add nsw i32 %6, 4096
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
%11 = load i8*, i8** %2
%12 = call i64 @isdirectory(i8* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 1, i32* %5
br label %31
15: ; preds = %1
store i64 0, i64* @errno
%16 = load i8*, i8** %2
%17 = call i64 @mkdir(i8* %16, i32 493)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %15
%20 = load i64, i64* @errno
%21 = load i64, i64* @EEXIST
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %19
%24 = call i8* @gettext(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %2
%26 = load i64, i64* @errno
%27 = call i8* @strerror(i64 %26)
%28 = call i32 @sprintf(i8* %10, i8* %24, i8* %25, i8* %27)
%29 = call i32 @warning(i8* %10)
br label %30
30: ; preds = %23, %19, %15
store i32 0, i32* %5
br label %31
31: ; preds = %30, %14
%32 = load i8*, i8** %3
%33 = load i32, i32* %5
switch i32 %33, label %35 [
i32 0, label %34
i32 1, label %34
]
34: ; preds = %31, %31
ret void
35: ; preds = %31
unreachable
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str = [36 x i8] c"Unable to create directory '%s': %s\00"
define void @ensuredirectory(i8* %0) {
%2 = load i32, i32* @FILENAME_MAX
%3 = add nsw i32 %2, 4096
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i64 @isdirectory(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %21
8: ; preds = %1
store i64 0, i64* @errno
%9 = tail call i64 @mkdir(i8* %0, i32 493)
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp eq i64 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = tail call i8* @gettext(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%17 = load i64, i64* @errno
%18 = tail call i8* @strerror(i64 %17)
%19 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) %16, i8* %0, i8* %18)
%20 = call i32 @warning(i8* %5)
br label %21
21: ; preds = %8, %11, %15, %1
ret void
}