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

/* Variables and functions */
int /*<<< orphan*/ clean_index_dir();
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ is_imgtype(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
char *strrchr(char *, char);
int /*<<< orphan*/ unlink(char *);
void clean_dir(void) {
  DIR *dir = opendir(".");
  if (!dir)
    return;
  struct dirent *ent;
  while ((ent = readdir(dir))) {
    if (*ent->d_name == '.')
      continue;
    char *p = strrchr(ent->d_name, '.');
    if (p && is_imgtype(p))
      unlink(ent->d_name);
    else
      printf("Warning: %s\n", ent->d_name);
  }
  closedir(dir);
  clean_index_dir();
}


x86 assembly (clang, -O0):
<clean_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a8 <clean_dir+0x28>
jmp    1248 <clean_dir+0xc8>
jmp    11ad <clean_dir+0x2d>
mov    -0x8(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1238 <clean_dir+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11dc <clean_dir+0x5c>
jmp    11ad <clean_dir+0x2d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1220 <clean_dir+0xa0>
mov    -0x18(%rbp),%rdi
call   1080 <is_imgtype@plt>
cmp    $0x0,%rax
je     1220 <clean_dir+0xa0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <unlink@plt>
jmp    1233 <clean_dir+0xb3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdd4(%rip),%rdi
call   1050 <printf@plt>
jmp    11ad <clean_dir+0x2d>
mov    -0x8(%rbp),%rdi
call   1070 <closedir@plt>
mov    $0x0,%al
call   10a0 <clean_index_dir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_dir>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe71(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     122b <clean_dir+0xab>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1211 <clean_dir+0x91>
mov    %rax,%rbx
lea    0xe4b(%rip),%r14
jmp    11db <clean_dir+0x5b>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1211 <clean_dir+0x91>
mov    (%rbx),%r12
cmpb   $0x2e,(%r12)
je     11cb <clean_dir+0x4b>
mov    %r12,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11c0 <clean_dir+0x40>
mov    %rax,%rdi
call   1080 <is_imgtype@plt>
mov    (%rbx),%r12
test   %rax,%rax
je     11c0 <clean_dir+0x40>
mov    %r12,%rdi
call   1030 <unlink@plt>
jmp    11cb <clean_dir+0x4b>
mov    %r15,%rdi
call   1070 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    10a0 <clean_index_dir@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"Warning: %s\0A\00"
define void @clean_dir() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca i8*
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
br label %47
8: ; preds = %0
br label %9
9: ; preds = %42, %20, %8
%10 = load i32*, i32** %1
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %2
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %43
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %2
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 46
br i1 %19, label %20, label %21
20: ; preds = %13
br label %9
21: ; preds = %13
%22 = load %struct.dirent*, %struct.dirent** %2
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i8* @strrchr(i8* %24, i8 signext 46)
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %37
28: ; preds = %21
%29 = load i8*, i8** %3
%30 = call i64 @is_imgtype(i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load %struct.dirent*, %struct.dirent** %2
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i32 @unlink(i8* %35)
br label %42
37: ; preds = %28, %21
%38 = load %struct.dirent*, %struct.dirent** %2
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %37, %32
br label %9
43: ; preds = %9
%44 = load i32*, i32** %1
%45 = call i32 @closedir(i32* %44)
%46 = call i32 (...) @clean_index_dir()
br label %47
47: ; preds = %43, %7
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"Warning: %s\0A\00"
define void @clean_dir() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %30, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %27, label %6
6: ; preds = %3, %24
%7 = phi %struct.dirent* [ %25, %24 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %24, label %12
12: ; preds = %6
%13 = tail call i8* @strrchr(i8* %9, i8 signext 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i64 @is_imgtype(i8* %13)
%17 = icmp eq i64 %16, 0
%18 = load i8*, i8** %8
br i1 %17, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @unlink(i8* %18)
br label %24
21: ; preds = %15, %12
%22 = phi i8* [ %9, %12 ], [ %18, %15 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %21, %6
%25 = tail call %struct.dirent* @readdir(i32* %1)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %27, label %6
27: ; preds = %24, %3
%28 = tail call i32 @closedir(i32* %1)
%29 = tail call i32 (...) @clean_index_dir()
br label %30
30: ; preds = %0, %27
ret void
}