#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ dirExists(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
char *strtok(char *, char *);
int createDirectory(const char *path, char *directoryName) {
  if (path == NULL || directoryName == NULL) {
    printf("ERROR: Could not create directory. Could not read filesystem\n");
    return 0;
  }
  char name[255];
  name[0] = 0;
  if (strlen(path) > 0) {
    strncat(name, path, 255);
  }
  char *nPath = strtok(directoryName, "\n");
  if (nPath != NULL) {
    strncat(name, nPath, 255);
  } else {
    strncat(name, directoryName, 255);
  }
  if (dirExists(name)) {
    printf("ERROR: Directory already exists\n");
    return 0;
  }
  mkdir(name, 0755);
  char filePath[256];
  filePath[0] = 0;
  strncat(filePath, name, 255);
  strncat(filePath, "/.list", 7);
  printf("Debug: %s\n", filePath);
  FILE *listFile = fopen(filePath, "a");
  if (listFile == NULL) {
    printf("ERROR: Could not create .list file in %s\n", filePath);
    return 0;
  }
  fclose(listFile);
  return 1;
}


x86 assembly (clang, -O0):
<createDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a9 <createDirectory+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <createDirectory+0x43>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <createDirectory+0x1b2>
movb   $0x0,-0x120(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x0,%rax
jle    11f2 <createDirectory+0x72>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
je     1234 <createDirectory+0xb4>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
jmp    1249 <createDirectory+0xc9>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
lea    -0x120(%rbp),%rdi
call   1040 <dirExists@plt>
cmp    $0x0,%rax
je     1279 <createDirectory+0xf9>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <createDirectory+0x1b2>
lea    -0x120(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
movb   $0x0,-0x230(%rbp)
lea    -0x230(%rbp),%rdi
lea    -0x120(%rbp),%rsi
mov    $0xff,%edx
call   1080 <strncat@plt>
lea    -0x230(%rbp),%rdi
lea    0xda8(%rip),%rsi
mov    $0x7,%edx
call   1080 <strncat@plt>
lea    -0x230(%rbp),%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x230(%rbp),%rdi
lea    0xd8d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    131f <createDirectory+0x19f>
lea    -0x230(%rbp),%rsi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <createDirectory+0x1b2>
mov    -0x238(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createDirectory>:
push   %r14
push   %rbx
sub    $0x208,%rsp
test   %rdi,%rdi
je     1207 <createDirectory+0x77>
mov    %rsi,%r14
test   %rsi,%rsi
je     1207 <createDirectory+0x77>
mov    %rdi,%rbx
movb   $0x0,(%rsp)
call   1070 <strlen@plt>
test   %rax,%rax
jle    11c8 <createDirectory+0x38>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strtok@plt>
test   %rax,%rax
cmovne %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
mov    %rbx,%rdi
call   1050 <dirExists@plt>
test   %rax,%rax
je     1222 <createDirectory+0x92>
lea    0xe39(%rip),%rdi
jmp    120e <createDirectory+0x7e>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
movb   $0x0,0x100(%rsp)
lea    0x100(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1090 <strncat@plt>
lea    0xda7(%rip),%rsi
mov    %r14,%rdi
mov    $0x7,%edx
call   1090 <strncat@plt>
lea    0xd9a(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xd92(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     129f <createDirectory+0x10f>
mov    %rax,%rdi
call   1060 <fclose@plt>
mov    $0x1,%ebx
jmp    1215 <createDirectory+0x85>
lea    0xd6e(%rip),%rdi
lea    0x100(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
jmp    1215 <createDirectory+0x85>

LLVM IR (-O0):
@.str = [62 x i8] c"ERROR: Could not create directory. Could not read filesystem\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [33 x i8] c"ERROR: Directory already exists\0A\00"
@.str.3 = [7 x i8] c"/.list\00"
@.str.4 = [11 x i8] c"Debug: %s\0A\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [42 x i8] c"ERROR: Could not create .list file in %s\0A\00"
define i32 @createDirectory(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [255 x i8]
%7 = alloca i8*
%8 = alloca [256 x i8]
%9 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12, %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %66
17: ; preds = %12
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
store i8 0, i8* %18
%19 = load i8*, i8** %4
%20 = call i64 @strlen(i8* %19)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i32 @strncat(i8* %23, i8* %24, i32 255)
br label %26
26: ; preds = %22, %17
%27 = load i8*, i8** %5
%28 = call i8* @strtok(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%33 = load i8*, i8** %7
%34 = call i32 @strncat(i8* %32, i8* %33, i32 255)
br label %39
35: ; preds = %26
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%37 = load i8*, i8** %5
%38 = call i32 @strncat(i8* %36, i8* %37, i32 255)
br label %39
39: ; preds = %35, %31
%40 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%41 = call i64 @dirExists(i8* %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %66
45: ; preds = %39
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%47 = call i32 @mkdir(i8* %46, i32 493)
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
store i8 0, i8* %48
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%50 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%51 = call i32 @strncat(i8* %49, i8* %50, i32 255)
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%53 = call i32 @strncat(i8* %52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7)
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %57, i32** %9
%58 = load i32*, i32** %9
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %45
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %61)
store i32 0, i32* %3
br label %66
63: ; preds = %45
%64 = load i32*, i32** %9
%65 = call i32 @fclose(i32* %64)
store i32 1, i32* %3
br label %66
66: ; preds = %63, %60, %43, %15
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"\0A\00"
@.str.3 = [7 x i8] c"/.list\00"
@.str.4 = [11 x i8] c"Debug: %s\0A\00"
@.str.5 = [2 x i8] c"a\00"
@.str.6 = [42 x i8] c"ERROR: Could not create .list file in %s\0A\00"
@str = [32 x i8] c"ERROR: Directory already exists\00"
@str.7 = [61 x i8] c"ERROR: Could not create directory. Could not read filesystem\00"
define i32 @createDirectory(i8* %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = alloca [256 x i8]
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.7, i64 0, i64 0))
br label %41
10: ; preds = %2
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
store i8 0, i8* %11
%12 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @strncat(i8* %11, i8* %0, i32 255)
br label %16
16: ; preds = %14, %10
%17 = call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i8* %17, null
%19 = select i1 %18, i8* %1, i8* %17
%20 = call i32 @strncat(i8* %11, i8* %19, i32 255)
%21 = call i64 @dirExists(i8* %11)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %16
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %39
25: ; preds = %16
%26 = call i32 @mkdir(i8* %11, i32 493)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
store i8 0, i8* %27
%28 = call i32 @strncat(i8* %27, i8* %11, i32 255)
%29 = call i32 @strncat(i8* %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 7)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %27)
%31 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %27)
br label %37
35: ; preds = %25
%36 = call i32 @fclose(i32* %31)
br label %37
37: ; preds = %35, %33
%38 = phi i32 [ 0, %33 ], [ 1, %35 ]
br label %39
39: ; preds = %37, %23
%40 = phi i32 [ 0, %23 ], [ %38, %37 ]
br label %41
41: ; preds = %39, %8
%42 = phi i32 [ 0, %8 ], [ %40, %39 ]
ret i32 %42
}