#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(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
void main(int argc, char *argv[]) {
  char *loc = "/proc";
  if (argv && argc > 1)
    loc = argv[1];
  DIR *fd = opendir(loc);
  struct dirent *de = 0;
  while (de = readdir(fd))
    printf("%s\n", de->d_name);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <main+0x3b>
cmpl   $0x1,-0x4(%rbp)
jle    117b <main+0x3b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11bf <main+0x7f>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
jmp    1190 <main+0x50>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%eax
lea    0xeb3(%rip),%rdi
cmp    $0x2,%eax
jl     115b <main+0x1b>
test   %rsi,%rsi
je     115b <main+0x1b>
mov    0x8(%rsi),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     1198 <main+0x58>
lea    0xe8f(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%rax),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
jne    1180 <main+0x40>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = icmp ne i8** %1, null
%4 = icmp sgt i32 %0, 1
%5 = and i1 %4, %3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
br label %9
9: ; preds = %6, %2
%10 = phi i8* [ %8, %6 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = tail call i32* @opendir(i8* %10)
%12 = tail call %struct.dirent* @readdir(i32* %11)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %21, label %14
14: ; preds = %9, %14
%15 = phi %struct.dirent* [ %19, %14 ], [ %12, %9 ]
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%17 = load i8*, i8** %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = tail call %struct.dirent* @readdir(i32* %11)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14, %9
%22 = tail call i32 @exit(i32 0)
unreachable
}