#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 {
  char *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_proc_entry(struct netns_entry **, struct list *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(char *, char *);
int netns_add_proc_list(struct list *netns_list) {
  struct netns_entry *entry;
  struct dirent *de;
  DIR *dir;
  int err;
  dir = opendir("/proc");
  if (!dir)
    return 0;
  while ((de = readdir(dir)) != NULL) {
    if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
      continue;
    if (de->d_name[0] < '0' || de->d_name[0] > '9')
      continue;
    err = netns_get_proc_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_proc_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe8d(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1193 <netns_add_proc_list+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1274 <netns_add_proc_list+0x114>
jmp    1198 <netns_add_proc_list+0x38>
mov    -0x28(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1264 <netns_add_proc_list+0x104>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     11e7 <netns_add_proc_list+0x87>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2d(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11ec <netns_add_proc_list+0x8c>
jmp    1198 <netns_add_proc_list+0x38>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1212 <netns_add_proc_list+0xb2>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    1217 <netns_add_proc_list+0xb7>
jmp    1198 <netns_add_proc_list+0x38>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    -0x18(%rbp),%rdi
call   1030 <netns_get_proc_entry@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    123d <netns_add_proc_list+0xdd>
jmp    1198 <netns_add_proc_list+0x38>
cmpl   $0x0,-0x2c(%rbp)
je     1252 <netns_add_proc_list+0xf2>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1274 <netns_add_proc_list+0x114>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <list_append@plt>
jmp    1198 <netns_add_proc_list+0x38>
mov    -0x28(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netns_add_proc_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
lea    0xe8b(%rip),%rdi
call   1040 <opendir@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1213 <netns_add_proc_list+0xb3>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     120b <netns_add_proc_list+0xab>
lea    0xe6a(%rip),%rbx
lea    0xe62(%rip),%r12
jmp    11bd <netns_add_proc_list+0x5d>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     120b <netns_add_proc_list+0xab>
mov    (%rax),%r13
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b0 <netns_add_proc_list+0x50>
mov    %r13,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11b0 <netns_add_proc_list+0x50>
movzbl 0x0(%r13),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11b0 <netns_add_proc_list+0x50>
mov    %rsp,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <netns_get_proc_entry@plt>
test   %eax,%eax
js     11b0 <netns_add_proc_list+0x50>
jne    1225 <netns_add_proc_list+0xc5>
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1080 <list_append@plt>
jmp    11b0 <netns_add_proc_list+0x50>
mov    %rbp,%rdi
call   1050 <closedir@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r14d
jmp    1213 <netns_add_proc_list+0xb3>

LLVM IR (-O0):
%struct.list = type { i32 }
%struct.netns_entry = type { i32 }
%struct.dirent = type { i8* }
%struct.node = type { i32 }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @netns_add_proc_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 ([6 x i8], [6 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 %69
12: ; preds = %1
br label %13
13: ; preds = %61, %55, %46, %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 %66
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %5
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %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 i8*, i8** %25
%27 = call i32 @strcmp(i8* %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.dirent*, %struct.dirent** %5
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp slt i32 %36, 48
br i1 %37, label %46, label %38
38: ; preds = %30
%39 = load %struct.dirent*, %struct.dirent** %5
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp sgt i32 %44, 57
br i1 %45, label %46, label %47
46: ; preds = %38, %30
br label %13
47: ; preds = %38
%48 = load %struct.list*, %struct.list** %3
%49 = load %struct.dirent*, %struct.dirent** %5
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 @netns_get_proc_entry(%struct.netns_entry** %4, %struct.list* %48, i8* %51)
store i32 %52, i32* %7
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %47
br label %13
56: ; preds = %47
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i32, i32* %7
store i32 %60, i32* %2
br label %69
61: ; preds = %56
%62 = load %struct.list*, %struct.list** %3
%63 = load %struct.netns_entry*, %struct.netns_entry** %4
%64 = bitcast %struct.netns_entry* %63 to %struct.node*
%65 = call i32 @list_append(%struct.list* %62, %struct.node* %64)
br label %13
66: ; preds = %13
%67 = load i32*, i32** %6
%68 = call i32 @closedir(i32* %67)
store i32 0, i32* %2
br label %69
69: ; preds = %66, %59, %11
%70 = load i32, i32* %2
ret i32 %70
}

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