#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ listdir(char *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  char cwd[256];
  getcwd(cwd, 256);
  if (argc == 1)
    listdir(cwd, 0);
  else if (argc == 2 && (!strcmp((argv[1]), ("-l"))))
    listdir(cwd, 1);
  else if (argc == 2 && (strcmp((argv[1]), ("-l"))))
    listdir(argv[1], 0);
  else if (argc == 3 && (!strcmp((argv[1]), ("-l"))))
    listdir(argv[2], 1);
  else {
    printf("ls: error\n");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    $0x100,%esi
call   1050 <getcwd@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1197 <main+0x47>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
call   1030 <listdir@plt>
jmp    1275 <main+0x125>
cmpl   $0x2,-0x8(%rbp)
jne    11d5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe50(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d5 <main+0x85>
lea    -0x110(%rbp),%rdi
mov    $0x1,%esi
call   1030 <listdir@plt>
jmp    1270 <main+0x120>
cmpl   $0x2,-0x8(%rbp)
jne    1211 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe12(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1211 <main+0xc1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   1030 <listdir@plt>
jmp    126b <main+0x11b>
cmpl   $0x3,-0x8(%rbp)
jne    1250 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1250 <main+0x100>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    $0x1,%esi
call   1030 <listdir@plt>
jmp    1266 <main+0x116>
lea    0xdac(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    126b <main+0x11b>
jmp    1270 <main+0x120>
jmp    1275 <main+0x125>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x100,%esi
call   1050 <getcwd@plt>
cmp    $0x3,%ebp
je     117f <main+0x2f>
cmp    $0x2,%ebp
je     119a <main+0x4a>
cmp    $0x1,%ebp
jne    11ce <main+0x7e>
mov    %rsp,%rdi
jmp    11e8 <main+0x98>
mov    0x8(%rbx),%rdi
lea    0xe76(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11ce <main+0x7e>
mov    0x10(%rbx),%rdi
jmp    11b2 <main+0x62>
mov    0x8(%rbx),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11b9 <main+0x69>
mov    %rsp,%rdi
mov    $0x1,%esi
jmp    11ea <main+0x9a>
mov    0x8(%rbx),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e4 <main+0x94>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
call   1040 <listdir@plt>
xor    %edi,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"-l\00"
@str = [10 x i8] c"ls: error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @getcwd(i8* %4, i32 256)
switch i32 %0, label %31 [
i32 1, label %6
i32 2, label %8
i32 3, label %22
]
6: ; preds = %2
%7 = call i32 @listdir(i8* %4, i32 0)
br label %34
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @listdir(i8* %4, i32 1)
br label %34
15: ; preds = %8
%16 = load i8*, i8** %9
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %15
%20 = load i8*, i8** %9
%21 = call i32 @listdir(i8* %20, i32 0)
br label %34
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @listdir(i8* %29, i32 1)
br label %34
31: ; preds = %2, %15, %22
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %13, %27, %19, %6
%35 = call i32 @exit(i32 0)
unreachable
}