#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 /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  DIR *dp;
  struct dirent *dirp;
  if (argc != 2)
    printf("%s\n", "usage: ls directory_name");
  if ((dp = opendir(argv[1])) == NULL)
    printf("can't open %s", argv[1]);
  while ((dirp = readdir(dp)) != NULL)
    printf("%s\n", dirp->d_name);
  closedir(dp);
  exit(0);
}


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   $0x2,-0x8(%rbp)
je     1183 <main+0x33>
lea    0xe89(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
jmp    11b7 <main+0x67>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e6 <main+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
jmp    11b7 <main+0x67>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
je     116f <main+0x1f>
lea    0xe9d(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <printf@plt>
mov    0x8(%r14),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1190 <main+0x40>
mov    0x8(%r14),%rsi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11c8 <main+0x78>
lea    0xe5c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rax),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    11b0 <main+0x60>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [25 x i8] c"usage: ls directory_name\00"
@.str.2 = [14 x i8] c"can't open %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %18, %12
br label %24
24: ; preds = %28, %23
%25 = load i32*, i32** %6
%26 = call %struct.dirent* @readdir(i32* %25)
store %struct.dirent* %26, %struct.dirent** %7
%27 = icmp ne %struct.dirent* %26, null
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = load %struct.dirent*, %struct.dirent** %7
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %31)
br label %24
33: ; preds = %24
%34 = load i32*, i32** %6
%35 = call i32 @closedir(i32* %34)
%36 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [25 x i8] c"usage: ls directory_name\00"
@.str.2 = [14 x i8] c"can't open %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @opendir(i8* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %6
%15 = tail call %struct.dirent* @readdir(i32* %9)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %24, label %17
17: ; preds = %14, %17
%18 = phi %struct.dirent* [ %22, %17 ], [ %15, %14 ]
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = tail call %struct.dirent* @readdir(i32* %9)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %24, label %17
24: ; preds = %17, %14
%25 = tail call i32 @closedir(i32* %9)
%26 = tail call i32 @exit(i32 0)
unreachable
}