#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 node {
  int dummy;
};
struct netns_entry {
  int dummy;
};
struct list {
  int dummy;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ list_append(struct list *, struct node *);
int netns_get_var_entry(struct netns_entry **, struct list *,
                        int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int netns_add_var_list(struct list *netns_list) {
  struct netns_entry *entry;
  struct dirent *de;
  DIR *dir;
  int err;
  dir = opendir("/var/run/netns");
  if (!dir)
    return 0;
  while ((de = readdir(dir)) != NULL) {
    if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
      continue;
    err = netns_get_var_entry(&entry, netns_list, de->d_name);
    if (err < 0) {
      continue;
    }
    if (err)
      return err;
    list_append(netns_list, ((struct node *)(entry)));
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<netns_add_var_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1193 <netns_add_var_list+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1246 <netns_add_var_list+0xe6>
jmp    1198 <netns_add_var_list+0x38>
mov    -0x28(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1236 <netns_add_var_list+0xd6>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11e5 <netns_add_var_list+0x85>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11ea <netns_add_var_list+0x8a>
jmp    1198 <netns_add_var_list+0x38>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
call   1070 <netns_get_var_entry@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    120f <netns_add_var_list+0xaf>
jmp    1198 <netns_add_var_list+0x38>
cmpl   $0x0,-0x2c(%rbp)
je     1224 <netns_add_var_list+0xc4>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1246 <netns_add_var_list+0xe6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <list_append@plt>
jmp    1198 <netns_add_var_list+0x38>
mov    -0x28(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netns_add_var_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe8b(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbp
xor    %eax,%eax
test   %rbp,%rbp
je     120a <netns_add_var_list+0xaa>
mov    %rbp,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1200 <netns_add_var_list+0xa0>
mov    %rax,%r14
lea    0xe71(%rip),%r15
lea    0xe69(%rip),%r12
mov    %rsp,%r13
jmp    11c0 <netns_add_var_list+0x60>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1060 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     1200 <netns_add_var_list+0xa0>
mov    (%r14),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b0 <netns_add_var_list+0x50>
mov    (%r14),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11b0 <netns_add_var_list+0x50>
mov    (%r14),%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <netns_get_var_entry@plt>
test   %eax,%eax
js     11b0 <netns_add_var_list+0x50>
jne    120a <netns_add_var_list+0xaa>
mov    (%rsp),%rsi
mov    %rbx,%rdi
call   1080 <list_append@plt>
jmp    11b0 <netns_add_var_list+0x50>
mov    %rbp,%rdi
call   1040 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.list = type { i32 }
%struct.netns_entry = type { i32 }
%struct.dirent = type { i32 }
%struct.node = type { i32 }
@.str = [15 x i8] c"/var/run/netns\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @netns_add_var_list(%struct.list* %0) {
%2 = alloca %struct.netns_entry*
%3 = bitcast %struct.netns_entry** %2 to i8*
%4 = tail call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %35, label %6
6: ; preds = %1
%7 = call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %33, label %9
9: ; preds = %6
%10 = bitcast %struct.netns_entry** %2 to %struct.node**
br label %11
11: ; preds = %9, %21
%12 = phi %struct.dirent* [ %7, %9 ], [ %22, %21 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @strcmp(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %11
%18 = load i32, i32* %13
%19 = call i32 @strcmp(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %11, %17, %30, %24
%22 = call %struct.dirent* @readdir(i32* %4)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %33, label %11
24: ; preds = %17
%25 = load i32, i32* %13
%26 = call i32 @netns_get_var_entry(%struct.netns_entry** %2, %struct.list* %0, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %21, label %28
28: ; preds = %24
%29 = icmp eq i32 %26, 0
br i1 %29, label %30, label %35
30: ; preds = %28
%31 = load %struct.node*, %struct.node** %10
%32 = call i32 @list_append(%struct.list* %0, %struct.node* %31)
br label %21
33: ; preds = %21, %6
%34 = call i32 @closedir(i32* %4)
br label %35
35: ; preds = %28, %1, %33
%36 = phi i32 [ 0, %33 ], [ 0, %1 ], [ %26, %28 ]
ret i32 %36
}