#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 */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
scalar_t__ mkdir(char const *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
void create_dir(const char *dir) {
  struct stat s;
  if (stat(dir, &s) == 0) {
    if (!S_ISDIR(s.st_mode)) {
      fprintf(stderr, "create_dir(): %s is not directory\n", dir);
      exit(1);
    }
  } else {
    if (mkdir(dir, 0755)) {
      fprintf(stderr, "create_dir(): cannot create %s: \n", dir);
      perror("");
      exit(1);
    }
  }
  return;
}


x86 assembly (clang, -O0):
<create_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    11bc <create_dir+0x5c>
mov    -0x10(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    11b7 <create_dir+0x57>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1208 <create_dir+0xa8>
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     1203 <create_dir+0xa3>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe50(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1208 <create_dir+0xa8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_dir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
test   %rax,%rax
je     11b7 <create_dir+0x57>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     11c4 <create_dir+0x64>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
lea    0xe9c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
je     11ca <create_dir+0x6a>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"create_dir(): %s is not directory\0A\00"
@.str.1 = [34 x i8] c"create_dir(): cannot create %s: \0A\00"
@.str.2 = [1 x i8] zeroinitializer
define void @create_dir(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 %18
7: ; preds = %1
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%9 = load i32, i32* %8
%10 = call i32 @S_ISDIR(i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %2
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %7
br label %29
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i64 @mkdir(i8* %19, i32 493)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %2
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
br label %29
29: ; preds = %28, %17
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"create_dir(): %s is not directory\0A\00"
@.str.1 = [34 x i8] c"create_dir(): cannot create %s: \0A\00"
@.str.2 = [1 x i8] zeroinitializer
define void @create_dir(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 %15
6: ; preds = %1
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 @S_ISDIR(i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = call i64 @mkdir(i8* %0, i32 493)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15, %6
ret void
}