#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__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ mkdir(char *, int);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy_s(char *, int, char const *);
int strlen(char *);
int EnsurePathExists(const char *FileName) {
  char NewPath[1024 * 2];
  int a;
  int LastSlash = 0;
  strcpy_s(NewPath, 1024 * 2, FileName);
  a = strlen(NewPath);
  for (;;) {
    a--;
    if (a == 0) {
      NewPath[0] = 0;
      break;
    }
    if (NewPath[a] == '/') {
      struct stat dummy;
      NewPath[a] = 0;
      if (stat(NewPath, &dummy) == 0) {
        if (S_ISDIR(dummy.st_mode)) {
          if (LastSlash == 0) {
            return 1;
          }
          break;
        } else {
          fprintf(stderr, "Can't create path '%s' due to file conflict\n",
                  NewPath);
          return 0;
        }
      }
      if (LastSlash == 0)
        LastSlash = a;
    }
  }
  for (; FileName[a]; a++) {
    if (FileName[a] == '/' || a == 0) {
      if (a == LastSlash)
        break;
      NewPath[a] = FileName[a];
      if (mkdir(NewPath, 0777)) {
        fprintf(stderr, "Could not create directory '%s'\n", NewPath);
        return 0;
      }
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<EnsurePathExists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x818(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1080 <strcpy_s@plt>
lea    -0x810(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x814(%rbp)
mov    -0x814(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jne    11c8 <EnsurePathExists+0x68>
movb   $0x0,-0x810(%rbp)
jmp    128a <EnsurePathExists+0x12a>
movslq -0x814(%rbp),%rax
movsbl -0x810(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1285 <EnsurePathExists+0x125>
movslq -0x814(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    1267 <EnsurePathExists+0x107>
mov    -0x820(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     123f <EnsurePathExists+0xdf>
cmpl   $0x0,-0x818(%rbp)
jne    123a <EnsurePathExists+0xda>
movl   $0x1,-0x4(%rbp)
jmp    1364 <EnsurePathExists+0x204>
jmp    128a <EnsurePathExists+0x12a>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xdaa(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1364 <EnsurePathExists+0x204>
cmpl   $0x0,-0x818(%rbp)
jne    1280 <EnsurePathExists+0x120>
mov    -0x814(%rbp),%eax
mov    %eax,-0x818(%rbp)
jmp    1285 <EnsurePathExists+0x125>
jmp    11a0 <EnsurePathExists+0x40>
jmp    128f <EnsurePathExists+0x12f>
mov    -0x10(%rbp),%rax
movslq -0x814(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     135d <EnsurePathExists+0x1fd>
mov    -0x10(%rbp),%rax
movslq -0x814(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     12c9 <EnsurePathExists+0x169>
cmpl   $0x0,-0x814(%rbp)
jne    1344 <EnsurePathExists+0x1e4>
mov    -0x814(%rbp),%eax
cmp    -0x818(%rbp),%eax
jne    12e0 <EnsurePathExists+0x180>
jmp    135d <EnsurePathExists+0x1fd>
mov    -0x10(%rbp),%rax
movslq -0x814(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x814(%rbp),%rax
mov    %cl,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     133f <EnsurePathExists+0x1df>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xcff(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1364 <EnsurePathExists+0x204>
jmp    1344 <EnsurePathExists+0x1e4>
jmp    1349 <EnsurePathExists+0x1e9>
mov    -0x814(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x814(%rbp)
jmp    128f <EnsurePathExists+0x12f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EnsurePathExists>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%r12
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1080 <strcpy_s@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
je     120e <EnsurePathExists+0xae>
movslq %ebp,%rbx
lea    (%rsp,%rbx,1),%r14
add    $0x10,%r14
shl    $0x20,%rbx
xor    %r13d,%r13d
movabs $0xffffffff00000000,%r15
ff ff ff
jmp    11d3 <EnsurePathExists+0x73>
cs nopw 0x0(%rax,%rax,1)
test   %r13d,%r13d
cmove  %ebp,%r13d
add    %r15,%rbx
add    $0xffffffffffffffff,%r14
add    $0xffffffff,%ebp
je     1211 <EnsurePathExists+0xb1>
cmpb   $0x2f,(%r14)
jne    11c7 <EnsurePathExists+0x67>
movb   $0x0,(%r14)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    11c0 <EnsurePathExists+0x60>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     1274 <EnsurePathExists+0x114>
test   %r13d,%r13d
je     12a6 <EnsurePathExists+0x146>
sar    $0x20,%rbx
jmp    1218 <EnsurePathExists+0xb8>
xor    %r13d,%r13d
movb   $0x0,0x10(%rsp)
xor    %ebx,%ebx
mov    (%r12,%rbx,1),%al
mov    $0x1,%r14d
test   %al,%al
je     1291 <EnsurePathExists+0x131>
movslq %r13d,%rbp
lea    0x10(%rsp),%r15
jmp    123e <EnsurePathExists+0xde>
movzbl 0x1(%r12,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     1291 <EnsurePathExists+0x131>
cmp    $0x2f,%al
je     1247 <EnsurePathExists+0xe7>
test   %rbx,%rbx
jne    1230 <EnsurePathExists+0xd0>
cmp    %rbx,%rbp
je     1291 <EnsurePathExists+0x131>
mov    %al,0x10(%rsp,%rbx,1)
mov    %r15,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1230 <EnsurePathExists+0xd0>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
jmp    1284 <EnsurePathExists+0x124>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
lea    0x10(%rsp),%rdx
call   1060 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r14d
jmp    1291 <EnsurePathExists+0x131>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [45 x i8] c"Can't create path '%s' due to file conflict\0A\00"
@.str.1 = [33 x i8] c"Could not create directory '%s'\0A\00"
define i32 @EnsurePathExists(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2048 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.stat
store i8* %0, i8** %3
store i32 0, i32* %6
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = call i32 @strcpy_s(i8* %8, i32 2048, i8* %9)
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
br label %13
13: ; preds = %54, %1
%14 = load i32, i32* %5
%15 = add nsw i32 %14, -1
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
store i8 0, i8* %19
br label %55
20: ; preds = %13
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 47
br i1 %26, label %27, label %54
27: ; preds = %20
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %29
store i8 0, i8* %30
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%32 = call i64 @stat(i8* %31, %struct.stat* %7)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %48
34: ; preds = %27
%35 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @S_ISDIR(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 1, i32* %2
br label %101
43: ; preds = %39
br label %55
44: ; preds = %34
%45 = load i32, i32* @stderr
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %46)
store i32 0, i32* %2
br label %101
48: ; preds = %27
%49 = load i32, i32* %6
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = load i32, i32* %5
store i32 %52, i32* %6
br label %53
53: ; preds = %51, %48
br label %54
54: ; preds = %53, %20
br label %13
55: ; preds = %43, %18
br label %56
56: ; preds = %97, %55
%57 = load i8*, i8** %3
%58 = load i32, i32* %5
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = icmp ne i8 %61, 0
br i1 %62, label %63, label %100
63: ; preds = %56
%64 = load i8*, i8** %3
%65 = load i32, i32* %5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 47
br i1 %70, label %74, label %71
71: ; preds = %63
%72 = load i32, i32* %5
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %96
74: ; preds = %71, %63
%75 = load i32, i32* %5
%76 = load i32, i32* %6
%77 = icmp eq i32 %75, %76
br i1 %77, label %78, label %79
78: ; preds = %74
br label %100
79: ; preds = %74
%80 = load i8*, i8** %3
%81 = load i32, i32* %5
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8, i8* %83
%85 = load i32, i32* %5
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 %86
store i8 %84, i8* %87
%88 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%89 = call i64 @mkdir(i8* %88, i32 511)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %95
91: ; preds = %79
%92 = load i32, i32* @stderr
%93 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%94 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %93)
store i32 0, i32* %2
br label %101
95: ; preds = %79
br label %96
96: ; preds = %95, %71
br label %97
97: ; preds = %96
%98 = load i32, i32* %5
%99 = add nsw i32 %98, 1
store i32 %99, i32* %5
br label %56
100: ; preds = %78, %56
store i32 1, i32* %2
br label %101
101: ; preds = %100, %91, %44, %42
%102 = load i32, i32* %2
ret i32 %102
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [45 x i8] c"Can't create path '%s' due to file conflict\0A\00"
@.str.1 = [33 x i8] c"Could not create directory '%s'\0A\00"
define i32 @EnsurePathExists(i8* %0) {
%2 = alloca [2048 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy_s(i8* %4, i32 2048, i8* %0)
%6 = call i32 @strlen(i8* %4)
%7 = add i32 %6, -1
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = bitcast %struct.stat* %3 to i8*
%11 = sext i32 %7 to i64
br label %14
12: ; preds = %42, %1
%13 = phi i32 [ 0, %1 ], [ %43, %42 ]
store i8 0, i8* %4
br label %47
14: ; preds = %9, %42
%15 = phi i64 [ %11, %9 ], [ %44, %42 ]
%16 = phi i32 [ 0, %9 ], [ %43, %42 ]
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %15
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
br i1 %19, label %20, label %42
20: ; preds = %14
store i8 0, i8* %17
%21 = call i64 @stat(i8* %4, %struct.stat* %3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @S_ISDIR(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = icmp eq i32 %16, 0
br i1 %29, label %37, label %39
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %4)
br label %37
33: ; preds = %20
%34 = icmp eq i32 %16, 0
%35 = trunc i64 %15 to i32
%36 = select i1 %34, i32 %35, i32 %16
br label %42
37: ; preds = %30, %28
%38 = phi i32 [ 0, %30 ], [ 1, %28 ]
br label %75
39: ; preds = %28
%40 = shl i64 %15, 32
%41 = ashr exact i64 %40, 32
br label %47
42: ; preds = %33, %14
%43 = phi i32 [ %16, %14 ], [ %36, %33 ]
%44 = add nsw i64 %15, -1
%45 = trunc i64 %44 to i32
%46 = icmp eq i32 %45, 0
br i1 %46, label %12, label %14
47: ; preds = %39, %12
%48 = phi i32 [ %16, %39 ], [ %13, %12 ]
%49 = phi i64 [ %41, %39 ], [ 0, %12 ]
%50 = getelementptr inbounds i8, i8* %0, i64 %49
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 0
br i1 %52, label %75, label %53
53: ; preds = %47
%54 = sext i32 %48 to i64
br label %55
55: ; preds = %53, %70
%56 = phi i64 [ %49, %53 ], [ %71, %70 ]
%57 = phi i8 [ %51, %53 ], [ %73, %70 ]
%58 = icmp eq i8 %57, 47
%59 = icmp eq i64 %56, 0
%60 = select i1 %58, i1 true, i1 %59
br i1 %60, label %61, label %70
61: ; preds = %55
%62 = icmp eq i64 %56, %54
br i1 %62, label %75, label %63
63: ; preds = %61
%64 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %56
store i8 %57, i8* %64
%65 = call i64 @mkdir(i8* %4, i32 511)
%66 = icmp eq i64 %65, 0
br i1 %66, label %70, label %67
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %75
70: ; preds = %55, %63
%71 = add i64 %56, 1
%72 = getelementptr inbounds i8, i8* %0, i64 %71
%73 = load i8, i8* %72
%74 = icmp eq i8 %73, 0
br i1 %74, label %75, label %55
75: ; preds = %61, %70, %47, %37, %67
%76 = phi i32 [ 0, %67 ], [ %38, %37 ], [ 1, %47 ], [ 1, %70 ], [ 1, %61 ]
ret i32 %76
}