#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 EXIT_SUCCESS;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ namespace_alive(char *);
int /*<<< orphan*/ namespace_cleanup(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int list(void) {
  struct dirent *entry;
  DIR *dir;
  dir = opendir("/var/run/pidns");
  if (!dir)
    return EXIT_SUCCESS;
  while ((entry = readdir(dir)) != NULL) {
    if (strcmp(entry->d_name, ".") == 0)
      continue;
    if (strcmp(entry->d_name, "..") == 0)
      continue;
    if (namespace_alive(entry->d_name) == 0) {
      printf("%s\n", entry->d_name);
    } else {
      namespace_cleanup(entry->d_name);
    }
  }
  closedir(dir);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <list+0x34>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1258 <list+0xe8>
jmp    11a9 <list+0x39>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1243 <list+0xd3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe42(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11e2 <list+0x72>
jmp    11a9 <list+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1204 <list+0x94>
jmp    11a9 <list+0x39>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <namespace_alive@plt>
cmp    $0x0,%rax
jne    1232 <list+0xc2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdea(%rip),%rdi
call   1040 <printf@plt>
jmp    123e <list+0xce>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <namespace_cleanup@plt>
jmp    11a9 <list+0x39>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe80(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     121a <list+0xaa>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1212 <list+0xa2>
mov    %rax,%rbx
lea    0xe68(%rip),%r14
lea    0xe60(%rip),%r15
lea    0xe5c(%rip),%r12
jmp    11d8 <list+0x68>
nopl   0x0(%rax,%rax,1)
mov    %rsi,%rdi
call   1090 <namespace_cleanup@plt>
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1212 <list+0xa2>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11c8 <list+0x58>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11c8 <list+0x58>
mov    (%rbx),%rdi
call   1060 <namespace_alive@plt>
mov    (%rbx),%rsi
test   %rax,%rax
jne    11c0 <list+0x50>
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11c8 <list+0x58>
mov    %r13,%rdi
call   1050 <closedir@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"/var/run/pidns\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @list() {
%1 = alloca i32
%2 = alloca %struct.dirent*
%3 = alloca i32*
%4 = call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = load i32, i32* @EXIT_SUCCESS
store i32 %8, i32* %1
br label %49
9: ; preds = %0
br label %10
10: ; preds = %44, %27, %20, %9
%11 = load i32*, i32** %3
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %2
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %45
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %2
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
br label %10
21: ; preds = %14
%22 = load %struct.dirent*, %struct.dirent** %2
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
br label %10
28: ; preds = %21
%29 = load %struct.dirent*, %struct.dirent** %2
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i64 @namespace_alive(i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load %struct.dirent*, %struct.dirent** %2
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %44
39: ; preds = %28
%40 = load %struct.dirent*, %struct.dirent** %2
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i32 @namespace_cleanup(i8* %42)
br label %44
44: ; preds = %39, %34
br label %10
45: ; preds = %10
%46 = load i32*, i32** %3
%47 = call i32 @closedir(i32* %46)
%48 = load i32, i32* @EXIT_SUCCESS
store i32 %48, i32* %1
br label %49
49: ; preds = %45, %7
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"/var/run/pidns\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @list() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %30, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %28, label %6
6: ; preds = %3, %25
%7 = phi %struct.dirent* [ %26, %25 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %6
%13 = load i8*, i8** %8
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = load i8*, i8** %8
%18 = tail call i64 @namespace_alive(i8* %17)
%19 = icmp eq i64 %18, 0
%20 = load i8*, i8** %8
br i1 %19, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %25
23: ; preds = %16
%24 = tail call i32 @namespace_cleanup(i8* %20)
br label %25
25: ; preds = %21, %23, %6, %12
%26 = tail call %struct.dirent* @readdir(i32* %1)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %28, label %6
28: ; preds = %25, %3
%29 = tail call i32 @closedir(i32* %1)
br label %30
30: ; preds = %0, %28
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}