#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ *opendir(char *);
int optopt;
scalar_t__ pedigree_module_is_loaded(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ stricmp(char *, char *);
char *strrchr(char *, char);
int main(int argc, char **argv) {
  int listAll = 0, listLoaded = 0, listUnloaded = 0, c = 0, err = 0;
  while ((c = getopt(argc, argv, "aluh")) != -1) {
    switch (c) {
    case 'a':
      if (listLoaded || listUnloaded)
        err = 1;
      else
        listAll = 1;
      break;
    case 'l':
      if (listAll || listUnloaded)
        err = 1;
      else
        listLoaded = 1;
      break;
    case 'u':
      if (listAll || listLoaded)
        err = 1;
      else
        listUnloaded = 1;
      break;
    case 'h':
      fprintf(stderr, "usage: modlist [-a] [-l] [-u]\n");
      fprintf(stderr, "-a%-16slist all modules and show their status\n", "");
      fprintf(stderr, "-l%-16slist all already-loaded modules\n", "");
      fprintf(stderr, "-u%-16slist all modules that are not loaded\n", "");
      fprintf(stderr, "-h%-16sshow this usage information\n", "");
      fprintf(stderr, "\n");
      fprintf(stderr, "modlist without arguments defaults to listing all "
                      "modules with their status\n");
      err = 3;
      break;
    default:
      fprintf(stderr, "Unrecognized option: -%c\n", optopt);
      err = 2;
    }
  }
  if (!listAll && !listLoaded && !listUnloaded)
    listAll = 1;
  if (err) {
    if (err == 1)
      fprintf(stderr, "Only one action (-a, -l, or -u) can be specified\n");
    else if (err == 3)
      return 0;
    return err;
  }
  DIR *dp = opendir("root»/system/modules");
  if (!dp) {
    printf("Couldn't open the directory %s: %s.\n", "root»/system/modules",
           strerror(errno));
    return -1;
  }
  struct dirent *ep;
  while ((ep = readdir(dp))) {
    char *filename = ep->d_name;
    char *lastPeriod = strrchr(filename, '.');
    char *suffix = lastPeriod + 1;
    if (lastPeriod && !stricmp(suffix, "o")) {
      *lastPeriod = '\0';
      if (listAll) {
        printf("%-32s%s\n", filename,
               pedigree_module_is_loaded(filename) ? "[loaded]" : "");
      } else if (listLoaded) {
        if (pedigree_module_is_loaded(filename)) {
          printf("%s\n", filename);
        }
      } else if (listUnloaded) {
        if (!pedigree_module_is_loaded(filename)) {
          printf("%s\n", filename);
        }
      }
    }
  }
  closedir(dp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6d(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     139a <main+0x1fa>
mov    -0x20(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0x14,%eax
ja     136e <main+0x1ce>
mov    -0x58(%rbp),%rax
lea    0xde8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,-0x18(%rbp)
jne    1235 <main+0x95>
cmpl   $0x0,-0x1c(%rbp)
je     1241 <main+0xa1>
movl   $0x1,-0x24(%rbp)
jmp    1248 <main+0xa8>
movl   $0x1,-0x14(%rbp)
jmp    1395 <main+0x1f5>
cmpl   $0x0,-0x14(%rbp)
jne    1261 <main+0xc1>
cmpl   $0x0,-0x1c(%rbp)
je     126d <main+0xcd>
movl   $0x1,-0x24(%rbp)
jmp    1274 <main+0xd4>
movl   $0x1,-0x18(%rbp)
jmp    1395 <main+0x1f5>
cmpl   $0x0,-0x14(%rbp)
jne    128d <main+0xed>
cmpl   $0x0,-0x18(%rbp)
je     1299 <main+0xf9>
movl   $0x1,-0x24(%rbp)
jmp    12a0 <main+0x100>
movl   $0x1,-0x1c(%rbp)
jmp    1395 <main+0x1f5>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
lea    0xf20(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
lea    0xf02(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
lea    0xee4(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
lea    0xec6(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x3,-0x24(%rbp)
jmp    1395 <main+0x1f5>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
mov    0x2c6a(%rip),%rax
mov    (%rax),%edx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x2,-0x24(%rbp)
jmp    11d9 <main+0x39>
cmpl   $0x0,-0x14(%rbp)
jne    13bf <main+0x21f>
cmpl   $0x0,-0x18(%rbp)
jne    13bf <main+0x21f>
cmpl   $0x0,-0x1c(%rbp)
jne    13bf <main+0x21f>
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1415 <main+0x275>
cmpl   $0x1,-0x24(%rbp)
jne    13ef <main+0x24f>
mov    0x2bfe(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    140a <main+0x26a>
cmpl   $0x3,-0x24(%rbp)
jne    1405 <main+0x265>
movl   $0x0,-0x4(%rbp)
jmp    15a9 <main+0x409>
jmp    140a <main+0x26a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15a9 <main+0x409>
lea    0xd9d(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1462 <main+0x2c2>
mov    0x2b99(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %rax,%rdx
lea    0xd87(%rip),%rdi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15a9 <main+0x409>
jmp    1467 <main+0x2c7>
mov    -0x30(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1599 <main+0x3f9>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1594 <main+0x3f4>
mov    -0x50(%rbp),%rdi
lea    0xd37(%rip),%rsi
call   1030 <stricmp@plt>
cmp    $0x0,%eax
jne    1594 <main+0x3f4>
mov    -0x48(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x14(%rbp)
je     151d <main+0x37d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x40(%rbp),%rdi
call   1090 <pedigree_module_is_loaded@plt>
mov    -0x60(%rbp),%rsi
mov    %rax,%rcx
lea    0xcf8(%rip),%rdx
lea    0xcfd(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xce5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    158f <main+0x3ef>
cmpl   $0x0,-0x18(%rbp)
je     1551 <main+0x3b1>
mov    -0x40(%rbp),%rdi
call   1090 <pedigree_module_is_loaded@plt>
cmp    $0x0,%rax
je     154c <main+0x3ac>
mov    -0x40(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    158a <main+0x3ea>
cmpl   $0x0,-0x1c(%rbp)
je     1585 <main+0x3e5>
mov    -0x40(%rbp),%rdi
call   1090 <pedigree_module_is_loaded@plt>
cmp    $0x0,%rax
jne    1580 <main+0x3e0>
mov    -0x40(%rbp),%rsi
lea    0xc82(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1585 <main+0x3e5>
jmp    158a <main+0x3ea>
jmp    158f <main+0x3ef>
jmp    1594 <main+0x3f4>
jmp    1467 <main+0x2c7>
mov    -0x30(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x2e1e(%rip),%r12
lea    0xe3f(%rip),%r13
lea    0x102b(%rip),%r14
xor    %ebx,%ebx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x10(%rsp)
movl   $0x0,0x14(%rsp)
jmp    127f <main+0xdf>
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
lea    0xe5e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xe6b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xe85(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xe98(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xeb0(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xf91(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%edi
lea    0xead(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x3,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
lea    0xdc9(%rip),%rdx
call   10b0 <getopt@plt>
lea    -0x61(%rax),%ecx
cmp    $0x14,%ecx
ja     12e0 <main+0x140>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x10(%rsp),%edx
mov    %edx,%eax
mov    0xc(%rsp),%ecx
or     %ecx,%eax
mov    $0x1,%esi
cmovne %esi,%ebx
mov    $0x0,%eax
cmove  %eax,%ecx
mov    %ecx,0xc(%rsp)
cmove  %eax,%edx
mov    %edx,0x10(%rsp)
mov    0x14(%rsp),%eax
cmove  %esi,%eax
mov    %eax,0x14(%rsp)
jmp    127f <main+0xdf>
cs nopw 0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     137c <main+0x1dc>
mov    (%r12),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%edx
lea    0xe70(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%ebx
jmp    127f <main+0xdf>
mov    0x14(%rsp),%edx
mov    %edx,%eax
mov    0xc(%rsp),%ecx
or     %ecx,%eax
mov    $0x1,%edi
cmovne %edi,%ebx
mov    $0x0,%esi
cmove  %esi,%ecx
mov    %ecx,0xc(%rsp)
mov    0x10(%rsp),%eax
cmove  %edi,%eax
mov    %eax,0x10(%rsp)
cmove  %esi,%edx
mov    %edx,0x14(%rsp)
jmp    127f <main+0xdf>
mov    0x14(%rsp),%edx
mov    %edx,%eax
mov    0x10(%rsp),%ecx
or     %ecx,%eax
mov    $0x1,%esi
cmovne %esi,%ebx
mov    0xc(%rsp),%eax
cmove  %esi,%eax
mov    %eax,0xc(%rsp)
mov    $0x0,%eax
cmove  %eax,%ecx
mov    %ecx,0x10(%rsp)
cmove  %eax,%edx
mov    %edx,0x14(%rsp)
jmp    127f <main+0xdf>
mov    0x14(%rsp),%ebp
mov    %ebp,%eax
or     0x10(%rsp),%eax
or     0xc(%rsp),%eax
setne  %r13b
xor    %r15d,%r15d
test   %ebx,%ebx
je     13c1 <main+0x221>
cmp    $0x3,%ebx
je     14f0 <main+0x350>
cmp    $0x1,%ebx
jne    14b5 <main+0x315>
mov    (%r12),%edi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebx,%r15d
jmp    14f0 <main+0x350>
lea    0xdf1(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     14c4 <main+0x324>
mov    %rax,%rbx
mov    %r13b,0xb(%rsp)
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     14ba <main+0x31a>
test   %ebp,%ebp
sete   %cl
and    %cl,0xb(%rsp)
lea    0xe00(%rip),%rbp
jmp    143d <main+0x29d>
mov    %r12,%rdi
call   1090 <pedigree_module_is_loaded@plt>
test   %rax,%rax
mov    %rbp,%rdx
cmove  %r14,%rdx
lea    0xddc(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     14ba <main+0x31a>
mov    (%rax),%r12
mov    %r12,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1430 <main+0x290>
mov    %rax,%r13
lea    0x1(%rax),%rdi
lea    0xd94(%rip),%rsi
call   1030 <stricmp@plt>
test   %eax,%eax
jne    1430 <main+0x290>
movb   $0x0,0x0(%r13)
cmpb   $0x0,0xb(%rsp)
je     1401 <main+0x261>
cmpl   $0x0,0x10(%rsp)
je     148b <main+0x2eb>
mov    %r12,%rdi
call   1090 <pedigree_module_is_loaded@plt>
test   %rax,%rax
jne    149f <main+0x2ff>
jmp    1430 <main+0x290>
cmpl   $0x0,0xc(%rsp)
je     1430 <main+0x290>
mov    %r12,%rdi
call   1090 <pedigree_module_is_loaded@plt>
test   %rax,%rax
jne    1430 <main+0x290>
lea    0xd55(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1430 <main+0x290>
mov    %ebx,%r15d
jmp    14f0 <main+0x350>
mov    %rbx,%rdi
call   1070 <closedir@plt>
jmp    14f0 <main+0x350>
mov    0x2b05(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcf6(%rip),%rdi
lea    0xcd9(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"aluh\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"usage: modlist [-a] [-l] [-u]\0A\00"
@.str.2 = [47 x i8] c"-a%-16slist all modules and show their status\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [40 x i8] c"-l%-16slist all already-loaded modules\0A\00"
@.str.5 = [45 x i8] c"-u%-16slist all modules that are not loaded\0A\00"
@.str.6 = [36 x i8] c"-h%-16sshow this usage information\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [77 x i8] c"modlist without arguments defaults to listing all modules with their status\0A\00"
@.str.9 = [26 x i8] c"Unrecognized option: -%c\0A\00"
@optopt = global i32 0
@.str.10 = [50 x i8] c"Only one action (-a, -l, or -u) can be specified\0A\00"
@.str.11 = [22 x i8] c"root\C2\BB/system/modules\00"
@.str.12 = [37 x i8] c"Couldn't open the directory %s: %s.\0A\00"
@errno = global i32 0
@.str.13 = [2 x i8] c"o\00"
@.str.14 = [9 x i8] c"%-32s%s\0A\00"
@.str.15 = [9 x i8] c"[loaded]\00"
@.str.16 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca %struct.dirent*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
br label %16
16: ; preds = %69, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %9
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %70
21: ; preds = %16
%22 = load i32, i32* %9
switch i32 %22, label %65 [
i32 97, label %23
i32 108, label %32
i32 117, label %41
i32 104, label %50
]
23: ; preds = %21
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26, %23
store i32 1, i32* %10
br label %31
30: ; preds = %26
store i32 1, i32* %6
br label %31
31: ; preds = %30, %29
br label %69
32: ; preds = %21
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35, %32
store i32 1, i32* %10
br label %40
39: ; preds = %35
store i32 1, i32* %7
br label %40
40: ; preds = %39, %38
br label %69
41: ; preds = %21
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = load i32, i32* %7
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %44, %41
store i32 1, i32* %10
br label %49
48: ; preds = %44
store i32 1, i32* %8
br label %49
49: ; preds = %48, %47
br label %69
50: ; preds = %21
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* @stderr
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.8, i64 0, i64 0))
store i32 3, i32* %10
br label %69
65: ; preds = %21
%66 = load i32, i32* @stderr
%67 = load i32, i32* @optopt
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %67)
store i32 2, i32* %10
br label %69
69: ; preds = %65, %50, %49, %40, %31
br label %16
70: ; preds = %16
%71 = load i32, i32* %6
%72 = icmp ne i32 %71, 0
br i1 %72, label %80, label %73
73: ; preds = %70
%74 = load i32, i32* %7
%75 = icmp ne i32 %74, 0
br i1 %75, label %80, label %76
76: ; preds = %73
%77 = load i32, i32* %8
%78 = icmp ne i32 %77, 0
br i1 %78, label %80, label %79
79: ; preds = %76
store i32 1, i32* %6
br label %80
80: ; preds = %79, %76, %73, %70
%81 = load i32, i32* %10
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %96
83: ; preds = %80
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %89
86: ; preds = %83
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0))
br label %94
89: ; preds = %83
%90 = load i32, i32* %10
%91 = icmp eq i32 %90, 3
br i1 %91, label %92, label %93
92: ; preds = %89
store i32 0, i32* %3
br label %164
93: ; preds = %89
br label %94
94: ; preds = %93, %86
%95 = load i32, i32* %10
store i32 %95, i32* %3
br label %164
96: ; preds = %80
%97 = call i32* @opendir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
store i32* %97, i32** %11
%98 = load i32*, i32** %11
%99 = icmp ne i32* %98, null
br i1 %99, label %104, label %100
100: ; preds = %96
%101 = load i32, i32* @errno
%102 = call i8* @strerror(i32 %101)
%103 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %102)
store i32 -1, i32* %3
br label %164
104: ; preds = %96
br label %105
105: ; preds = %160, %104
%106 = load i32*, i32** %11
%107 = call %struct.dirent* @readdir(i32* %106)
store %struct.dirent* %107, %struct.dirent** %12
%108 = icmp ne %struct.dirent* %107, null
br i1 %108, label %109, label %161
109: ; preds = %105
%110 = load %struct.dirent*, %struct.dirent** %12
%111 = getelementptr inbounds %struct.dirent, %struct.dirent* %110, i32 0, i32 0
%112 = load i8*, i8** %111
store i8* %112, i8** %13
%113 = load i8*, i8** %13
%114 = call i8* @strrchr(i8* %113, i8 signext 46)
store i8* %114, i8** %14
%115 = load i8*, i8** %14
%116 = getelementptr inbounds i8, i8* %115, i64 1
store i8* %116, i8** %15
%117 = load i8*, i8** %14
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %160
119: ; preds = %109
%120 = load i8*, i8** %15
%121 = call i32 @stricmp(i8* %120, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%122 = icmp ne i32 %121, 0
br i1 %122, label %160, label %123
123: ; preds = %119
%124 = load i8*, i8** %14
store i8 0, i8* %124
%125 = load i32, i32* %6
%126 = icmp ne i32 %125, 0
br i1 %126, label %127, label %135
127: ; preds = %123
%128 = load i8*, i8** %13
%129 = load i8*, i8** %13
%130 = call i64 @pedigree_module_is_loaded(i8* %129)
%131 = icmp ne i64 %130, 0
%132 = zext i1 %131 to i64
%133 = select i1 %131, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%134 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0), i8* %128, i8* %133)
br label %159
135: ; preds = %123
%136 = load i32, i32* %7
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %146
138: ; preds = %135
%139 = load i8*, i8** %13
%140 = call i64 @pedigree_module_is_loaded(i8* %139)
%141 = icmp ne i64 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %138
%143 = load i8*, i8** %13
%144 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* %143)
br label %145
145: ; preds = %142, %138
br label %158
146: ; preds = %135
%147 = load i32, i32* %8
%148 = icmp ne i32 %147, 0
br i1 %148, label %149, label %157
149: ; preds = %146
%150 = load i8*, i8** %13
%151 = call i64 @pedigree_module_is_loaded(i8* %150)
%152 = icmp ne i64 %151, 0
br i1 %152, label %156, label %153
153: ; preds = %149
%154 = load i8*, i8** %13
%155 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* %154)
br label %156
156: ; preds = %153, %149
br label %157
157: ; preds = %156, %146
br label %158
158: ; preds = %157, %145
br label %159
159: ; preds = %158, %127
br label %160
160: ; preds = %159, %119, %109
br label %105
161: ; preds = %105
%162 = load i32*, i32** %11
%163 = call i32 @closedir(i32* %162)
store i32 0, i32* %3
br label %164
164: ; preds = %161, %100, %94, %92
%165 = load i32, i32* %3
ret i32 %165
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [5 x i8] c"aluh\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"usage: modlist [-a] [-l] [-u]\0A\00"
@.str.2 = [47 x i8] c"-a%-16slist all modules and show their status\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [40 x i8] c"-l%-16slist all already-loaded modules\0A\00"
@.str.5 = [45 x i8] c"-u%-16slist all modules that are not loaded\0A\00"
@.str.6 = [36 x i8] c"-h%-16sshow this usage information\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [77 x i8] c"modlist without arguments defaults to listing all modules with their status\0A\00"
@.str.9 = [26 x i8] c"Unrecognized option: -%c\0A\00"
@optopt = global i32 0
@.str.10 = [50 x i8] c"Only one action (-a, -l, or -u) can be specified\0A\00"
@.str.11 = [22 x i8] c"root\C2\BB/system/modules\00"
@.str.12 = [37 x i8] c"Couldn't open the directory %s: %s.\0A\00"
@errno = global i32 0
@.str.13 = [2 x i8] c"o\00"
@.str.14 = [9 x i8] c"%-32s%s\0A\00"
@.str.15 = [9 x i8] c"[loaded]\00"
@.str.16 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %19, %2
%4 = phi i32 [ 0, %2 ], [ %20, %19 ]
%5 = phi i32 [ 0, %2 ], [ %21, %19 ]
%6 = phi i32 [ 0, %2 ], [ %22, %19 ]
%7 = phi i32 [ 0, %2 ], [ %23, %19 ]
br label %8
8: ; preds = %59, %3
%9 = phi i32 [ %4, %3 ], [ %60, %59 ]
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %55 [
i32 -1, label %61
i32 97, label %11
i32 108, label %24
i32 117, label %32
i32 104, label %40
]
11: ; preds = %8
%12 = icmp ne i32 %6, 0
%13 = icmp ne i32 %5, 0
%14 = select i1 %12, i1 true, i1 %13
%15 = select i1 %14, i32 1, i32 %9
%16 = select i1 %14, i32 %5, i32 0
%17 = select i1 %14, i32 %6, i32 0
%18 = select i1 %14, i32 %7, i32 1
br label %19
19: ; preds = %11, %24, %32
%20 = phi i32 [ %36, %32 ], [ %28, %24 ], [ %15, %11 ]
%21 = phi i32 [ %37, %32 ], [ %29, %24 ], [ %16, %11 ]
%22 = phi i32 [ %38, %32 ], [ %30, %24 ], [ %17, %11 ]
%23 = phi i32 [ %39, %32 ], [ %31, %24 ], [ %18, %11 ]
br label %3
24: ; preds = %8
%25 = icmp ne i32 %7, 0
%26 = icmp ne i32 %5, 0
%27 = select i1 %25, i1 true, i1 %26
%28 = select i1 %27, i32 1, i32 %9
%29 = select i1 %27, i32 %5, i32 0
%30 = select i1 %27, i32 %6, i32 1
%31 = select i1 %27, i32 %7, i32 0
br label %19
32: ; preds = %8
%33 = icmp ne i32 %7, 0
%34 = icmp ne i32 %6, 0
%35 = select i1 %33, i1 true, i1 %34
%36 = select i1 %35, i32 1, i32 %9
%37 = select i1 %35, i32 %5, i32 1
%38 = select i1 %35, i32 %6, i32 0
%39 = select i1 %35, i32 %7, i32 0
br label %19
40: ; preds = %8
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @stderr
%50 = tail call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* @stderr
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%53 = load i32, i32* @stderr
%54 = tail call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.8, i64 0, i64 0))
br label %59
55: ; preds = %8
%56 = load i32, i32* @stderr
%57 = load i32, i32* @optopt
%58 = tail call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %55, %40
%60 = phi i32 [ 2, %55 ], [ 3, %40 ]
br label %8
61: ; preds = %8
%62 = icmp ne i32 %7, 0
%63 = icmp ne i32 %6, 0
%64 = select i1 %62, i1 true, i1 %63
%65 = icmp ne i32 %5, 0
%66 = select i1 %64, i1 true, i1 %65
switch i32 %9, label %70 [
i32 0, label %71
i32 1, label %67
i32 3, label %117
]
67: ; preds = %61
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0))
br label %70
70: ; preds = %61, %67
br label %117
71: ; preds = %61
%72 = tail call i32* @opendir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0))
%73 = icmp eq i32* %72, null
br i1 %73, label %80, label %74
74: ; preds = %71
%75 = tail call %struct.dirent* @readdir(i32* %72)
%76 = icmp eq %struct.dirent* %75, null
br i1 %76, label %115, label %77
77: ; preds = %74
%78 = icmp eq i32 %7, 0
%79 = select i1 %66, i1 %78, i1 false
br label %84
80: ; preds = %71
%81 = load i32, i32* @errno
%82 = tail call i8* @strerror(i32 %81)
%83 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %82)
br label %117
84: ; preds = %77, %112
%85 = phi %struct.dirent* [ %75, %77 ], [ %113, %112 ]
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i64 0, i32 0
%87 = load i8*, i8** %86
%88 = tail call i8* @strrchr(i8* dereferenceable(1) %87, i8 signext 46)
%89 = icmp eq i8* %88, null
br i1 %89, label %112, label %90
90: ; preds = %84
%91 = getelementptr inbounds i8, i8* %88, i64 1
%92 = tail call i32 @stricmp(i8* %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %112
94: ; preds = %90
store i8 0, i8* %88
br i1 %79, label %100, label %95
95: ; preds = %94
%96 = tail call i64 @pedigree_module_is_loaded(i8* %87)
%97 = icmp eq i64 %96, 0
%98 = select i1 %97, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0)
%99 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0), i8* %87, i8* %98)
br label %112
100: ; preds = %94
br i1 %63, label %101, label %106
101: ; preds = %100
%102 = tail call i64 @pedigree_module_is_loaded(i8* %87)
%103 = icmp eq i64 %102, 0
br i1 %103, label %112, label %104
104: ; preds = %101
%105 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* %87)
br label %112
106: ; preds = %100
br i1 %65, label %107, label %112
107: ; preds = %106
%108 = tail call i64 @pedigree_module_is_loaded(i8* %87)
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %112
110: ; preds = %107
%111 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0), i8* %87)
br label %112
112: ; preds = %95, %106, %110, %107, %101, %104, %90, %84
%113 = tail call %struct.dirent* @readdir(i32* %72)
%114 = icmp eq %struct.dirent* %113, null
br i1 %114, label %115, label %84
115: ; preds = %112, %74
%116 = tail call i32 @closedir(i32* %72)
br label %117
117: ; preds = %80, %115, %61, %70
%118 = phi i32 [ %9, %70 ], [ 0, %61 ], [ 0, %115 ], [ -1, %80 ]
ret i32 %118
}