#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*/ F_OK;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ access_test(char *, int /*<<< orphan*/);
int expect_zng(int, int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ mkdir_test(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ rmdir_test(char *);
int /*<<< orphan*/ stat_test(char *, struct stat *);
int /*<<< orphan*/ testbreak();
int /*<<< orphan*/ xtmpnam(char *);
int BasicDir(void) {
  char tf[8192] = {0};
  int passed;
  int block = 0;
  struct stat buf;
  xtmpnam(tf);
  testbreak();
  passed = expect_zng(0, mkdir_test(tf, S_IRWXU));
  if (passed != 0) {
    printf("\tFailed Phase 2: This call did something unexpected.\n");
    fflush(NULL);
    block = -1;
  };
  if (passed == -1) {
    printf("\tFail Phase 2: Aborting test because of catastrophic failure\n");
    fflush(NULL);
    return passed;
  };
  passed = expect_zng(0, stat_test(tf, &buf));
  if (passed != 0) {
    printf("\tFailed Phase 2: This call did something unexpected.\n");
    fflush(NULL);
    block = -1;
  }
  if (!(S_ISDIR(buf.st_mode))) {
    printf("\tFailed Phase 2: mkdir() something that wasn't a directory\n");
    fflush(NULL);
    block = -1;
  }
  passed = expect_zng(0, rmdir_test(tf));
  if (passed != 0) {
    printf("\tFailed Phase 2: This call did something unexpected.\n");
    fflush(NULL);
    block = -1;
  };
  passed = expect_zng(-1, access_test(tf, F_OK));
  if (passed != 0) {
    printf("\tFailed Phase 2: This call did something unexpected.\n");
    fflush(NULL);
    block = -1;
  };
  testbreak();
  return block;
}


x86 assembly (clang, -O0):
<BasicDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
movl   $0x0,-0x2018(%rbp)
lea    -0x2010(%rbp),%rdi
call   1030 <xtmpnam@plt>
mov    $0x0,%al
call   10a0 <testbreak@plt>
lea    -0x2010(%rbp),%rdi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
call   10b0 <mkdir_test@plt>
mov    %eax,%esi
xor    %edi,%edi
call   1080 <expect_zng@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
je     123b <BasicDir+0x8b>
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x2018(%rbp)
ff ff ff
cmpl   $0xffffffff,-0x2014(%rbp)
jne    126b <BasicDir+0xbb>
lea    0xde7(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
mov    -0x2014(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1396 <BasicDir+0x1e6>
lea    -0x2010(%rbp),%rdi
lea    -0x2020(%rbp),%rsi
call   10d0 <stat_test@plt>
mov    %eax,%esi
xor    %edi,%edi
call   1080 <expect_zng@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
je     12b9 <BasicDir+0x109>
lea    0xd5f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x2018(%rbp)
ff ff ff
mov    -0x2020(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    12ec <BasicDir+0x13c>
lea    0xda0(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x2018(%rbp)
ff ff ff
lea    -0x2010(%rbp),%rdi
call   1070 <rmdir_test@plt>
mov    %eax,%esi
xor    %edi,%edi
call   1080 <expect_zng@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
je     1333 <BasicDir+0x183>
lea    0xce5(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x2018(%rbp)
ff ff ff
lea    -0x2010(%rbp),%rdi
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
call   10c0 <access_test@plt>
mov    %eax,%esi
mov    $0xffffffff,%edi
call   1080 <expect_zng@plt>
mov    %eax,-0x2014(%rbp)
cmpl   $0x0,-0x2014(%rbp)
je     1386 <BasicDir+0x1d6>
lea    0xc92(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
movl   $0xffffffff,-0x2018(%rbp)
ff ff ff
mov    $0x0,%al
call   10a0 <testbreak@plt>
mov    -0x2018(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BasicDir>:
push   %rbp
push   %rbx
sub    $0x2018,%rsp
lea    0x10(%rsp),%rbp
xor    %ebx,%ebx
mov    $0x2000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rbp,%rdi
call   1040 <xtmpnam@plt>
xor    %eax,%eax
call   10a0 <testbreak@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10b0 <mkdir_test@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1080 <expect_zng@plt>
test   %eax,%eax
je     121f <BasicDir+0x6f>
mov    %eax,%ebp
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%ebp
je     12eb <BasicDir+0x13b>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10d0 <stat_test@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1080 <expect_zng@plt>
test   %eax,%eax
je     1253 <BasicDir+0xa3>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebx
mov    0x8(%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
jne    1278 <BasicDir+0xc8>
lea    0xd99(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebx
lea    0x10(%rsp),%rdi
call   1070 <rmdir_test@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1080 <expect_zng@plt>
test   %eax,%eax
je     12a7 <BasicDir+0xf7>
lea    0xde2(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebx
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   10c0 <access_test@plt>
mov    $0xffffffff,%edi
mov    %eax,%esi
call   1080 <expect_zng@plt>
test   %eax,%eax
je     12e2 <BasicDir+0x132>
lea    0xda7(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebx
xor    %eax,%eax
call   10a0 <testbreak@plt>
jmp    1303 <BasicDir+0x153>
lea    0xd49(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IRWXU = global i32 0
@.str = [54 x i8] c"\09Failed Phase 2: This call did something unexpected.\0A\00"
@.str.1 = [62 x i8] c"\09Fail Phase 2: Aborting test because of catastrophic failure\0A\00"
@.str.2 = [60 x i8] c"\09Failed Phase 2: mkdir() something that wasn't a directory\0A\00"
@F_OK = global i32 0
define i32 @BasicDir() {
%1 = alloca i32
%2 = alloca [8192 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.stat
%6 = bitcast [8192 x i8]* %2 to i8*
store i32 0, i32* %4
%7 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%8 = call i32 @xtmpnam(i8* %7)
%9 = call i32 (...) @testbreak()
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%11 = load i32, i32* @S_IRWXU
%12 = call i32 @mkdir_test(i8* %10, i32 %11)
%13 = call i32 @expect_zng(i32 0, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @fflush(i32* null)
store i32 -1, i32* %4
br label %19
19: ; preds = %16, %0
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @fflush(i32* null)
%25 = load i32, i32* %3
store i32 %25, i32* %1
br label %65
26: ; preds = %19
%27 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%28 = call i32 @stat_test(i8* %27, %struct.stat* %5)
%29 = call i32 @expect_zng(i32 0, i32 %28)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @fflush(i32* null)
store i32 -1, i32* %4
br label %35
35: ; preds = %32, %26
%36 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @S_ISDIR(i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @fflush(i32* null)
store i32 -1, i32* %4
br label %43
43: ; preds = %40, %35
%44 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%45 = call i32 @rmdir_test(i8* %44)
%46 = call i32 @expect_zng(i32 0, i32 %45)
store i32 %46, i32* %3
%47 = load i32, i32* %3
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %43
%50 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%51 = call i32 @fflush(i32* null)
store i32 -1, i32* %4
br label %52
52: ; preds = %49, %43
%53 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%54 = load i32, i32* @F_OK
%55 = call i32 @access_test(i8* %53, i32 %54)
%56 = call i32 @expect_zng(i32 -1, i32 %55)
store i32 %56, i32* %3
%57 = load i32, i32* %3
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%61 = call i32 @fflush(i32* null)
store i32 -1, i32* %4
br label %62
62: ; preds = %59, %52
%63 = call i32 (...) @testbreak()
%64 = load i32, i32* %4
store i32 %64, i32* %1
br label %65
65: ; preds = %62, %22
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IRWXU = global i32 0
@F_OK = global i32 0
@str = [59 x i8] c"\09Failed Phase 2: mkdir() something that wasn't a directory\00"
@str.6 = [61 x i8] c"\09Fail Phase 2: Aborting test because of catastrophic failure\00"
@str.7 = [53 x i8] c"\09Failed Phase 2: This call did something unexpected.\00"
define i32 @BasicDir() {
%1 = alloca [8192 x i8]
%2 = alloca %struct.stat
%3 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.stat* %2 to i8*
%5 = call i32 @xtmpnam(i8* %3)
%6 = call i32 (...) @testbreak()
%7 = load i32, i32* @S_IRWXU
%8 = call i32 @mkdir_test(i8* %3, i32 %7)
%9 = call i32 @expect_zng(i32 0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%13 = call i32 @fflush(i32* null)
%14 = icmp eq i32 %9, -1
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.6, i64 0, i64 0))
%17 = call i32 @fflush(i32* null)
br label %55
18: ; preds = %0, %11
%19 = phi i32 [ -1, %11 ], [ 0, %0 ]
%20 = call i32 @stat_test(i8* %3, %struct.stat* %2)
%21 = call i32 @expect_zng(i32 0, i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%25 = call i32 @fflush(i32* null)
br label %26
26: ; preds = %23, %18
%27 = phi i32 [ -1, %23 ], [ %19, %18 ]
%28 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @S_ISDIR(i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%34 = call i32 @fflush(i32* null)
br label %35
35: ; preds = %32, %26
%36 = phi i32 [ %27, %26 ], [ -1, %32 ]
%37 = call i32 @rmdir_test(i8* %3)
%38 = call i32 @expect_zng(i32 0, i32 %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %35
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%42 = call i32 @fflush(i32* null)
br label %43
43: ; preds = %40, %35
%44 = phi i32 [ -1, %40 ], [ %36, %35 ]
%45 = load i32, i32* @F_OK
%46 = call i32 @access_test(i8* %3, i32 %45)
%47 = call i32 @expect_zng(i32 -1, i32 %46)
%48 = icmp eq i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %43
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.7, i64 0, i64 0))
%51 = call i32 @fflush(i32* null)
br label %52
52: ; preds = %49, %43
%53 = phi i32 [ -1, %49 ], [ %44, %43 ]
%54 = call i32 (...) @testbreak()
br label %55
55: ; preds = %52, %15
%56 = phi i32 [ -1, %15 ], [ %53, %52 ]
ret i32 %56
}