#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 */
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int);
char getopt(int, char **, char *);
int /*<<< orphan*/ listAllColl_close(int /*<<< orphan*/ *);
char *listAllColl_next(int /*<<< orphan*/ *);
int /*<<< orphan*/ *listAllColl_start();
int /*<<< orphan*/ printf(char *, ...);
int rLastDocID(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char *argv[]) {
  int optCount = 0;
  int optFormat = 0;
  char *optmatch = NULL;
  extern char *optarg;
  char c;
  while ((c = getopt(argc, argv, "cfm:")) != -1) {
    switch (c) {
    case 'c':
      optCount = 1;
      break;
    case 'f':
      optFormat = 1;
      break;
    case 'm':
      optmatch = optarg;
      break;
    default:
      exit(-1);
    }
  }
  if (optFormat == 1) {
    printf("|--------------------------------|------------|\n");
    printf("| Collection                     | Nr of docs |\n");
    printf("|--------------------------------|------------|\n");
  }
  DIR *dirh = listAllColl_start();
  if (dirh == NULL)
    err(1, "listAllColl_start()");
  char *subname;
  int docCount = 0;
  while ((subname = listAllColl_next(dirh)) != NULL) {
    if ((optmatch != NULL) && (strstr(subname, optmatch) == NULL)) {
      continue;
    }
    if (optCount == 1) {
      docCount = rLastDocID(subname);
    }
    if ((optCount == 1) && (optFormat == 1)) {
      printf("| %30s | %10u |\n", subname, docCount);
    } else if (optCount == 1) {
      printf("subname: %s, docCount: %u\n", subname, docCount);
    } else {
      printf("subname: %s\n", subname);
    }
  }
  listAllColl_close(dirh);
  if (optFormat == 1) {
    printf("|--------------------------------|------------|\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe36(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     124f <main+0xbf>
movsbl -0x21(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x63,%eax
je     1215 <main+0x85>
jmp    11f3 <main+0x63>
mov    -0x40(%rbp),%eax
sub    $0x66,%eax
je     1221 <main+0x91>
jmp    1204 <main+0x74>
mov    -0x40(%rbp),%eax
sub    $0x6d,%eax
je     122d <main+0x9d>
jmp    1240 <main+0xb0>
movl   $0x1,-0x14(%rbp)
jmp    124a <main+0xba>
movl   $0x1,-0x18(%rbp)
jmp    124a <main+0xba>
mov    0x2dac(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    124a <main+0xba>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    11bc <main+0x2c>
cmpl   $0x1,-0x18(%rbp)
jne    1283 <main+0xf3>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <listAllColl_start@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12aa <main+0x11a>
mov    $0x1,%edi
lea    0xdc2(%rip),%rsi
call   1070 <err@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <listAllColl_next@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1373 <main+0x1e3>
cmpq   $0x0,-0x20(%rbp)
je     12ef <main+0x15f>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
jne    12ef <main+0x15f>
jmp    12b1 <main+0x121>
cmpl   $0x1,-0x14(%rbp)
jne    1305 <main+0x175>
mov    -0x38(%rbp),%rdi
call   1050 <rLastDocID@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1333 <main+0x1a3>
cmpl   $0x1,-0x18(%rbp)
jne    1333 <main+0x1a3>
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    136e <main+0x1de>
cmpl   $0x1,-0x14(%rbp)
jne    1357 <main+0x1c7>
mov    -0x38(%rbp),%rsi
mov    -0x3c(%rbp),%edx
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1369 <main+0x1d9>
mov    -0x38(%rbp),%rsi
lea    0xd45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    136e <main+0x1de>
jmp    12b1 <main+0x121>
mov    -0x30(%rbp),%rdi
call   1060 <listAllColl_close@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1394 <main+0x204>
lea    0xc78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%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
mov    %edi,%ebp
lea    0xe49(%rip),%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     1256 <main+0xb6>
xor    %r12d,%r12d
lea    0xe32(%rip),%r15
xor    %r13d,%r13d
xor    %r14d,%r14d
jmp    11fb <main+0x5b>
cs nopw 0x0(%rax,%rax,1)
mov    0x2df9(%rip),%rax
mov    (%rax),%r14
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getopt@plt>
cmp    $0xff,%al
je     1228 <main+0x88>
movsbl %al,%eax
cmp    $0x63,%eax
je     1220 <main+0x80>
cmp    $0x6d,%eax
je     11e0 <main+0x40>
cmp    $0x66,%eax
jne    131d <main+0x17d>
mov    $0x1,%r13d
jmp    11ea <main+0x4a>
nopl   0x0(%rax)
mov    $0x1,%r12d
jmp    11ea <main+0x4a>
cmp    $0x1,%r13d
jne    1261 <main+0xc1>
lea    0xe4d(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%r15b
jmp    1264 <main+0xc4>
xor    %r15d,%r15d
xor    %r12d,%r12d
xor    %r14d,%r14d
jmp    1264 <main+0xc4>
xor    %r15d,%r15d
xor    %eax,%eax
call   1090 <listAllColl_start@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1284 <main+0xe4>
lea    0xd8b(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
lea    0xdba(%rip),%r13
jmp    129d <main+0xfd>
nopl   (%rax)
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <listAllColl_next@plt>
test   %rax,%rax
je     12f3 <main+0x153>
mov    %rax,%rbp
test   %r14,%r14
je     12c2 <main+0x122>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     129d <main+0xfd>
cmp    $0x1,%r12d
jne    1290 <main+0xf0>
mov    %rbp,%rdi
call   1060 <rLastDocID@plt>
test   %r15b,%r15b
je     12de <main+0x13e>
lea    0xd3d(%rip),%rdi
jmp    12e5 <main+0x145>
lea    0xd45(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    129d <main+0xfd>
mov    %rbx,%rdi
call   1070 <listAllColl_close@plt>
test   %r15b,%r15b
je     130c <main+0x16c>
lea    0xd7b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"cfm:\00"
@optarg = external global i8*
@.str.1 = [49 x i8] c"|--------------------------------|------------|\0A\00"
@.str.2 = [49 x i8] c"| Collection | Nr of docs |\0A\00"
@.str.3 = [20 x i8] c"listAllColl_start()\00"
@.str.4 = [17 x i8] c"| %30s | %10u |\0A\00"
@.str.5 = [27 x i8] c"subname: %s, docCount: %u\0A\00"
@.str.6 = [13 x i8] c"subname: %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 i8*
%9 = alloca i8
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
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 i8* null, i8** %8
br label %13
13: ; preds = %28, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call signext i8 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8 %16, i8* %9
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %29
19: ; preds = %13
%20 = load i8, i8* %9
%21 = sext i8 %20 to i32
switch i32 %21, label %26 [
i32 99, label %22
i32 102, label %23
i32 109, label %24
]
22: ; preds = %19
store i32 1, i32* %6
br label %28
23: ; preds = %19
store i32 1, i32* %7
br label %28
24: ; preds = %19
%25 = load i8*, i8** @optarg
store i8* %25, i8** %8
br label %28
26: ; preds = %19
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %24, %23, %22
br label %13
29: ; preds = %13
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %32, %29
%37 = call i32* (...) @listAllColl_start()
store i32* %37, i32** %10
%38 = load i32*, i32** %10
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
store i32 0, i32* %12
br label %43
43: ; preds = %83, %55, %42
%44 = load i32*, i32** %10
%45 = call i8* @listAllColl_next(i32* %44)
store i8* %45, i8** %11
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %84
47: ; preds = %43
%48 = load i8*, i8** %8
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %56
50: ; preds = %47
%51 = load i8*, i8** %11
%52 = load i8*, i8** %8
%53 = call i32* @strstr(i8* %51, i8* %52)
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %56
55: ; preds = %50
br label %43
56: ; preds = %50, %47
%57 = load i32, i32* %6
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %11
%61 = call i32 @rLastDocID(i8* %60)
store i32 %61, i32* %12
br label %62
62: ; preds = %59, %56
%63 = load i32, i32* %6
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %72
65: ; preds = %62
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 1
br i1 %67, label %68, label %72
68: ; preds = %65
%69 = load i8*, i8** %11
%70 = load i32, i32* %12
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %69, i32 %70)
br label %83
72: ; preds = %65, %62
%73 = load i32, i32* %6
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %79
75: ; preds = %72
%76 = load i8*, i8** %11
%77 = load i32, i32* %12
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %76, i32 %77)
br label %82
79: ; preds = %72
%80 = load i8*, i8** %11
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %79, %75
br label %83
83: ; preds = %82, %68
br label %43
84: ; preds = %43
%85 = load i32*, i32** %10
%86 = call i32 @listAllColl_close(i32* %85)
%87 = load i32, i32* %7
%88 = icmp eq i32 %87, 1
br i1 %88, label %89, label %91
89: ; preds = %84
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
br label %91
91: ; preds = %89, %84
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"cfm:\00"
@optarg = external global i8*
@.str.3 = [20 x i8] c"listAllColl_start()\00"
@.str.4 = [17 x i8] c"| %30s | %10u |\0A\00"
@.str.5 = [27 x i8] c"subname: %s, docCount: %u\0A\00"
@.str.6 = [13 x i8] c"subname: %s\0A\00"
@str.8 = [48 x i8] c"| Collection | Nr of docs |\00"
@str.9 = [48 x i8] c"|--------------------------------|------------|\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8 %3, -1
br i1 %4, label %28, label %5
5: ; preds = %2, %16
%6 = phi i8 [ %20, %16 ], [ %3, %2 ]
%7 = phi i32 [ %19, %16 ], [ 0, %2 ]
%8 = phi i32 [ %18, %16 ], [ 0, %2 ]
%9 = phi i8* [ %17, %16 ], [ null, %2 ]
%10 = sext i8 %6 to i32
switch i32 %10, label %14 [
i32 99, label %16
i32 102, label %11
i32 109, label %12
]
11: ; preds = %5
br label %16
12: ; preds = %5
%13 = load i8*, i8** @optarg
br label %16
14: ; preds = %5
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %5, %12, %11
%17 = phi i8* [ %13, %12 ], [ %9, %11 ], [ %9, %5 ]
%18 = phi i32 [ %8, %12 ], [ 1, %11 ], [ %8, %5 ]
%19 = phi i32 [ %7, %12 ], [ %7, %11 ], [ 1, %5 ]
%20 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i8 %20, -1
br i1 %21, label %22, label %5
22: ; preds = %16
%23 = icmp eq i32 %18, 1
br i1 %23, label %24, label %28
24: ; preds = %22
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.8, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
br label %28
28: ; preds = %2, %24, %22
%29 = phi i1 [ true, %24 ], [ false, %22 ], [ false, %2 ]
%30 = phi i32 [ %19, %24 ], [ %19, %22 ], [ 0, %2 ]
%31 = phi i8* [ %17, %24 ], [ %17, %22 ], [ null, %2 ]
%32 = tail call i32* (...) @listAllColl_start()
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %28
%37 = icmp eq i8* %31, null
%38 = icmp eq i32 %30, 1
br label %39
39: ; preds = %46, %36
%40 = tail call i8* @listAllColl_next(i32* %32)
%41 = icmp eq i8* %40, null
br i1 %41, label %56, label %42
42: ; preds = %39
br i1 %37, label %47, label %43
43: ; preds = %42
%44 = tail call i32* @strstr(i8* %40, i8* %31)
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %47
46: ; preds = %43, %52, %54, %50
br label %39
47: ; preds = %43, %42
br i1 %38, label %48, label %54
48: ; preds = %47
%49 = tail call i32 @rLastDocID(i8* %40)
br i1 %29, label %50, label %52
50: ; preds = %48
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %40, i32 %49)
br label %46
52: ; preds = %48
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %40, i32 %49)
br label %46
54: ; preds = %47
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %40)
br label %46
56: ; preds = %39
%57 = tail call i32 @listAllColl_close(i32* %32)
br i1 %29, label %58, label %60
58: ; preds = %56
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
br label %60
60: ; preds = %58, %56
ret i32 0
}