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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int chdir(char *);
int closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printFileDetails(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  DIR *directory;
  struct dirent *info;
  if (argc != 2) {
    printf("Usage: %s dirname\n", argv[0]);
    exit(EXIT_SUCCESS);
  }
  if (chdir(argv[1]) == -1) {
    do {
      perror("chdir");
      exit(EXIT_FAILURE);
    } while (0);
  }
  directory = opendir(".");
  while ((info = readdir(directory)) != NULL) {
    printFileDetails(info->d_name);
  }
  if (closedir(directory) == -1) {
    do {
      perror("closedir");
      exit(EXIT_FAILURE);
    } while (0);
  }
  return 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)
cmpl   $0x2,-0x8(%rbp)
je     11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    11f6 <main+0x76>
jmp    11dc <main+0x5c>
lea    0xe30(%rip),%rdi
call   1090 <perror@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe1c(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     122d <main+0xad>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1070 <printFileDetails@plt>
jmp    1206 <main+0x86>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
cmp    $0xffffffff,%eax
jne    125e <main+0xde>
jmp    1244 <main+0xc4>
lea    0xdd0(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    11de <main+0x5e>
mov    0x8(%rsi),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     11fb <main+0x7b>
lea    0xe7e(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
call   1080 <readdir@plt>
test   %rax,%rax
je     11c6 <main+0x46>
mov    (%rax),%edi
call   1070 <printFileDetails@plt>
mov    %rbx,%rdi
jmp    11b0 <main+0x30>
mov    %rbx,%rdi
call   1060 <closedir@plt>
cmp    $0xffffffff,%eax
je     1204 <main+0x84>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe18(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xe11(%rip),%rdi
jmp    120b <main+0x8b>
lea    0xe10(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [19 x i8] c"Usage: %s dirname\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [6 x i8] c"chdir\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [9 x i8] c"closedir\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 %17
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_SUCCESS
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @chdir(i8* %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %17
%30 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %6
br label %31
31: ; preds = %35, %29
%32 = load i32*, i32** %6
%33 = call %struct.dirent* @readdir(i32* %32)
store %struct.dirent* %33, %struct.dirent** %7
%34 = icmp ne %struct.dirent* %33, null
br i1 %34, label %35, label %40
35: ; preds = %31
%36 = load %struct.dirent*, %struct.dirent** %7
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @printFileDetails(i32 %38)
br label %31
40: ; preds = %31
%41 = load i32*, i32** %6
%42 = call i32 @closedir(i32* %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %40
br label %45
45: ; preds = %44
%46 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; No predecessors!
br label %50
50: ; preds = %49, %40
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [19 x i8] c"Usage: %s dirname\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [6 x i8] c"chdir\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [9 x i8] c"closedir\00"
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 i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_SUCCESS
%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 @chdir(i8* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %9
%19 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call %struct.dirent* @readdir(i32* %19)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %29, label %22
22: ; preds = %18, %22
%23 = phi %struct.dirent* [ %27, %22 ], [ %20, %18 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i32, i32* %24
%26 = tail call i32 @printFileDetails(i32 %25)
%27 = tail call %struct.dirent* @readdir(i32* %19)
%28 = icmp eq %struct.dirent* %27, null
br i1 %28, label %29, label %22
29: ; preds = %22, %18
%30 = tail call i32 @closedir(i32* %19)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = tail call i32 @exit(i32 %34)
unreachable
36: ; preds = %29
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}