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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int arg;
  for (arg = 1; arg < argc; arg++) {
    DIR *d;
    if ((d = opendir(argv[arg])) == NULL) {
      fprintf(stderr, "opendir( '%s' ) failed\n", argv[arg]);
    } else {
      struct dirent *de;
      while ((de = readdir(d)) != NULL) {
        printf("name '%s' type 0x%08x\n", de->d_name, de->d_type);
      }
      closedir(d);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1215 <main+0xc5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11be <main+0x6e>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe4c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1202 <main+0xb2>
jmp    11c3 <main+0x73>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f9 <main+0xa9>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
jmp    11c3 <main+0x73>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
jmp    1207 <main+0xb7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11e7 <main+0x97>
mov    %rsi,%r15
mov    %edi,%r13d
mov    $0x1,%ebp
lea    0xe8a(%rip),%r14
lea    0xe9b(%rip),%r12
jmp    1191 <main+0x41>
nop
mov    %rbx,%rdi
call   1050 <closedir@plt>
add    $0x1,%rbp
cmp    %r13,%rbp
je     11e7 <main+0x97>
mov    (%r15,%rbp,8),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11d0 <main+0x80>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1180 <main+0x30>
mov    (%rax),%rsi
mov    0x8(%rax),%edx
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11b0 <main+0x60>
nopl   (%rax)
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    (%r15,%rbp,8),%rdx
mov    %r14,%rsi
call   1060 <fprintf@plt>
jmp    1188 <main+0x38>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"opendir( '%s' ) failed\0A\00"
@.str.1 = [23 x i8] c"name '%s' type 0x%08x\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
br label %9
9: ; preds = %46, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %49
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32* @opendir(i8* %18)
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %29
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %45
29: ; preds = %13
br label %30
30: ; preds = %34, %29
%31 = load i32*, i32** %7
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %8
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load %struct.dirent*, %struct.dirent** %8
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = load %struct.dirent*, %struct.dirent** %8
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %37, i32 %40)
br label %30
42: ; preds = %30
%43 = load i32*, i32** %7
%44 = call i32 @closedir(i32* %43)
br label %45
45: ; preds = %42, %21
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %9
49: ; preds = %9
ret i32 0
}

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