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

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ addFile(struct windowlist **, char *, struct stat);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileExistsInList(struct windowlist *, char *);
int /*<<< orphan*/ free(struct stat *);
struct stat *malloc(int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
char *realloc(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int stat(char *, struct stat *);
char *strdup(char *);
int strlen(char *);
void findAllFiles(struct windowlist **list, char *path) {
  DIR *dp;
  int st;
  char *fullname;
  struct stat *statbuf;
  struct dirent *dir;
  fullname = strdup(path);
  if (!fullname)
    return;
  statbuf = malloc(sizeof(struct stat));
  if (!statbuf)
    return;
  dp = opendir(path);
  while ((dir = readdir(dp)) != NULL) {
    fullname = realloc(fullname,
                       sizeof(char) * (strlen(path) + strlen(dir->d_name) + 2));
    if (!fullname)
      return;
    sprintf(fullname + strlen(path), "/%s", dir->d_name);
    st = stat(fullname, statbuf);
    if (!st && S_ISREG(statbuf->st_mode) && !fileExistsInList(*list, fullname))
      addFile(list, fullname, *statbuf);
  }
  closedir(dp);
  free(statbuf);
}


x86 assembly (clang, -O0):
<findAllFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11fd <findAllFiles+0x2d>
jmp    132d <findAllFiles+0x15d>
mov    $0x4,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    121b <findAllFiles+0x4b>
jmp    132d <findAllFiles+0x15d>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     131b <findAllFiles+0x14b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   10c0 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    128e <findAllFiles+0xbe>
jmp    132d <findAllFiles+0x15d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
lea    0xd4a(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1316 <findAllFiles+0x146>
mov    -0x30(%rbp),%rax
mov    (%rax),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1316 <findAllFiles+0x146>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <fileExistsInList@plt>
cmp    $0x0,%eax
jne    1316 <findAllFiles+0x146>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10d0 <addFile@plt>
jmp    1228 <findAllFiles+0x58>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findAllFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,(%rsp)
mov    %rsi,%rdi
call   10f0 <strdup@plt>
test   %rax,%rax
je     12d2 <findAllFiles+0x102>
mov    %rax,%rbx
mov    $0x4,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     12d2 <findAllFiles+0x102>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <opendir@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12e1 <findAllFiles+0x111>
mov    %rax,%r14
jmp    1244 <findAllFiles+0x74>
nopl   (%rax)
mov    %r13,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     12e1 <findAllFiles+0x111>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    (%r14),%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%esi
add    $0x2,%esi
mov    %rbx,%rdi
call   10c0 <realloc@plt>
test   %rax,%rax
je     12d2 <findAllFiles+0x102>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    (%r14),%rdx
lea    0xd7c(%rip),%rsi
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <stat@plt>
test   %eax,%eax
jne    1230 <findAllFiles+0x60>
mov    (%r12),%ebp
mov    %ebp,%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     1230 <findAllFiles+0x60>
mov    (%rsp),%rax
mov    (%rax),%rdi
mov    %rbx,%rsi
call   1060 <fileExistsInList@plt>
test   %eax,%eax
jne    1230 <findAllFiles+0x60>
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   10d0 <addFile@plt>
jmp    1230 <findAllFiles+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
call   1070 <closedir@plt>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.windowlist = type { i32 }
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [4 x i8] c"/%s\00"
define void @findAllFiles(%struct.windowlist** %0, i8* %1) {
%3 = alloca %struct.windowlist**
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.stat*
%9 = alloca %struct.dirent*
store %struct.windowlist** %0, %struct.windowlist*** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
br label %84
15: ; preds = %2
%16 = call %struct.stat* @malloc(i32 4)
store %struct.stat* %16, %struct.stat** %8
%17 = load %struct.stat*, %struct.stat** %8
%18 = icmp ne %struct.stat* %17, null
br i1 %18, label %20, label %19
19: ; preds = %15
br label %84
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = call i32* @opendir(i8* %21)
store i32* %22, i32** %5
br label %23
23: ; preds = %78, %20
%24 = load i32*, i32** %5
%25 = call %struct.dirent* @readdir(i32* %24)
store %struct.dirent* %25, %struct.dirent** %9
%26 = icmp ne %struct.dirent* %25, null
br i1 %26, label %27, label %79
27: ; preds = %23
%28 = load i8*, i8** %7
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
%31 = load %struct.dirent*, %struct.dirent** %9
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %30, %34
%36 = add nsw i32 %35, 2
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i8* @realloc(i8* %28, i32 %39)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = icmp ne i8* %41, null
br i1 %42, label %44, label %43
43: ; preds = %27
br label %84
44: ; preds = %27
%45 = load i8*, i8** %7
%46 = load i8*, i8** %4
%47 = call i32 @strlen(i8* %46)
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
%50 = load %struct.dirent*, %struct.dirent** %9
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %7
%55 = load %struct.stat*, %struct.stat** %8
%56 = call i32 @stat(i8* %54, %struct.stat* %55)
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = icmp ne i32 %57, 0
br i1 %58, label %78, label %59
59: ; preds = %44
%60 = load %struct.stat*, %struct.stat** %8
%61 = getelementptr inbounds %struct.stat, %struct.stat* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i64 @S_ISREG(i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %78
65: ; preds = %59
%66 = load %struct.windowlist**, %struct.windowlist*** %3
%67 = load %struct.windowlist*, %struct.windowlist** %66
%68 = load i8*, i8** %7
%69 = call i32 @fileExistsInList(%struct.windowlist* %67, i8* %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %78, label %71
71: ; preds = %65
%72 = load %struct.windowlist**, %struct.windowlist*** %3
%73 = load i8*, i8** %7
%74 = load %struct.stat*, %struct.stat** %8
%75 = getelementptr inbounds %struct.stat, %struct.stat* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i32 @addFile(%struct.windowlist** %72, i8* %73, i32 %76)
br label %78
78: ; preds = %71, %65, %59, %44
br label %23
79: ; preds = %23
%80 = load i32*, i32** %5
%81 = call i32 @closedir(i32* %80)
%82 = load %struct.stat*, %struct.stat** %8
%83 = call i32 @free(%struct.stat* %82)
br label %84
84: ; preds = %79, %43, %19, %14
ret void
}

LLVM IR (-O2):
%struct.windowlist = type { i32 }
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [4 x i8] c"/%s\00"
define void @findAllFiles(%struct.windowlist** %0, i8* %1) {
%3 = tail call i8* @strdup(i8* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %49, label %5
5: ; preds = %2
%6 = tail call %struct.stat* @malloc(i32 4)
%7 = icmp eq %struct.stat* %6, null
br i1 %7, label %49, label %8
8: ; preds = %5
%9 = tail call i32* @opendir(i8* %1)
%10 = tail call %struct.dirent* @readdir(i32* %9)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %46, label %12
12: ; preds = %8
%13 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
br label %14
14: ; preds = %12, %43
%15 = phi %struct.dirent* [ %10, %12 ], [ %44, %43 ]
%16 = phi i8* [ %3, %12 ], [ %23, %43 ]
%17 = tail call i32 @strlen(i8* %1)
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = tail call i32 @strlen(i8* %19)
%21 = add i32 %17, 2
%22 = add i32 %21, %20
%23 = tail call i8* @realloc(i8* %16, i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %49, label %25
25: ; preds = %14
%26 = tail call i32 @strlen(i8* %1)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
%29 = load i8*, i8** %18
%30 = tail call i32 @sprintf(i8* %28, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = tail call i32 @stat(i8* %23, %struct.stat* %6)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %25
%34 = load i32, i32* %13
%35 = tail call i64 @S_ISREG(i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %33
%38 = load %struct.windowlist*, %struct.windowlist** %0
%39 = tail call i32 @fileExistsInList(%struct.windowlist* %38, i8* %23)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = tail call i32 @addFile(%struct.windowlist** %0, i8* %23, i32 %34)
br label %43
43: ; preds = %41, %37, %33, %25
%44 = tail call %struct.dirent* @readdir(i32* %9)
%45 = icmp eq %struct.dirent* %44, null
br i1 %45, label %46, label %14
46: ; preds = %43, %8
%47 = tail call i32 @closedir(i32* %9)
%48 = tail call i32 @free(%struct.stat* %6)
br label %49
49: ; preds = %14, %5, %2, %46
ret void
}