#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*/ err_quit(char *);
int /*<<< orphan*/ err_sys(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  DIR *dp;
  struct dirent *dirp;
  if (argc != 2) {
    err_quit("Usage: ls dir1 [dir2] [dir3]");
  }
  if ((dp = opendir(*++argv)) == NULL) {
    err_sys("cann't open %s", *argv);
  }
  while ((dirp = readdir(dp)) != NULL) {
    fprintf(stdout, "%s\n", dirp->d_name);
  }
  closedir(dp);
  return 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     118c <main+0x2c>
lea    0xe79(%rip),%rdi
call   1060 <err_quit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c5 <main+0x65>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5d(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11ca <main+0x6a>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1202 <main+0xa2>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe34(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11ca <main+0x6a>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
je     1179 <main+0x19>
lea    0xe8c(%rip),%rdi
call   1060 <err_quit@plt>
mov    0x8(%r14),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119a <main+0x3a>
mov    0x8(%r14),%rsi
lea    0xe88(%rip),%rdi
call   1030 <err_sys@plt>
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11db <main+0x7b>
mov    0x2e32(%rip),%r15
lea    0xe77(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edi
mov    (%rax),%rdx
mov    %r14,%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [29 x i8] c"Usage: ls dir1 [dir2] [dir3]\00"
@.str.1 = [15 x i8] c"cann't open %s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\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 @err_quit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
%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 %22
18: ; preds = %12
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = call i32 @err_sys(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %18, %12
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %6
%25 = call %struct.dirent* @readdir(i32* %24)
store %struct.dirent* %25, %struct.dirent** %7
%26 = icmp ne %struct.dirent* %25, null
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* @stdout
%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 @fprintf(i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %23
33: ; preds = %23
%34 = load i32*, i32** %6
%35 = call i32 @closedir(i32* %34)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [29 x i8] c"Usage: ls dir1 [dir2] [dir3]\00"
@.str.1 = [15 x i8] c"cann't open %s\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\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 @err_quit(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, 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 @err_sys(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, 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 %25, label %17
17: ; preds = %14, %17
%18 = phi %struct.dirent* [ %23, %17 ], [ %15, %14 ]
%19 = load i32, i32* @stdout
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = tail call %struct.dirent* @readdir(i32* %9)
%24 = icmp eq %struct.dirent* %23, null
br i1 %24, label %25, label %17
25: ; preds = %17, %14
%26 = tail call i32 @closedir(i32* %9)
ret i32 0
}