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

/* Variables and functions */
int /*<<< orphan*/ getcwd(char *, int);
int getopt(int, char **, char *);
int /*<<< orphan*/ list_items(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  int arg_count = argc;
  char **arguments = argv;
  bool show_all = false;
  int c = getopt(arg_count, arguments, "a");
  if (c == 'a') {
    arg_count--;
    arguments++;
    show_all = true;
  }
  if (arg_count == 1) {
    char current_dir[1024];
    getcwd(current_dir, sizeof(current_dir));
    DIR *directory = opendir(current_dir);
    list_items(directory, show_all);
  }
  while (--arg_count > 0) {
    DIR *directory = opendir(*++arguments);
    if (directory == NULL) {
      perror(*arguments);
      return 1;
    }
    list_items(directory, show_all);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    0xe64(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x61,-0x28(%rbp)
jne    11ca <main+0x6a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1207 <main+0xa7>
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    -0x430(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1080 <list_items@plt>
jmp    120c <main+0xac>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1277 <main+0x117>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x20(%rbp)
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x440(%rbp)
cmpq   $0x0,-0x440(%rbp)
jne    1263 <main+0x103>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1283 <main+0x123>
mov    -0x440(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1080 <list_items@plt>
jmp    120c <main+0xac>
lea    0xd84(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xe84(%rip),%rdx
call   1070 <getopt@plt>
xor    %r12d,%r12d
cmp    $0x61,%eax
sete   %r12b
mov    %r15d,%ecx
sub    %r12d,%ecx
cmp    $0x1,%ecx
jne    11bb <main+0x5b>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
mov    %r14,%rdi
call   1040 <opendir@plt>
mov    %rax,%rdi
mov    %r12d,%esi
call   1080 <list_items@plt>
jmp    1204 <main+0xa4>
jle    1204 <main+0xa4>
mov    %r12d,%ecx
neg    %ecx
xor    %edx,%edx
cmp    $0x61,%eax
sete   %dl
lea    (%r15,%rcx,1),%ebp
add    $0x1,%ebp
lea    (%r14,%rdx,8),%rbx
add    $0x8,%rbx
nopl   0x0(%rax)
mov    (%rbx),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1220 <main+0xc0>
mov    %rax,%rdi
mov    %r12d,%esi
call   1080 <list_items@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x2,%ebp
jg     11e0 <main+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
jmp    1210 <main+0xb0>

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
store i32 %13, i32* %6
%14 = load i8**, i8*** %5
store i8** %14, i8*** %7
store i32 0, i32* %8
%15 = load i32, i32* %6
%16 = load i8**, i8*** %7
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, 97
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i32, i32* %6
%22 = add nsw i32 %21, -1
store i32 %22, i32* %6
%23 = load i8**, i8*** %7
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %7
store i32 1, i32* %8
br label %25
25: ; preds = %20, %2
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%30 = call i32 @getcwd(i8* %29, i32 1024)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%32 = call i32* @opendir(i8* %31)
store i32* %32, i32** %11
%33 = load i32*, i32** %11
%34 = load i32, i32* %8
%35 = call i32 @list_items(i32* %33, i32 %34)
br label %36
36: ; preds = %28, %25
br label %37
37: ; preds = %52, %36
%38 = load i32, i32* %6
%39 = add nsw i32 %38, -1
store i32 %39, i32* %6
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %56
41: ; preds = %37
%42 = load i8**, i8*** %7
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %7
%44 = load i8*, i8** %43
%45 = call i32* @opendir(i8* %44)
store i32* %45, i32** %12
%46 = load i32*, i32** %12
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %52
48: ; preds = %41
%49 = load i8**, i8*** %7
%50 = load i8*, i8** %49
%51 = call i32 @perror(i8* %50)
store i32 1, i32* %3
br label %58
52: ; preds = %41
%53 = load i32*, i32** %12
%54 = load i32, i32* %8
%55 = call i32 @list_items(i32* %53, i32 %54)
br label %37
56: ; preds = %37
%57 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %58
58: ; preds = %56, %48
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 97
%6 = zext i1 %5 to i32
%7 = sext i1 %5 to i32
%8 = add nsw i32 %7, %0
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = call i32 @getcwd(i8* %11, i32 1024)
%13 = call i32* @opendir(i8* %11)
%14 = call i32 @list_items(i32* %13, i32 %6)
br label %34
15: ; preds = %2
%16 = icmp sgt i32 %8, 1
br i1 %16, label %17, label %34
17: ; preds = %15
%18 = zext i1 %5 to i64
%19 = getelementptr i8*, i8** %1, i64 %18
br label %20
20: ; preds = %17, %30
%21 = phi i32 [ %31, %30 ], [ %8, %17 ]
%22 = phi i8** [ %23, %30 ], [ %19, %17 ]
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32* @opendir(i8* %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i8*, i8** %23
%29 = call i32 @perror(i8* %28)
br label %36
30: ; preds = %20
%31 = add nsw i32 %21, -1
%32 = call i32 @list_items(i32* %25, i32 %6)
%33 = icmp sgt i32 %21, 2
br i1 %33, label %20, label %34
34: ; preds = %30, %10, %15
%35 = call i32 @putchar(i32 10)
br label %36
36: ; preds = %27, %34
%37 = phi i32 [ 0, %34 ], [ 1, %27 ]
ret i32 %37
}