#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 */
typedef int /*<<< orphan*/ filename;

/* Variables and functions */
int rmdir(char *);
int /*<<< orphan*/ shim_strlcat(char *, char *, int);
int /*<<< orphan*/ shim_strlcpy(char *, char const *, int);
void stress_invalid_rmdir(const char *path) {
  int ret;
  char filename[(4096) + 16];
  (void)shim_strlcpy(filename, path, sizeof(filename));
  (void)shim_strlcat(filename, "/.", sizeof(filename));
  ret = rmdir(filename);
  (void)ret;
  (void)shim_strlcat(filename, ".", sizeof(filename));
  ret = rmdir(filename);
  (void)ret;
  ret = rmdir("/");
  (void)ret;
}


x86 assembly (clang, -O0):
<stress_invalid_rmdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x1010,%edx
call   1030 <shim_strlcpy@plt>
lea    -0x1020(%rbp),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x1010,%edx
call   1050 <shim_strlcat@plt>
lea    -0x1020(%rbp),%rdi
call   1040 <rmdir@plt>
mov    %eax,-0xc(%rbp)
lea    -0x1020(%rbp),%rdi
lea    0xe78(%rip),%rsi
mov    $0x1010,%edx
call   1050 <shim_strlcat@plt>
lea    -0x1020(%rbp),%rdi
call   1040 <rmdir@plt>
mov    %eax,-0xc(%rbp)
lea    0xe5a(%rip),%rdi
call   1040 <rmdir@plt>
mov    %eax,-0xc(%rbp)
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stress_invalid_rmdir>:
push   %rbx
sub    $0x1010,%rsp
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1010,%edx
call   1030 <shim_strlcpy@plt>
lea    0xeae(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1010,%edx
call   1050 <shim_strlcat@plt>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1010,%edx
call   1050 <shim_strlcat@plt>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
lea    0xe79(%rip),%rdi
call   1040 <rmdir@plt>
add    $0x1010,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"/.\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"/\00"
define void @stress_invalid_rmdir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [4112 x i8]
store i8* %0, i8** %2
%5 = getelementptr inbounds [4112 x i8], [4112 x i8]* %4, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @shim_strlcpy(i8* %5, i8* %6, i32 4112)
%8 = getelementptr inbounds [4112 x i8], [4112 x i8]* %4, i64 0, i64 0
%9 = call i32 @shim_strlcat(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 4112)
%10 = getelementptr inbounds [4112 x i8], [4112 x i8]* %4, i64 0, i64 0
%11 = call i32 @rmdir(i8* %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = getelementptr inbounds [4112 x i8], [4112 x i8]* %4, i64 0, i64 0
%14 = call i32 @shim_strlcat(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 4112)
%15 = getelementptr inbounds [4112 x i8], [4112 x i8]* %4, i64 0, i64 0
%16 = call i32 @rmdir(i8* %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = call i32 @rmdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 %18, i32* %3
%19 = load i32, i32* %3
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"/.\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [2 x i8] c"/\00"
define void @stress_invalid_rmdir(i8* %0) {
%2 = alloca [4112 x i8]
%3 = getelementptr inbounds [4112 x i8], [4112 x i8]* %2, i64 0, i64 0
%4 = call i32 @shim_strlcpy(i8* %3, i8* %0, i32 4112)
%5 = call i32 @shim_strlcat(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 4112)
%6 = call i32 @rmdir(i8* %3)
%7 = call i32 @shim_strlcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 4112)
%8 = call i32 @rmdir(i8* %3)
%9 = call i32 @rmdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}