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

/* Variables and functions */
int /*<<< orphan*/ ConvertFile(char *);
int /*<<< orphan*/ LogMessage(char *, char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ *strstr(char *, char *);
int time(int /*<<< orphan*/);
void *FTPLoop(void *some_void_ptr) {
  while (1) {
    DIR *dp;
    struct dirent *ep;
    struct stat st;
    char *SSDVFolder;
    char FileName[100], TempName[100];
    SSDVFolder = "/tmp";
    dp = opendir(SSDVFolder);
    if (dp != NULL) {
      while (ep = readdir(dp)) {
        if (strstr(ep->d_name, ".bin") != NULL) {
          sprintf(FileName, "%s/%s", SSDVFolder, ep->d_name);
          stat(FileName, &st);
          if ((time(0) - st.st_mtime) < 20) {
            ConvertFile(ep->d_name);
          } else if ((time(0) - st.st_mtime) > 120) {
            sprintf(TempName, "%s/%s", SSDVFolder, ep->d_name);
            LogMessage("Removing %s\n", TempName);
            remove(TempName);
          }
        }
      }
    }
    (void)closedir(dp);
    sleep(5);
  }
}


x86 assembly (clang, -O0):
<FTPLoop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe3a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12d1 <FTPLoop+0x121>
jmp    11e7 <FTPLoop+0x37>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12cc <FTPLoop+0x11c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdf9(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12c7 <FTPLoop+0x117>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xdd6(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
xor    %edi,%edi
call   1070 <time@plt>
sub    -0x20(%rbp),%eax
cmp    $0x14,%eax
jge    126d <FTPLoop+0xbd>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <ConvertFile@plt>
jmp    12c2 <FTPLoop+0x112>
xor    %edi,%edi
call   1070 <time@plt>
sub    -0x20(%rbp),%eax
cmp    $0x78,%eax
jle    12bd <FTPLoop+0x10d>
lea    -0x100(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xd71(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x100(%rbp),%rsi
lea    0xd64(%rip),%rdi
call   1090 <LogMessage@plt>
lea    -0x100(%rbp),%rdi
call   1030 <remove@plt>
jmp    12c2 <FTPLoop+0x112>
jmp    12c7 <FTPLoop+0x117>
jmp    11e7 <FTPLoop+0x37>
jmp    12d1 <FTPLoop+0x121>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
jmp    11bf <FTPLoop+0xf>

x86 assembly (clang, -O2):
<FTPLoop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
lea    0xe3d(%rip),%r12
lea    0x80(%rsp),%r14
jmp    11f2 <FTPLoop+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <closedir@plt>
mov    $0x5,%edi
call   10c0 <sleep@plt>
lea    0xe07(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11e0 <FTPLoop+0x30>
mov    %rbp,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11e0 <FTPLoop+0x30>
mov    %rax,%r13
jmp    1239 <FTPLoop+0x89>
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13),%rdi
call   10a0 <ConvertFile@plt>
mov    %rbp,%rdi
call   1080 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     11e0 <FTPLoop+0x30>
mov    0x0(%r13),%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1229 <FTPLoop+0x79>
mov    %r14,%rdi
lea    0xdb3(%rip),%rsi
lea    0xda2(%rip),%rdx
mov    %r15,%rcx
call   10b0 <sprintf@plt>
mov    %r14,%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    0x8(%rsp),%ebx
sub    %ebx,%eax
cmp    $0x13,%eax
jle    1220 <FTPLoop+0x70>
xor    %edi,%edi
call   1070 <time@plt>
sub    %ebx,%eax
cmp    $0x79,%eax
jl     1229 <FTPLoop+0x79>
mov    0x0(%r13),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd64(%rip),%rsi
lea    0xd53(%rip),%rdx
call   10b0 <sprintf@plt>
lea    0xd57(%rip),%rdi
mov    %rbx,%rsi
call   1090 <LogMessage@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
jmp    1229 <FTPLoop+0x79>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@.str = [5 x i8] c"/tmp\00"
@.str.1 = [5 x i8] c".bin\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [13 x i8] c"Removing %s\0A\00"
define i8* @FTPLoop(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
store i8* %0, i8** %2
br label %9
9: ; preds = %1, %65
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %6
%10 = load i8*, i8** %6
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %65
14: ; preds = %9
br label %15
15: ; preds = %63, %14
%16 = load i32*, i32** %3
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %4
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %64
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %4
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32* @strstr(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %63
25: ; preds = %19
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = load %struct.dirent*, %struct.dirent** %4
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %30)
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%33 = call i32 @stat(i8* %32, %struct.stat* %5)
%34 = call i32 @time(i32 0)
%35 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%36 = load i32, i32* %35
%37 = sub nsw i32 %34, %36
%38 = icmp slt i32 %37, 20
br i1 %38, label %39, label %44
39: ; preds = %25
%40 = load %struct.dirent*, %struct.dirent** %4
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i32 @ConvertFile(i8* %42)
br label %62
44: ; preds = %25
%45 = call i32 @time(i32 0)
%46 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%47 = load i32, i32* %46
%48 = sub nsw i32 %45, %47
%49 = icmp sgt i32 %48, 120
br i1 %49, label %50, label %61
50: ; preds = %44
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%52 = load i8*, i8** %6
%53 = load %struct.dirent*, %struct.dirent** %4
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %52, i8* %55)
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%58 = call i32 @LogMessage(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%60 = call i32 @remove(i8* %59)
br label %61
61: ; preds = %50, %44
br label %62
62: ; preds = %61, %39
br label %63
63: ; preds = %62, %19
br label %15
64: ; preds = %15
br label %65
65: ; preds = %64, %9
%66 = load i32*, i32** %3
%67 = call i32 @closedir(i32* %66)
%68 = call i32 @sleep(i32 5)
br label %9
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [5 x i8] c"/tmp\00"
@.str.1 = [5 x i8] c".bin\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [13 x i8] c"Removing %s\0A\00"
define noalias i8* @FTPLoop(i8* nocapture readnone %0) {
%2 = alloca %struct.stat
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = bitcast %struct.stat* %2 to i8*
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %9
9: ; preds = %1, %43
%10 = call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %43, label %12
12: ; preds = %9
%13 = call %struct.dirent* @readdir(i32* %10)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %43, label %15
15: ; preds = %12, %40
%16 = phi %struct.dirent* [ %41, %40 ], [ %13, %12 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = call i32* @strstr(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %40, label %21
21: ; preds = %15
%22 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %18)
%23 = call i32 @stat(i8* %6, %struct.stat* %2)
%24 = call i32 @time(i32 0)
%25 = load i32, i32* %8
%26 = sub nsw i32 %24, %25
%27 = icmp slt i32 %26, 20
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i8*, i8** %17
%30 = call i32 @ConvertFile(i8* %29)
br label %40
31: ; preds = %21
%32 = call i32 @time(i32 0)
%33 = sub nsw i32 %32, %25
%34 = icmp sgt i32 %33, 120
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load i8*, i8** %17
%37 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = call i32 @LogMessage(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%39 = call i32 @remove(i8* %7)
br label %40
40: ; preds = %28, %35, %31, %15
%41 = call %struct.dirent* @readdir(i32* %10)
%42 = icmp eq %struct.dirent* %41, null
br i1 %42, label %43, label %15
43: ; preds = %40, %12, %9
%44 = call i32 @closedir(i32* %10)
%45 = call i32 @sleep(i32 5)
br label %9
}