#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 EOF;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ listfile(char *);
int /*<<< orphan*/ *opendir(char *);
scalar_t__ opterr;
scalar_t__ optind;
int optopt;
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  DIR *d;
  struct dirent *info;
  int c, allflag = 0;
  opterr = 0;
  while ((c = getopt(argc, argv, "a")) != EOF) {
    switch (c) {
    case 'a':
      allflag = 1;
      break;
    case '?':
      fprintf(stderr, "invalid option: -%c\n", optopt);
    }
  }
  argv += optind;
  argc -= optind;
  if (argc != 1) {
    fprintf(stderr, "usage: listdir2 [-a] dirname\n");
    exit(1);
  }
  chdir(argv[0]);
  d = opendir(".");
  while ((info = readdir(d)) != NULL) {
    if (info->d_name[0] != '.' || allflag)
      listfile(info->d_name);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    0x2e2c(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe57(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%eax
je     1216 <main+0xa6>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x3f,%eax
je     11f1 <main+0x81>
jmp    11d4 <main+0x64>
mov    -0x2c(%rbp),%eax
sub    $0x61,%eax
jne    1211 <main+0xa1>
jmp    11e5 <main+0x75>
movl   $0x1,-0x28(%rbp)
jmp    1211 <main+0xa1>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    119b <main+0x2b>
mov    0x2dbb(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     126b <main+0xfb>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <chdir@plt>
lea    0xdb7(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12cc <main+0x15c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12bb <main+0x14b>
cmpl   $0x0,-0x28(%rbp)
je     12c7 <main+0x157>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1070 <listfile@plt>
jmp    1287 <main+0x117>
mov    -0x4(%rbp),%eax
add    $0x30,%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
mov    0x2e39(%rip),%rax
movq   $0x0,(%rax)
lea    0xe6b(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2e3f(%rip),%r13
xor    %r12d,%r12d
cmp    0x0(%r13),%eax
jne    1212 <main+0xa2>
mov    0x2e27(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebp
cmp    $0x1,%ebp
jne    1275 <main+0x105>
mov    (%rbx,%rax,8),%rdi
call   1040 <chdir@plt>
lea    0xe66(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    11e8 <main+0x78>
nopl   0x0(%rax)
call   1070 <listfile@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1201 <main+0x91>
mov    (%rax),%rdi
cmpb   $0x2e,(%rdi)
jne    11e0 <main+0x70>
test   %r12d,%r12d
je     11e5 <main+0x75>
jmp    11e0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde9(%rip),%r14
lea    0xde0(%rip),%r15
xor    %r12d,%r12d
jmp    1263 <main+0xf3>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    0x0(%r13),%eax
je     11aa <main+0x3a>
cmp    $0x3f,%eax
je     1230 <main+0xc0>
cmp    $0x61,%eax
jne    124c <main+0xdc>
mov    $0x1,%r12d
jmp    124c <main+0xdc>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@opterr = global i64 0
@.str = [2 x i8] c"a\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"invalid option: -%c\0A\00"
@optopt = global i32 0
@optind = global i64 0
@.str.2 = [30 x i8] c"usage: listdir2 [-a] dirname\0A\00"
@.str.3 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%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
store i32 0, i32* %9
store i64 0, i64* @opterr
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %8
%14 = load i32, i32* @EOF
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %10
%17 = load i32, i32* %8
switch i32 %17, label %23 [
i32 97, label %18
i32 63, label %19
]
18: ; preds = %16
store i32 1, i32* %9
br label %23
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i32, i32* @optopt
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %16, %18
br label %10
24: ; preds = %10
%25 = load i64, i64* @optind
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 %25
store i8** %27, i8*** %5
%28 = load i64, i64* @optind
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = sub nsw i64 %30, %28
%32 = trunc i64 %31 to i32
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 1
br i1 %34, label %35, label %39
35: ; preds = %24
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %24
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @chdir(i8* %42)
%44 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %44, i32** %6
br label %45
45: ; preds = %65, %39
%46 = load i32*, i32** %6
%47 = call %struct.dirent* @readdir(i32* %46)
store %struct.dirent* %47, %struct.dirent** %7
%48 = icmp ne %struct.dirent* %47, null
br i1 %48, label %49, label %66
49: ; preds = %45
%50 = load %struct.dirent*, %struct.dirent** %7
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 46
br i1 %56, label %60, label %57
57: ; preds = %49
%58 = load i32, i32* %9
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %57, %49
%61 = load %struct.dirent*, %struct.dirent** %7
%62 = getelementptr inbounds %struct.dirent, %struct.dirent* %61, i32 0, i32 0
%63 = load i8*, i8** %62
%64 = call i32 @listfile(i8* %63)
br label %65
65: ; preds = %60, %57
br label %45
66: ; preds = %45
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@opterr = global i64 0
@.str = [2 x i8] c"a\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"invalid option: -%c\0A\00"
@optopt = global i32 0
@optind = global i64 0
@.str.2 = [30 x i8] c"usage: listdir2 [-a] dirname\0A\00"
@.str.3 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
store i64 0, i64* @opterr
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %19, label %6
6: ; preds = %2, %14
%7 = phi i32 [ %16, %14 ], [ %3, %2 ]
%8 = phi i32 [ %15, %14 ], [ 0, %2 ]
switch i32 %7, label %14 [
i32 97, label %9
i32 63, label %10
]
9: ; preds = %6
br label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = load i32, i32* @optopt
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %6, %9
%15 = phi i32 [ %8, %6 ], [ %8, %10 ], [ 1, %9 ]
%16 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %6
19: ; preds = %14, %2
%20 = phi i32 [ 0, %2 ], [ %15, %14 ]
%21 = load i64, i64* @optind
%22 = trunc i64 %21 to i32
%23 = sub i32 %0, %22
%24 = icmp eq i32 %23, 1
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %19
%30 = getelementptr inbounds i8*, i8** %1, i64 %21
%31 = load i8*, i8** %30
%32 = tail call i32 @chdir(i8* %31)
%33 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call %struct.dirent* @readdir(i32* %33)
%35 = icmp eq %struct.dirent* %34, null
br i1 %35, label %50, label %36
36: ; preds = %29
%37 = icmp ne i32 %20, 0
br label %38
38: ; preds = %36, %47
%39 = phi %struct.dirent* [ %34, %36 ], [ %48, %47 ]
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i64 0, i32 0
%41 = load i8*, i8** %40
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 46
%44 = select i1 %43, i1 true, i1 %37
br i1 %44, label %45, label %47
45: ; preds = %38
%46 = tail call i32 @listfile(i8* %41)
br label %47
47: ; preds = %38, %45
%48 = tail call %struct.dirent* @readdir(i32* %33)
%49 = icmp eq %struct.dirent* %48, null
br i1 %49, label %50, label %38
50: ; preds = %47, %29
ret i32 0
}