#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*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ unlink(char *);
int do_clean() {
  DIR *dir;
  struct dirent *de;
  remove("mklibnow.bat");
  dir = opendir("lgcctmp");
  if (!dir)
    return 0;
  while ((de = readdir(dir))) {
    char buf[30];
    if (de->d_name[0] == '.')
      continue;
    sprintf(buf, "lgcctmp/%s", de->d_name);
    unlink(buf);
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<do_clean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe91(%rip),%rdi
call   1040 <remove@plt>
lea    0xe92(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <do_clean+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    1204 <do_clean+0xa4>
jmp    11a0 <do_clean+0x40>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11f4 <do_clean+0x94>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11cf <do_clean+0x6f>
jmp    11a0 <do_clean+0x40>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xe34(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <unlink@plt>
jmp    11a0 <do_clean+0x40>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_clean>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe90(%rip),%rdi
call   1040 <remove@plt>
lea    0xe91(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     11e2 <do_clean+0x82>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11da <do_clean+0x7a>
lea    0xe78(%rip),%r14
mov    %rsp,%r15
jmp    11bd <do_clean+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11da <do_clean+0x7a>
mov    (%rax),%rdx
cmpb   $0x2e,(%rdx)
je     11b0 <do_clean+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <sprintf@plt>
mov    %r15,%rdi
call   1030 <unlink@plt>
jmp    11b0 <do_clean+0x50>
mov    %rbx,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [13 x i8] c"mklibnow.bat\00"
@.str.1 = [8 x i8] c"lgcctmp\00"
@.str.2 = [11 x i8] c"lgcctmp/%s\00"
define i32 @do_clean() {
%1 = alloca [30 x i8]
%2 = tail call i32 @remove(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %24, label %5
5: ; preds = %0
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
br label %10
10: ; preds = %8, %19
%11 = phi %struct.dirent* [ %6, %8 ], [ %20, %19 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 46
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%18 = call i32 @unlink(i8* %9)
br label %19
19: ; preds = %10, %16
%20 = tail call %struct.dirent* @readdir(i32* %3)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %10
22: ; preds = %19, %5
%23 = tail call i32 @closedir(i32* %3)
br label %24
24: ; preds = %0, %22
ret i32 0
}