#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__ EACCES;
scalar_t__ EEXIST;
scalar_t__ ENOSPC;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int mkdir(char *, int);
int /*<<< orphan*/ print_log(char *);
int /*<<< orphan*/ strcat(char *, char *);
void create_directory(char *name) {
  char message[100];
  message[0] = '\0';
  strcat(message, "creating directory: ");
  strcat(message, name);
  print_log(message);
  int success = mkdir(name, 0755);
  if (success == 0) {
    print_log("-- directory created");
  } else if (EEXIST == errno) {
    print_log("-- directory already exists");
    print_log("-- moving on...");
  } else if (EACCES == errno) {
    print_log("-- no permission to create directory");
    exit(1);
  } else if (ENOSPC == errno) {
    print_log("-- not enough space to create directory");
    exit(1);
  } else {
    print_log("-- could not create directory");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<create_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x70(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x70(%rbp),%rdi
call   1040 <print_log@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jne    11a5 <create_directory+0x65>
lea    0xe7a(%rip),%rdi
call   1040 <print_log@plt>
jmp    1257 <create_directory+0x117>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%rax
jne    11dc <create_directory+0x9c>
lea    0xe64(%rip),%rdi
call   1040 <print_log@plt>
lea    0xe74(%rip),%rdi
call   1040 <print_log@plt>
jmp    1252 <create_directory+0x112>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    120c <create_directory+0xcc>
lea    0xe59(%rip),%rdi
call   1040 <print_log@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%rax
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%rax
jne    123c <create_directory+0xfc>
lea    0xe4e(%rip),%rdi
call   1040 <print_log@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe60(%rip),%rdi
call   1040 <print_log@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1257 <create_directory+0x117>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_directory>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
movb   $0x0,(%rsp)
lea    0xeab(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
mov    %r14,%rdi
call   1040 <print_log@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     11af <create_directory+0x6f>
mov    0x2e4d(%rip),%rcx
mov    0x2e3e(%rip),%rax
mov    (%rax),%rax
cmp    %rax,(%rcx)
jne    11c3 <create_directory+0x83>
lea    0xe89(%rip),%rdi
call   1040 <print_log@plt>
lea    0xe99(%rip),%rdi
jmp    11b6 <create_directory+0x76>
lea    0xe5f(%rip),%rdi
call   1040 <print_log@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e1e(%rip),%rcx
cmp    %rax,(%rcx)
jne    11d8 <create_directory+0x98>
lea    0xe80(%rip),%rdi
jmp    11f4 <create_directory+0xb4>
mov    0x2de9(%rip),%rcx
cmp    %rax,(%rcx)
jne    11ed <create_directory+0xad>
lea    0xe90(%rip),%rdi
jmp    11f4 <create_directory+0xb4>
lea    0xeaf(%rip),%rdi
call   1040 <print_log@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"creating directory: \00"
@.str.1 = [21 x i8] c"-- directory created\00"
@EEXIST = global i64 0
@errno = global i64 0
@.str.2 = [28 x i8] c"-- directory already exists\00"
@.str.3 = [16 x i8] c"-- moving on...\00"
@EACCES = global i64 0
@.str.4 = [37 x i8] c"-- no permission to create directory\00"
@ENOSPC = global i64 0
@.str.5 = [40 x i8] c"-- not enough space to create directory\00"
@.str.6 = [30 x i8] c"-- could not create directory\00"
define void @create_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca [100 x i8]
%4 = alloca i32
store i8* %0, i8** %2
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
store i8 0, i8* %5
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @strcat(i8* %8, i8* %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = call i32 @print_log(i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @mkdir(i8* %13, i32 493)
store i32 %14, i32* %4
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 @print_log(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %44
19: ; preds = %1
%20 = load i64, i64* @EEXIST
%21 = load i64, i64* @errno
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @print_log(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @print_log(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %43
26: ; preds = %19
%27 = load i64, i64* @EACCES
%28 = load i64, i64* @errno
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 @print_log(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %26
%34 = load i64, i64* @ENOSPC
%35 = load i64, i64* @errno
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @print_log(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %33
%41 = call i32 @print_log(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %23
br label %44
44: ; preds = %43, %17
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"creating directory: \00"
@.str.1 = [21 x i8] c"-- directory created\00"
@EEXIST = global i64 0
@errno = global i64 0
@.str.2 = [28 x i8] c"-- directory already exists\00"
@.str.3 = [16 x i8] c"-- moving on...\00"
@EACCES = global i64 0
@.str.4 = [37 x i8] c"-- no permission to create directory\00"
@ENOSPC = global i64 0
@.str.5 = [40 x i8] c"-- not enough space to create directory\00"
@.str.6 = [30 x i8] c"-- could not create directory\00"
define void @create_directory(i8* %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
%4 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strcat(i8* %3, i8* %0)
%6 = call i32 @print_log(i8* %3)
%7 = call i32 @mkdir(i8* %0, i32 493)
%8 = icmp eq i32 %7, 0
br i1 %8, label %30, label %9
9: ; preds = %1
%10 = load i64, i64* @EEXIST
%11 = load i64, i64* @errno
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @print_log(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %30
15: ; preds = %9
%16 = load i64, i64* @EACCES
%17 = icmp eq i64 %16, %11
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @print_log(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = load i64, i64* @ENOSPC
%23 = icmp eq i64 %22, %11
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i32 @print_log(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %21
%28 = call i32 @print_log(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %1, %13
%31 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %13 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %1 ]
%32 = call i32 @print_log(i8* %31)
ret void
}