#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 stat {
  int st_ino;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char name_buf[1024];
  DIR *dir;
  struct dirent *dentry;
  struct stat file_info;
  int status = 0;
  if (argc <= 1) {
    fprintf(stderr, "%s: missing argument: dir\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  dir = opendir(argv[1]);
  if (!dir)
    do {
      perror("opendir");
      exit(EXIT_FAILURE);
    } while (0);
  for (;;) {
    dentry = readdir(dir);
    if (!dentry)
      break;
    sprintf(name_buf, "%s/%s", argv[1], dentry->d_name);
    status = stat(name_buf, &file_info);
    printf("%d %s\n", file_info.st_ino, dentry->d_name);
    if (status != 0)
      do {
        perror("stat");
        exit(EXIT_FAILURE);
      } while (0);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x42c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     11d7 <main+0x57>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    1218 <main+0x98>
jmp    11fe <main+0x7e>
lea    0xe16(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    121d <main+0x9d>
mov    -0x418(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jne    1243 <main+0xc3>
jmp    12ce <main+0x14e>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x420(%rbp),%rax
mov    (%rax),%rcx
lea    0xdc0(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x428(%rbp),%rsi
call   1060 <stat@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x428(%rbp),%esi
mov    -0x420(%rbp),%rax
mov    (%rax),%rdx
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x42c(%rbp)
je     12c9 <main+0x149>
jmp    12af <main+0x12f>
lea    0xd7a(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    121d <main+0x9d>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11b6 <main+0x36>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe54(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1236 <main+0xb6>
mov    0x8(%r14),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
jne    11cd <main+0x4d>
lea    0xe50(%rip),%rdi
jmp    1231 <main+0xb1>
mov    %rax,%r12
lea    0x10(%rsp),%rbx
lea    0xe4d(%rip),%rbp
nopl   0x0(%rax)
mov    %r12,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1244 <main+0xc4>
mov    %rax,%r15
mov    0x8(%r14),%rdx
mov    (%rax),%rcx
mov    %rbx,%rdi
lea    0xe22(%rip),%rsi
call   1090 <sprintf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
mov    %eax,%r13d
mov    0x8(%rsp),%esi
mov    (%r15),%rdx
mov    %rbp,%rdi
call   1040 <printf@plt>
test   %r13d,%r13d
je     11e0 <main+0x60>
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [27 x i8] c"%s: missing argument: dir\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"opendir\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [7 x i8] c"%d %s\0A\00"
@.str.4 = [5 x i8] c"stat\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32* @opendir(i8* %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %25
21: ; preds = %14
%22 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %19, %28
%26 = tail call %struct.dirent* @readdir(i32* %17)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %42, label %28
28: ; preds = %25
%29 = load i8*, i8** %15
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i64 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %29, i8* %31)
%33 = call i32 @stat(i8* %5, %struct.stat* %4)
%34 = load i32, i32* %20
%35 = load i8*, i8** %30
%36 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %34, i8* %35)
%37 = icmp eq i32 %33, 0
br i1 %37, label %25, label %38
38: ; preds = %28
%39 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = tail call i32 @exit(i32 %40)
unreachable
42: ; preds = %25
%43 = load i32, i32* @EXIT_SUCCESS
%44 = tail call i32 @exit(i32 %43)
unreachable
}