#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ free(char *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ ls(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  if (argc > 0) {
    if (argc == 1) {
      char *wd = getcwd(NULL, 0);
      ls(wd);
      free(wd);
    } else {
      ls(argv[1]);
    }
    return EXIT_SUCCESS;
  } else {
    usage();
    return EXIT_FAILURE;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11ae <main+0x6e>
cmpl   $0x1,-0x8(%rbp)
jne    1190 <main+0x50>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1040 <getcwd@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ls@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    119d <main+0x5d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <ls@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11c1 <main+0x81>
mov    $0x0,%al
call   1060 <usage@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
test   %edi,%edi
jle    1168 <main+0x28>
cmp    $0x1,%edi
jne    1178 <main+0x38>
xor    %edi,%edi
xor    %esi,%esi
call   1040 <getcwd@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <ls@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1181 <main+0x41>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x2e6a(%rip),%rax
jmp    1188 <main+0x48>
mov    0x8(%rsi),%rdi
call   1050 <ls@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %25
9: ; preds = %2
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = call i8* @getcwd(i32* null, i32 0)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i32 @ls(i8* %14)
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
br label %23
18: ; preds = %9
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @ls(i8* %21)
br label %23
23: ; preds = %18, %12
%24 = load i32, i32* @EXIT_SUCCESS
store i32 %24, i32* %3
br label %28
25: ; preds = %2
%26 = call i32 (...) @usage()
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %23
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %4
%7 = tail call i8* @getcwd(i32* null, i32 0)
%8 = tail call i32 @ls(i8* %7)
%9 = tail call i32 @free(i8* %7)
br label %16
10: ; preds = %4
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @ls(i8* %12)
br label %16
14: ; preds = %2
%15 = tail call i32 (...) @usage()
br label %16
16: ; preds = %6, %10, %14
%17 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_SUCCESS, %10 ], [ @EXIT_SUCCESS, %6 ]
%18 = load i32, i32* %17
ret i32 %18
}