#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 dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ chdir(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ unlink(int /*<<< orphan*/);
int flatclean(void) {
  DIR *dirp;
  struct dirent *dp;
  if (chdir("/etc/config") < 0)
    return ((-(78)));
  if ((dirp = opendir(".")) == NULL)
    return ((-(82)));
  while ((dp = readdir(dirp)) != NULL) {
    if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..") == 0))
      continue;
    unlink(dp->d_name);
  }
  closedir(dirp);
  return (0);
}


x86 assembly (clang, -O0):
<flatclean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1050 <chdir@plt>
cmp    $0x0,%rax
jge    118a <flatclean+0x2a>
movl   $0xffffffb2,-0x4(%rbp)
jmp    1229 <flatclean+0xc9>
lea    0xe7c(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b0 <flatclean+0x50>
movl   $0xffffffae,-0x4(%rbp)
jmp    1229 <flatclean+0xc9>
jmp    11b5 <flatclean+0x55>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1219 <flatclean+0xb9>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1204 <flatclean+0xa4>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1209 <flatclean+0xa9>
jmp    11b5 <flatclean+0x55>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <unlink@plt>
jmp    11b5 <flatclean+0x55>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flatclean>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe91(%rip),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
js     11f3 <flatclean+0x93>
lea    0xe8d(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11fa <flatclean+0x9a>
mov    %rax,%r12
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11e7 <flatclean+0x87>
mov    %rax,%rbx
lea    0xe69(%rip),%r14
lea    0xe61(%rip),%r15
jmp    11c0 <flatclean+0x60>
nopl   (%rax)
mov    %r12,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e7 <flatclean+0x87>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b0 <flatclean+0x50>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b0 <flatclean+0x50>
mov    (%rbx),%edi
call   1030 <unlink@plt>
jmp    11b0 <flatclean+0x50>
mov    %r12,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
jmp    11ff <flatclean+0x9f>
mov    $0xffffffb2,%eax
jmp    11ff <flatclean+0x9f>
mov    $0xffffffae,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [12 x i8] c"/etc/config\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @flatclean() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = call i64 @chdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 -78, i32* %1
br label %37
7: ; preds = %0
%8 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %7
store i32 -82, i32* %1
br label %37
11: ; preds = %7
br label %12
12: ; preds = %29, %28, %11
%13 = load i32*, i32** %2
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %3
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %3
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i64 @strcmp(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = load %struct.dirent*, %struct.dirent** %3
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @strcmp(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22, %16
br label %12
29: ; preds = %22
%30 = load %struct.dirent*, %struct.dirent** %3
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @unlink(i32 %32)
br label %12
34: ; preds = %12
%35 = load i32*, i32** %2
%36 = call i32 @closedir(i32* %35)
store i32 0, i32* %1
br label %37
37: ; preds = %34, %10, %6
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [12 x i8] c"/etc/config\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @flatclean() {
%1 = tail call i64 @chdir(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = icmp slt i64 %1, 0
br i1 %2, label %27, label %3
3: ; preds = %0
%4 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %27, label %6
6: ; preds = %3
%7 = tail call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %25, label %9
9: ; preds = %6, %19
%10 = phi %struct.dirent* [ %20, %19 ], [ %7, %6 ]
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i64 @strcmp(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %9
%16 = load i32, i32* %11
%17 = tail call i64 @strcmp(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %9, %15, %22
%20 = tail call %struct.dirent* @readdir(i32* %4)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %25, label %9
22: ; preds = %15
%23 = load i32, i32* %11
%24 = tail call i32 @unlink(i32 %23)
br label %19
25: ; preds = %19, %6
%26 = tail call i32 @closedir(i32* %4)
br label %27
27: ; preds = %3, %0, %25
%28 = phi i32 [ 0, %25 ], [ -78, %0 ], [ -82, %3 ]
ret i32 %28
}