#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 */
int /*<<< orphan*/ AT_REMOVEDIR;
int O_DIRECTORY;
int O_RDONLY;
int /*<<< orphan*/ mkdir(char *, int);
int open(char *, int);
int /*<<< orphan*/ rmdir(char *);
int /*<<< orphan*/ unlinkat(int, char *, int /*<<< orphan*/);
int main() {
  mkdir("tmp/subdirnew.temporary", 0777);
  mkdir("tmp/subdirnew.temporary/subsub", 0777);
  int subd = open("tmp/subdirnew.temporary", O_RDONLY | O_DIRECTORY);
  unlinkat(subd, "subsub", AT_REMOVEDIR);
  rmdir("tmp/subdirnew.temporary");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
lea    0xeb1(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
lea    0xe76(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
lea    0xe8b(%rip),%rsi
call   1040 <unlinkat@plt>
lea    0xe4f(%rip),%rdi
call   1050 <rmdir@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
lea    0xebc(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
mov    0x2e7b(%rip),%rax
mov    0x2e64(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    0x2e49(%rip),%rcx
mov    (%rcx),%edx
lea    0xea0(%rip),%rsi
mov    %eax,%edi
call   1040 <unlinkat@plt>
mov    %rbx,%rdi
call   1050 <rmdir@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [24 x i8] c"tmp/subdirnew.temporary\00"
@.str.1 = [31 x i8] c"tmp/subdirnew.temporary/subsub\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.2 = [7 x i8] c"subsub\00"
@AT_REMOVEDIR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @mkdir(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 511)
%4 = call i32 @mkdir(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 511)
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_DIRECTORY
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = load i32, i32* @AT_REMOVEDIR
%11 = call i32 @unlinkat(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 @rmdir(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"tmp/subdirnew.temporary\00"
@.str.1 = [31 x i8] c"tmp/subdirnew.temporary/subsub\00"
@O_RDONLY = global i32 0
@O_DIRECTORY = global i32 0
@.str.2 = [7 x i8] c"subsub\00"
@AT_REMOVEDIR = global i32 0
define i32 @main() {
%1 = tail call i32 @mkdir(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 511)
%2 = tail call i32 @mkdir(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 511)
%3 = load i32, i32* @O_RDONLY
%4 = load i32, i32* @O_DIRECTORY
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @AT_REMOVEDIR
%8 = tail call i32 @unlinkat(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 @rmdir(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
ret i32 0
}