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

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ closedir(int /*<<< orphan*/ *);
scalar_t__ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(scalar_t__, char *);
scalar_t__ strlen(char *);
scalar_t__ strstr(scalar_t__, char *);
int main(int argc, char **argv) {
  struct stat statbuf;
  struct dirent *dirp;
  DIR *dp;
  int len;
  if (argc != 2) {
    printf("Usage: %s <path to xml files>\n", argv[0]);
    return -1;
  }
  if (lstat(argv[1], &statbuf) < 0) {
    printf("Unable to stat %s\n", argv[1]);
    return -1;
  }
  if (S_ISDIR(statbuf.st_mode) == 0) {
    printf("%s not a directory\n", argv[1]);
    return -1;
  }
  if ((dp = opendir(argv[1])) == NULL) {
    printf("Unable to read directory\n");
    return -1;
  }
  while ((dirp = readdir(dp)) != NULL) {
    if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0 ||
        strcmp(dirp->d_name, "server_config.xml") == 0 ||
        strstr(dirp->d_name, "server_") != dirp->d_name)
      continue;
    if (strstr(dirp->d_name, ".xml") !=
        dirp->d_name + strlen(dirp->d_name) - strlen(".xml"))
      continue;
    printf("%s\n", dirp->d_name);
  }
  if (closedir(dp) < 0) {
    printf("Unable to close directory\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c1 <main+0x231>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <lstat@plt>
cmp    $0x0,%rax
jge    120e <main+0x7e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c1 <main+0x231>
mov    -0x18(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    1242 <main+0xb2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c1 <main+0x231>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1277 <main+0xe7>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c1 <main+0x231>
jmp    127c <main+0xec>
mov    -0x28(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     138d <main+0x1fd>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xdc0(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     130a <main+0x17a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xda2(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     130a <main+0x17a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd88(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     130a <main+0x17a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd7d(%rip),%rsi
call   10b0 <strstr@plt>
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%rax
je     130f <main+0x17f>
jmp    127c <main+0xec>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd53(%rip),%rsi
call   10b0 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
lea    0xd1e(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rcx
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
sub    %rdx,%rcx
cmp    %rcx,%rax
je     1373 <main+0x1e3>
jmp    127c <main+0xec>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xcad(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    127c <main+0xec>
mov    -0x28(%rbp),%rdi
call   1070 <closedir@plt>
cmp    $0x0,%rax
jge    13ba <main+0x22a>
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c1 <main+0x231>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    12e6 <main+0x146>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
call   1090 <lstat@plt>
test   %rax,%rax
js     12f2 <main+0x152>
mov    (%rsp),%edi
call   1070 <S_ISDIR@plt>
mov    0x8(%rbx),%rsi
test   %rax,%rax
je     131a <main+0x17a>
mov    %rsi,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     133c <main+0x19c>
mov    %rax,%r14
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     12ff <main+0x15f>
mov    %rax,%rbp
lea    0xe37(%rip),%rbx
lea    0xe2f(%rip),%r15
lea    0xe2b(%rip),%r12
lea    0xe36(%rip),%r13
jmp    1244 <main+0xa4>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12ff <main+0x15f>
mov    0x0(%rbp),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1230 <main+0x90>
mov    0x0(%rbp),%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1230 <main+0x90>
mov    0x0(%rbp),%rdi
mov    %r12,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1230 <main+0x90>
mov    0x0(%rbp),%rdi
mov    %r13,%rsi
call   10c0 <strstr@plt>
cmp    0x0(%rbp),%rax
jne    1230 <main+0x90>
mov    %rax,%rdi
lea    0xdc3(%rip),%rsi
call   10c0 <strstr@plt>
mov    %r15,%rbx
mov    %r12,%r15
mov    %r13,%r12
mov    %rax,%r13
mov    0x0(%rbp),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
add    %rbp,%rax
add    $0xfffffffffffffffc,%rax
cmp    %rax,%r13
mov    %r12,%r13
mov    %r15,%r12
mov    %rbx,%r15
lea    0xd7d(%rip),%rbx
jne    1230 <main+0x90>
lea    0xd57(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1230 <main+0x90>
mov    (%rbx),%rsi
lea    0xd10(%rip),%rdi
jmp    1321 <main+0x181>
mov    0x8(%rbx),%rsi
lea    0xd22(%rip),%rdi
jmp    1321 <main+0x181>
mov    %r14,%rdi
call   1080 <closedir@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    132d <main+0x18d>
lea    0xd4b(%rip),%rdi
jmp    1343 <main+0x1a3>
lea    0xd11(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3a(%rip),%rdi
call   1030 <puts@plt>
jmp    1328 <main+0x188>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i64 }
@.str = [31 x i8] c"Usage: %s <path to xml files>\0A\00"
@.str.1 = [19 x i8] c"Unable to stat %s\0A\00"
@.str.2 = [20 x i8] c"%s not a directory\0A\00"
@.str.3 = [26 x i8] c"Unable to read directory\0A\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [18 x i8] c"server_config.xml\00"
@.str.7 = [8 x i8] c"server_\00"
@.str.8 = [5 x i8] c".xml\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@.str.10 = [27 x i8] c"Unable to close directory\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca %struct.dirent*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %109
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @lstat(i8* %20, %struct.stat* %6)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -1, i32* %3
br label %109
28: ; preds = %17
%29 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @S_ISDIR(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %36)
store i32 -1, i32* %3
br label %109
38: ; preds = %28
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = call i32* @opendir(i8* %41)
store i32* %42, i32** %8
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %46
44: ; preds = %38
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %109
46: ; preds = %38
br label %47
47: ; preds = %97, %96, %78, %46
%48 = load i32*, i32** %8
%49 = call %struct.dirent* @readdir(i32* %48)
store %struct.dirent* %49, %struct.dirent** %7
%50 = icmp ne %struct.dirent* %49, null
br i1 %50, label %51, label %102
51: ; preds = %47
%52 = load %struct.dirent*, %struct.dirent** %7
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i64, i64* %53
%55 = call i64 @strcmp(i64 %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %78, label %57
57: ; preds = %51
%58 = load %struct.dirent*, %struct.dirent** %7
%59 = getelementptr inbounds %struct.dirent, %struct.dirent* %58, i32 0, i32 0
%60 = load i64, i64* %59
%61 = call i64 @strcmp(i64 %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %78, label %63
63: ; preds = %57
%64 = load %struct.dirent*, %struct.dirent** %7
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i64, i64* %65
%67 = call i64 @strcmp(i64 %66, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%68 = icmp eq i64 %67, 0
br i1 %68, label %78, label %69
69: ; preds = %63
%70 = load %struct.dirent*, %struct.dirent** %7
%71 = getelementptr inbounds %struct.dirent, %struct.dirent* %70, i32 0, i32 0
%72 = load i64, i64* %71
%73 = call i64 @strstr(i64 %72, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%74 = load %struct.dirent*, %struct.dirent** %7
%75 = getelementptr inbounds %struct.dirent, %struct.dirent* %74, i32 0, i32 0
%76 = load i64, i64* %75
%77 = icmp ne i64 %73, %76
br i1 %77, label %78, label %79
78: ; preds = %69, %63, %57, %51
br label %47
79: ; preds = %69
%80 = load %struct.dirent*, %struct.dirent** %7
%81 = getelementptr inbounds %struct.dirent, %struct.dirent* %80, i32 0, i32 0
%82 = load i64, i64* %81
%83 = call i64 @strstr(i64 %82, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%84 = load %struct.dirent*, %struct.dirent** %7
%85 = getelementptr inbounds %struct.dirent, %struct.dirent* %84, i32 0, i32 0
%86 = load i64, i64* %85
%87 = load %struct.dirent*, %struct.dirent** %7
%88 = getelementptr inbounds %struct.dirent, %struct.dirent* %87, i32 0, i32 0
%89 = load i64, i64* %88
%90 = inttoptr i64 %89 to i8*
%91 = call i64 @strlen(i8* %90)
%92 = add nsw i64 %86, %91
%93 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%94 = sub nsw i64 %92, %93
%95 = icmp ne i64 %83, %94
br i1 %95, label %96, label %97
96: ; preds = %79
br label %47
97: ; preds = %79
%98 = load %struct.dirent*, %struct.dirent** %7
%99 = getelementptr inbounds %struct.dirent, %struct.dirent* %98, i32 0, i32 0
%100 = load i64, i64* %99
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i64 %100)
br label %47
102: ; preds = %47
%103 = load i32*, i32** %8
%104 = call i64 @closedir(i32* %103)
%105 = icmp slt i64 %104, 0
br i1 %105, label %106, label %108
106: ; preds = %102
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %3
br label %109
108: ; preds = %102
store i32 0, i32* %3
br label %109
109: ; preds = %108, %106, %44, %33, %23, %12
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i64 }
@.str = [31 x i8] c"Usage: %s <path to xml files>\0A\00"
@.str.1 = [19 x i8] c"Unable to stat %s\0A\00"
@.str.2 = [20 x i8] c"%s not a directory\0A\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [18 x i8] c"server_config.xml\00"
@.str.7 = [8 x i8] c"server_\00"
@.str.8 = [5 x i8] c".xml\00"
@.str.9 = [4 x i8] c"%s\0A\00"
@str = [26 x i8] c"Unable to close directory\00"
@str.11 = [25 x i8] c"Unable to read directory\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %70
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i64 @lstat(i8* %11, %struct.stat* %3)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %70
17: ; preds = %9
%18 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%19 = load i32, i32* %18
%20 = tail call i64 @S_ISDIR(i32 %19)
%21 = icmp eq i64 %20, 0
%22 = load i8*, i8** %10
br i1 %21, label %23, label %25
23: ; preds = %17
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %70
25: ; preds = %17
%26 = tail call i32* @opendir(i8* %22)
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = tail call %struct.dirent* @readdir(i32* %26)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %65, label %33
31: ; preds = %25
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.11, i64 0, i64 0))
br label %70
33: ; preds = %28, %52
%34 = phi %struct.dirent* [ %53, %52 ], [ %29, %28 ]
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i64 0, i32 0
%36 = load i64, i64* %35
%37 = tail call i64 @strcmp(i64 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %52, label %39
39: ; preds = %33
%40 = load i64, i64* %35
%41 = tail call i64 @strcmp(i64 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39
%44 = load i64, i64* %35
%45 = tail call i64 @strcmp(i64 %44, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %43
%48 = load i64, i64* %35
%49 = tail call i64 @strstr(i64 %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%50 = load i64, i64* %35
%51 = icmp eq i64 %49, %50
br i1 %51, label %55, label %52
52: ; preds = %33, %39, %43, %47, %63, %55
%53 = tail call %struct.dirent* @readdir(i32* %26)
%54 = icmp eq %struct.dirent* %53, null
br i1 %54, label %65, label %33
55: ; preds = %47
%56 = tail call i64 @strstr(i64 %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%57 = load i64, i64* %35
%58 = inttoptr i64 %57 to i8*
%59 = tail call i64 @strlen(i8* dereferenceable(1) %58)
%60 = add i64 %57, -4
%61 = add i64 %60, %59
%62 = icmp eq i64 %56, %61
br i1 %62, label %63, label %52
63: ; preds = %55
%64 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i64 %57)
br label %52
65: ; preds = %52, %28
%66 = tail call i64 @closedir(i32* %26)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %65
%69 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %70
70: ; preds = %65, %68, %31, %23, %14, %6
%71 = phi i32 [ -1, %6 ], [ -1, %14 ], [ -1, %23 ], [ -1, %31 ], [ -1, %68 ], [ 0, %65 ]
ret i32 %71
}