#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 */
#define EINVAL 130
#define EIO 129
#define ENOENT 128
int /*<<< orphan*/ err(int, char *);
int errno;
int /*<<< orphan*/ finish();
int /*<<< orphan*/ killdir();
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ startup();
int /*<<< orphan*/ warnx(char *);
void test5(void) {
  printf("Checking if creating subdirs works after rmdir...\n");
  startup();
  killdir();
  if (mkdir("newdir", 0775) < 0) {
    switch (errno) {
    case EINVAL:
    case EIO:
    case ENOENT:
      break;
    default:
      err(1, "mkdir in removed dir");
      break;
    }
  } else {
    warnx("newfile: creating directories after rmdir works");
    warnx("(this is only ok if the space gets reclaimed)");
    mkdir("newdir/t0", 0775);
    mkdir("newdir/t1", 0775);
    mkdir("newdir/t2", 0775);
    mkdir("newdir/t3", 0775);
    mkdir("newdir/t4", 0775);
    mkdir("newdir/t5", 0775);
  }
  finish();
}


x86 assembly (clang, -O0):
<test5>:
push   %rbp
mov    %rsp,%rbp
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <startup@plt>
mov    $0x0,%al
call   1070 <killdir@plt>
lea    0xe9e(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    11de <test5+0x6e>
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x2,%eax
ja     11c8 <test5+0x58>
jmp    11c3 <test5+0x53>
jmp    11d9 <test5+0x69>
mov    $0x1,%edi
lea    0xe66(%rip),%rsi
call   1080 <err@plt>
jmp    125c <test5+0xec>
lea    0xe6a(%rip),%rdi
call   1060 <warnx@plt>
lea    0xe8e(%rip),%rdi
call   1060 <warnx@plt>
lea    0xeb0(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xea9(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xea2(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xe9b(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xe94(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xe8d(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
mov    $0x0,%al
call   1030 <finish@plt>
pop    %rbp
ret

x86 assembly (clang, -O2):
<test5>:
push   %rax
lea    0xf3e(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1090 <startup@plt>
xor    %eax,%eax
call   1070 <killdir@plt>
lea    0xe6e(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
js     1225 <test5+0xb5>
lea    0xe70(%rip),%rdi
call   1060 <warnx@plt>
lea    0xe94(%rip),%rdi
call   1060 <warnx@plt>
lea    0xeb6(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xeaf(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xea8(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xea1(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xe9a(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
lea    0xe93(%rip),%rdi
mov    $0x1fd,%esi
call   1040 <mkdir@plt>
jmp    1247 <test5+0xd7>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
cmp    $0x3,%eax
jb     1247 <test5+0xd7>
lea    0xdca(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
xor    %eax,%eax
pop    %rcx
jmp    1030 <finish@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"Checking if creating subdirs works after rmdir...\0A\00"
@.str.1 = [7 x i8] c"newdir\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"mkdir in removed dir\00"
@.str.3 = [48 x i8] c"newfile: creating directories after rmdir works\00"
@.str.4 = [46 x i8] c"(this is only ok if the space gets reclaimed)\00"
@.str.5 = [10 x i8] c"newdir/t0\00"
@.str.6 = [10 x i8] c"newdir/t1\00"
@.str.7 = [10 x i8] c"newdir/t2\00"
@.str.8 = [10 x i8] c"newdir/t3\00"
@.str.9 = [10 x i8] c"newdir/t4\00"
@.str.10 = [10 x i8] c"newdir/t5\00"
define void @test5() {
%1 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%2 = call i32 (...) @startup()
%3 = call i32 (...) @killdir()
%4 = call i64 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 509)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @errno
switch i32 %7, label %9 [
i32 130, label %8
i32 129, label %8
i32 128, label %8
]
8: ; preds = %6, %6, %6
br label %11
9: ; preds = %6
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %8
br label %21
12: ; preds = %0
%13 = call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @warnx(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%15 = call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 509)
%16 = call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 509)
%17 = call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 509)
%18 = call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 509)
%19 = call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 509)
%20 = call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i32 509)
br label %21
21: ; preds = %12, %11
%22 = call i32 (...) @finish()
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"newdir\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"mkdir in removed dir\00"
@.str.3 = [48 x i8] c"newfile: creating directories after rmdir works\00"
@.str.4 = [46 x i8] c"(this is only ok if the space gets reclaimed)\00"
@.str.5 = [10 x i8] c"newdir/t0\00"
@.str.6 = [10 x i8] c"newdir/t1\00"
@.str.7 = [10 x i8] c"newdir/t2\00"
@.str.8 = [10 x i8] c"newdir/t3\00"
@.str.9 = [10 x i8] c"newdir/t4\00"
@.str.10 = [10 x i8] c"newdir/t5\00"
@str = [50 x i8] c"Checking if creating subdirs works after rmdir...\00"
define void @test5() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @startup()
%3 = tail call i32 (...) @killdir()
%4 = tail call i64 @mkdir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 509)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = add i32 %7, -128
%9 = icmp ult i32 %8, 3
br i1 %9, label %21, label %10
10: ; preds = %6
%11 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %21
12: ; preds = %0
%13 = tail call i32 @warnx(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @warnx(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 509)
%16 = tail call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 509)
%17 = tail call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 509)
%18 = tail call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 509)
%19 = tail call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 509)
%20 = tail call i64 @mkdir(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i32 509)
br label %21
21: ; preds = %6, %10, %12
%22 = tail call i32 (...) @finish()
ret void
}