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


x86 assembly (clang, -O0):
<netns_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1186 <netns_list+0x36>
movl   $0x0,-0x4(%rbp)
jmp    120e <netns_list+0xbe>
jmp    118b <netns_list+0x3b>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11fe <netns_list+0xae>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe60(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11c4 <netns_list+0x74>
jmp    118b <netns_list+0x3b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe3d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e6 <netns_list+0x96>
jmp    118b <netns_list+0x3b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    118b <netns_list+0x3b>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netns_list>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xea0(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11e5 <netns_list+0x95>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11dd <netns_list+0x8d>
mov    %rax,%rbx
lea    0xe8c(%rip),%r14
lea    0xe84(%rip),%r15
lea    0xe80(%rip),%r12
jmp    11b0 <netns_list+0x60>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11dd <netns_list+0x8d>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <netns_list+0x50>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <netns_list+0x50>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11a0 <netns_list+0x50>
mov    %r13,%rdi
call   1050 <closedir@plt>
xor    %eax,%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/netns\00"
@.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 @netns_list(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.dirent*
%7 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i32 0, i32* %3
br label %39
12: ; preds = %2
br label %13
13: ; preds = %31, %30, %23, %12
%14 = load i32*, i32** %7
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %6
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %36
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %6
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %13
24: ; preds = %17
%25 = load %struct.dirent*, %struct.dirent** %6
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %13
31: ; preds = %24
%32 = load %struct.dirent*, %struct.dirent** %6
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %13
36: ; preds = %13
%37 = load i32*, i32** %7
%38 = call i32 @closedir(i32* %37)
store i32 0, i32* %3
br label %39
39: ; preds = %36, %11
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"/var/run/netns\00"
@.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 @netns_list(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %24, label %8
8: ; preds = %5, %21
%9 = phi %struct.dirent* [ %22, %21 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %14
%19 = load i8*, i8** %10
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %8, %14
%22 = tail call %struct.dirent* @readdir(i32* %3)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %24, label %8
24: ; preds = %21, %5
%25 = tail call i32 @closedir(i32* %3)
br label %26
26: ; preds = %2, %24
ret i32 0
}