#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*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  DIR *dp;
  struct dirent *dirp;
  printf("Directory content:\n");
  if ((dp = opendir(".")) != NULL) {
    while ((dirp = readdir(dp)) != NULL) {
      if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
        continue;
      printf("%s\n", dirp->d_name);
    }
    closedir(dp);
  } else
    fprintf(stderr, "Can't open current directory\n");
}


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)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1221 <main+0xc1>
jmp    11a3 <main+0x43>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1213 <main+0xb3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11f4 <main+0x94>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f9 <main+0x99>
jmp    11a3 <main+0x43>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a3 <main+0x43>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
jmp    1236 <main+0xd6>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
lea    0xe86(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11f4 <main+0x94>
mov    %rax,%r12
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11ea <main+0x8a>
mov    %rax,%rbx
lea    0xe62(%rip),%r14
lea    0xe5a(%rip),%r15
jmp    11c0 <main+0x60>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ea <main+0x8a>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11b0 <main+0x50>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11b0 <main+0x50>
mov    (%rbx),%rdi
call   1030 <puts@plt>
jmp    11b0 <main+0x50>
mov    %r12,%rdi
call   1050 <closedir@plt>
jmp    1209 <main+0xa9>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [20 x i8] c"Directory content:\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Can't open current directory\0A\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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %37
11: ; preds = %2
br label %12
12: ; preds = %29, %28, %11
%13 = load i32*, i32** %6
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %7
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %34
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %7
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = load %struct.dirent*, %struct.dirent** %7
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22, %16
br label %12
29: ; preds = %22
%30 = load %struct.dirent*, %struct.dirent** %7
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %32)
br label %12
34: ; preds = %12
%35 = load i32*, i32** %6
%36 = call i32 @closedir(i32* %35)
br label %40
37: ; preds = %2
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Can't open current directory\0A\00"
@str = [19 x i8] c"Directory content:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = tail call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %25, label %9
9: ; preds = %6, %19
%10 = phi %struct.dirent* [ %20, %19 ], [ %7, %6 ]
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %9
%16 = load i8*, i8** %11
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %9, %15, %22
%20 = tail call %struct.dirent* @readdir(i32* %4)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %25, label %9
22: ; preds = %15
%23 = load i8*, i8** %11
%24 = tail call i32 @puts(i8* dereferenceable(1) %23)
br label %19
25: ; preds = %19, %6
%26 = tail call i32 @closedir(i32* %4)
br label %30
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %27, %25
ret i32 0
}