#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;
  int /*<<< orphan*/ d_off;
  int /*<<< orphan*/ d_ino;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int main(int argc, char *argv[]) {
  int fd = -1;
  DIR *dPtr = NULL;
  struct dirent *d = NULL;
  if ((fd = open(argv[1], 0, 0)) == -1) {
    fprintf(stderr, "Unable to open %s (%s)\n", argv[1], strerror(errno));
    exit(1);
  }
  if ((dPtr = opendir(argv[1])) == NULL) {
    fprintf(stderr, "Unable to opendir %s (%s)\n", argv[1], strerror(errno));
    exit(2);
  }
  while ((d = readdir(dPtr)) != NULL) {
    printf("%20s  %ld  %ld\n", d->d_name, d->d_ino, d->d_off);
  }
  if (errno != 0) {
    fprintf(stderr, "Failure during readdir()! (%s)\n", strerror(errno));
    exit(3);
  }
  closedir(dPtr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1213 <main+0x93>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1277 <main+0xf7>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
jmp    127c <main+0xfc>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12b9 <main+0x139>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xd84(%rip),%rdi
call   1040 <printf@plt>
jmp    127c <main+0xfc>
mov    0x2d18(%rip),%rax
cmpq   $0x0,(%rax)
je     1303 <main+0x183>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cfb(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1213 <main+0x93>
mov    0x8(%r14),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     124f <main+0xcf>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11ee <main+0x6e>
lea    0xe71(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rax),%rsi
mov    0xc(%rax),%edx
mov    0x8(%rax),%ecx
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
jne    11d0 <main+0x50>
mov    0x2de3(%rip),%rax
mov    (%rax),%rdi
test   %rdi,%rdi
jne    128b <main+0x10b>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dc6(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2db1(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xdca(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%r14),%r14
mov    0x2d75(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
lea    0xda6(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%ebx
call   10a0 <strerror@plt>
lea    0xda3(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Unable to open %s (%s)\0A\00"
@errno = global i64 0
@.str.1 = [27 x i8] c"Unable to opendir %s (%s)\0A\00"
@.str.2 = [16 x i8] c"%20s %ld %ld\0A\00"
@.str.3 = [32 x i8] c"Failure during readdir()! (%s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32* null, i32** %7
store %struct.dirent* null, %struct.dirent** %8
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @open(i8* %11, i32 0, i32 0)
store i32 %12, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i64, i64* @errno
%20 = call i8* @strerror(i64 %19)
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %18, i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @opendir(i8* %26)
store i32* %27, i32** %7
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %38
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i64, i64* @errno
%35 = call i8* @strerror(i64 %34)
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %35)
%37 = call i32 @exit(i32 2)
unreachable
38: ; preds = %23
br label %39
39: ; preds = %43, %38
%40 = load i32*, i32** %7
%41 = call %struct.dirent* @readdir(i32* %40)
store %struct.dirent* %41, %struct.dirent** %8
%42 = icmp ne %struct.dirent* %41, null
br i1 %42, label %43, label %54
43: ; preds = %39
%44 = load %struct.dirent*, %struct.dirent** %8
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = load %struct.dirent*, %struct.dirent** %8
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 2
%49 = load i32, i32* %48
%50 = load %struct.dirent*, %struct.dirent** %8
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %46, i32 %49, i32 %52)
br label %39
54: ; preds = %39
%55 = load i64, i64* @errno
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i64, i64* @errno
%60 = call i8* @strerror(i64 %59)
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %60)
%62 = call i32 @exit(i32 3)
unreachable
63: ; preds = %54
%64 = load i32*, i32** %7
%65 = call i32 @closedir(i32* %64)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"Unable to open %s (%s)\0A\00"
@errno = global i64 0
@.str.1 = [27 x i8] c"Unable to opendir %s (%s)\0A\00"
@.str.2 = [16 x i8] c"%20s %ld %ld\0A\00"
@.str.3 = [32 x i8] c"Failure during readdir()! (%s)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @open(i8* %4, i32 0, i32 0)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %3
%10 = load i64, i64* @errno
%11 = tail call i8* @strerror(i64 %10)
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = tail call i32* @opendir(i8* %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = tail call %struct.dirent* @readdir(i32* %16)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %39, label %28
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %3
%24 = load i64, i64* @errno
%25 = tail call i8* @strerror(i64 %24)
%26 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
%27 = tail call i32 @exit(i32 2)
unreachable
28: ; preds = %18, %28
%29 = phi %struct.dirent* [ %37, %28 ], [ %19, %18 ]
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%31 = load i8*, i8** %30
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 2
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 1
%35 = load i32, i32* %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %33, i32 %35)
%37 = tail call %struct.dirent* @readdir(i32* %16)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %39, label %28
39: ; preds = %28, %18
%40 = load i64, i64* @errno
%41 = icmp eq i64 %40, 0
br i1 %41, label %47, label %42
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = tail call i8* @strerror(i64 %40)
%45 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %44)
%46 = tail call i32 @exit(i32 3)
unreachable
47: ; preds = %39
%48 = tail call i32 @closedir(i32* %16)
ret i32 0
}