#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 S_IROTH;
int S_IRWXG;
int S_IRWXU;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int S_IXOTH;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                         char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getchar();
int mkdir(char *, int);
int /*<<< orphan*/ puts(char *);
int stat(char *, struct stat *);
int mk_default_dir(char *path) {
  char *notdirerr = "%s exists but is not a directory.\n";
  char *othererr = "Error creating %s";
  char *play_anyway = "Can't write high scores to default target\nfile or read "
                      "default keyfile.\n"
                      "Play anyway? [y/n]";
  char reply;
  struct stat buf;
  int statret;
  int mkdirret;
  statret = stat(path, &buf);
  if (statret == -1) {
    mkdirret = mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    if (mkdirret == 0) {
      return 0;
    }
    error(0, 0, othererr, path);
  } else if (S_ISDIR(buf.st_mode)) {
    return 0;
  } else {
    error(0, 0, notdirerr, path);
  }
  while (1) {
    puts(play_anyway);
    reply = getchar();
    if (reply == 'n')
      exit(0);
    if (reply == 'y')
      break;
  }
  return 1;
}


x86 assembly (clang, -O0):
<mk_default_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1213 <mk_default_dir+0xa3>
mov    -0x10(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    0x2e0d(%rip),%rax
or     (%rax),%esi
mov    0x2df4(%rip),%rax
or     (%rax),%esi
mov    0x2e03(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    11fd <mk_default_dir+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    1291 <mk_default_dir+0x121>
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %esi,%esi
mov    %esi,%edi
call   1080 <error@plt>
jmp    1247 <mk_default_dir+0xd7>
mov    -0x30(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1231 <mk_default_dir+0xc1>
movl   $0x0,-0x4(%rbp)
jmp    1291 <mk_default_dir+0x121>
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %esi,%esi
mov    %esi,%edi
call   1080 <error@plt>
jmp    1247 <mk_default_dir+0xd7>
jmp    124c <mk_default_dir+0xdc>
mov    -0x28(%rbp),%rdi
call   1040 <puts@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0x6e,%eax
jne    1273 <mk_default_dir+0x103>
xor    %edi,%edi
call   1090 <exit@plt>
movsbl -0x29(%rbp),%eax
cmp    $0x79,%eax
jne    1285 <mk_default_dir+0x115>
jmp    128a <mk_default_dir+0x11a>
jmp    124c <mk_default_dir+0xdc>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_default_dir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
je     11a3 <mk_default_dir+0x33>
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1217 <mk_default_dir+0xa7>
lea    0xe5f(%rip),%rdx
jmp    11da <mk_default_dir+0x6a>
mov    0x2e3e(%rip),%rax
mov    0x2e27(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0c(%rip),%rax
or     (%rax),%esi
mov    0x2e1b(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
test   %eax,%eax
je     1215 <mk_default_dir+0xa5>
lea    0xe49(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %rbx,%rcx
call   1080 <error@plt>
lea    0xe48(%rip),%rbx
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x79,%al
je     120e <mk_default_dir+0x9e>
cmp    $0x6e,%al
jne    11f0 <mk_default_dir+0x80>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x1,%eax
jmp    1217 <mk_default_dir+0xa7>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [35 x i8] c"%s exists but is not a directory.\0A\00"
@.str.1 = [18 x i8] c"Error creating %s\00"
@.str.2 = [91 x i8] c"Can't write high scores to default target\0Afile or read default keyfile.\0APlay anyway? [y/n]\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
define i32 @mk_default_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0), i8** %6
%11 = load i8*, i8** %3
%12 = call i32 @stat(i8* %11, %struct.stat* %8)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %32
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IROTH
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IXOTH
%23 = or i32 %21, %22
%24 = call i32 @mkdir(i8* %16, i32 %23)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %15
store i32 0, i32* %2
br label %60
28: ; preds = %15
%29 = load i8*, i8** %5
%30 = load i8*, i8** %3
%31 = call i32 @error(i32 0, i32 0, i8* %29, i8* %30)
br label %43
32: ; preds = %1
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i64 @S_ISDIR(i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 0, i32* %2
br label %60
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = load i8*, i8** %3
%41 = call i32 @error(i32 0, i32 0, i8* %39, i8* %40)
br label %42
42: ; preds = %38
br label %43
43: ; preds = %42, %28
br label %44
44: ; preds = %43, %58
%45 = load i8*, i8** %6
%46 = call i32 @puts(i8* %45)
%47 = call signext i8 (...) @getchar()
store i8 %47, i8* %7
%48 = load i8, i8* %7
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 110
br i1 %50, label %51, label %53
51: ; preds = %44
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %44
%54 = load i8, i8* %7
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 121
br i1 %56, label %57, label %58
57: ; preds = %53
br label %59
58: ; preds = %53
br label %44
59: ; preds = %57
store i32 1, i32* %2
br label %60
60: ; preds = %59, %37, %27
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [35 x i8] c"%s exists but is not a directory.\0A\00"
@.str.1 = [18 x i8] c"Error creating %s\00"
@.str.2 = [91 x i8] c"Can't write high scores to default target\0Afile or read default keyfile.\0APlay anyway? [y/n]\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
define i32 @mk_default_dir(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = load i32, i32* @S_IRWXU
%8 = load i32, i32* @S_IRWXG
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IROTH
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IXOTH
%13 = or i32 %11, %12
%14 = tail call i32 @mkdir(i8* %0, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %29, label %21
16: ; preds = %1
%17 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i64 @S_ISDIR(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %16, %6
%22 = phi i8* [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %16 ]
%23 = tail call i32 @error(i32 0, i32 0, i8* %22, i8* %0)
br label %24
24: ; preds = %24, %21
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call signext i8 (...) @getchar()
switch i8 %26, label %24 [
i8 110, label %27
i8 121, label %29
]
27: ; preds = %24
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %24, %16, %6
%30 = phi i32 [ 0, %6 ], [ 0, %16 ], [ 1, %24 ]
ret i32 %30
}