#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  DIR *dp = NULL;
  struct dirent *dir = NULL;
  if (argc != 2) {
    fprintf(stderr, "Usage: main directory_name\n");
    exit(EXIT_FAILURE);
  }
  if ((dp = opendir(argv[1])) == NULL) {
    fprintf(stderr, "Can't open %s.", argv[1]);
    exit(EXIT_FAILURE);
  }
  while ((dir = readdir(dp)) != NULL)
    fprintf(stdout, "%s\n", dir->d_name);
  closedir(dp);
  exit(EXIT_SUCCESS);
}


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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a5 <main+0x55>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ed <main+0x9d>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11f2 <main+0xa2>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122c <main+0xdc>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11f2 <main+0xa2>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1188 <main+0x38>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
jne    11ad <main+0x5d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe9d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    119f <main+0x4f>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11ed <main+0x9d>
mov    0x2e0c(%rip),%r15
lea    0xe60(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    (%rax),%rdx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    11d0 <main+0x80>
mov    %rbx,%rdi
call   1040 <closedir@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [28 x i8] c"Usage: main directory_name\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [15 x i8] c"Can't open %s.\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
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
store i32* null, i32** %6
store %struct.dirent* null, %struct.dirent** %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @opendir(i8* %18)
store i32* %19, i32** %6
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %15
br label %30
30: ; preds = %34, %29
%31 = load i32*, i32** %6
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %7
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i32, i32* @stdout
%36 = load %struct.dirent*, %struct.dirent** %7
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %38)
br label %30
40: ; preds = %30
%41 = load i32*, i32** %6
%42 = call i32 @closedir(i32* %41)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
}

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