#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void createdir(char *dir) {
  struct stat statbuf;
  if ((stat(dir, &statbuf)) == 0) {
    if (S_ISDIR(statbuf.st_mode) == 0) {
      printf("dir: %s must be a directory\n", dir);
      exit(-1);
    }
  } else {
    if (errno == ENOENT) {
      if ((mkdir(dir, 0755)) != 0) {
        fprintf(stderr, "Can't create directory : %s : %s\n", dir,
                strerror(errno));
        exit(-1);
      }
      printf("The Created directory : %s\n", dir);
    }
  }
}


x86 assembly (clang, -O0):
<createdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    11c4 <createdir+0x54>
mov    -0x10(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    11bf <createdir+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
jmp    124e <createdir+0xde>
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
jne    1249 <createdir+0xd9>
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1239 <createdir+0xc9>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%rdi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf3(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
jmp    124e <createdir+0xde>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createdir>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     11c4 <createdir+0x54>
mov    0x2e47(%rip),%rbp
mov    0x0(%rbp),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
jne    11d2 <createdir+0x62>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jne    11f4 <createdir+0x84>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    11d2 <createdir+0x62>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     11db <createdir+0x6b>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe1e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%r14d
mov    0x0(%rbp),%rdi
call   1090 <strerror@plt>
lea    0xe0f(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [29 x i8] c"dir: %s must be a directory\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Can't create directory : %s : %s\0A\00"
@.str.2 = [28 x i8] c"The Created directory : %s\0A\00"
define void @createdir(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @stat(i8* %4, %struct.stat* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i64 @S_ISDIR(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %7
br label %36
17: ; preds = %1
%18 = load i64, i64* @errno
%19 = load i64, i64* @ENOENT
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i64 @mkdir(i8* %22, i32 493)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %2
%28 = load i64, i64* @errno
%29 = call i8* @strerror(i64 %28)
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %21
%33 = load i8*, i8** %2
%34 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %17
br label %36
36: ; preds = %35, %16
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [29 x i8] c"dir: %s must be a directory\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"Can't create directory : %s : %s\0A\00"
@.str.2 = [28 x i8] c"The Created directory : %s\0A\00"
define void @createdir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i64 @S_ISDIR(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %6
%12 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = call i64 @mkdir(i8* %0, i32 493)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %24)
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %18
%28 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %29
29: ; preds = %14, %27, %6
ret void
}