#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 stat {
  scalar_t__ st_dev;
  scalar_t__ st_ino;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ net_path;
typedef int /*<<< orphan*/ name_path;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ ENOENT;
int MAXPATHLEN;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ fstat(int, struct stat *);
int /*<<< orphan*/ is_pid(char const *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(scalar_t__);
int netns_identify(int argc, char **argv) {
  const char *pidstr;
  char net_path[MAXPATHLEN];
  int netns;
  struct stat netst;
  DIR *dir;
  struct dirent *entry;
  if (argc < 1) {
    fprintf(stderr, "No pid specified\n");
    return -1;
  }
  if (argc > 1) {
    fprintf(stderr, "extra arguments specified\n");
    return -1;
  }
  pidstr = argv[0];
  if (!is_pid(pidstr)) {
    fprintf(stderr, "Specified string '%s' is not a pid\n", pidstr);
    return -1;
  }
  snprintf(net_path, sizeof(net_path), "/proc/%s/ns/net", pidstr);
  netns = open(net_path, O_RDONLY);
  if (netns < 0) {
    fprintf(stderr, "Cannot open network namespace: %s\n", strerror(errno));
    return -1;
  }
  if (fstat(netns, &netst) < 0) {
    fprintf(stderr, "Stat of netns failed: %s\n", strerror(errno));
    return -1;
  }
  dir = opendir("/var/run/netns");
  if (!dir) {
    if (errno == ENOENT)
      return 0;
    fprintf(stderr, "Failed to open directory %s:%s\n", "/var/run/netns",
            strerror(errno));
    return -1;
  }
  while ((entry = readdir(dir))) {
    char name_path[MAXPATHLEN];
    struct stat st;
    if (strcmp(entry->d_name, ".") == 0)
      continue;
    if (strcmp(entry->d_name, "..") == 0)
      continue;
    snprintf(name_path, sizeof(name_path), "%s/%s", "/var/run/netns",
             entry->d_name);
    if (stat(name_path, &st) != 0)
      continue;
    if ((st.st_dev == netst.st_dev) && (st.st_ino == netst.st_ino)) {
      printf("%s\n", entry->d_name);
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<netns_identify>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1239 <netns_identify+0x79>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
cmpl   $0x1,-0x8(%rbp)
jle    126d <netns_identify+0xad>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   10d0 <is_pid@plt>
cmp    $0x0,%eax
jne    12b8 <netns_identify+0xf8>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
lea    0xd81(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x80(%rbp),%rdi
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    133e <netns_identify+0x17e>
mov    0x2cd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2cbc(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
mov    -0x2c(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   10e0 <fstat@plt>
cmp    $0x0,%rax
jge    139c <netns_identify+0x1dc>
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x2c5e(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x90(%rbp),%edi
mov    %rax,%rdx
lea    0xd02(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
lea    0xcfb(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1433 <netns_identify+0x273>
mov    0x2c0a(%rip),%rax
mov    (%rax),%rax
mov    0x2bf0(%rip),%rcx
cmp    (%rcx),%rax
jne    13e4 <netns_identify+0x224>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
mov    0x2be5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2bce(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rcx
lea    0xc9b(%rip),%rsi
lea    0xc85(%rip),%rdx
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
jmp    1597 <netns_identify+0x3d7>
jmp    1438 <netns_identify+0x278>
mov    -0x48(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
je     1580 <netns_identify+0x3c0>
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xa8(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rax
mov    (%rax),%rdi
lea    0xc3b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    14ae <netns_identify+0x2ee>
movl   $0x2,-0x54(%rbp)
jmp    155f <netns_identify+0x39f>
mov    -0x50(%rbp),%rax
mov    (%rax),%rdi
lea    0xc11(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    14d7 <netns_identify+0x317>
movl   $0x2,-0x54(%rbp)
jmp    155f <netns_identify+0x39f>
mov    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rax
mov    %eax,%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%r8
lea    0xbdb(%rip),%rdx
lea    0xba2(%rip),%rcx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0xa0(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     1529 <netns_identify+0x369>
movl   $0x2,-0x54(%rbp)
jmp    155f <netns_identify+0x39f>
mov    -0x78(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    1558 <netns_identify+0x398>
mov    -0x70(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    1558 <netns_identify+0x398>
mov    -0x50(%rbp),%rax
mov    (%rax),%rsi
lea    0xb47(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x54(%rbp),%eax
test   %eax,%eax
je     157b <netns_identify+0x3bb>
jmp    1576 <netns_identify+0x3b6>
jmp    1438 <netns_identify+0x278>
jmp    1438 <netns_identify+0x278>
mov    -0x48(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x54(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netns_identify>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x2e08(%rip),%r12
mov    (%r12),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %edi,%edi
jle    1365 <netns_identify+0x1a5>
cmp    $0x1,%edi
jne    1377 <netns_identify+0x1b7>
mov    (%rsi),%r15
mov    %r15,%rdi
call   10d0 <is_pid@plt>
test   %eax,%eax
je     1390 <netns_identify+0x1d0>
lea    0xe39(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     13a5 <netns_identify+0x1e5>
lea    -0x58(%rbp),%rsi
mov    %eax,%edi
call   10e0 <fstat@plt>
test   %rax,%rax
js     13d2 <netns_identify+0x212>
lea    0xe42(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1411 <netns_identify+0x251>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     13c6 <netns_identify+0x206>
mov    %rax,%r13
mov    -0x58(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    12be <netns_identify+0xfe>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rsp
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
mov    0x2d28(%rip),%r12
je     13c6 <netns_identify+0x206>
mov    %rsp,%r14
mov    (%r12),%r15d
mov    %rsp,%r12
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x0(%r13),%rdi
lea    0xded(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12a0 <netns_identify+0xe0>
mov    0x0(%r13),%rdi
lea    0xdd7(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12a0 <netns_identify+0xe0>
mov    0x0(%r13),%r8
mov    %r12,%rdi
mov    %r15d,%esi
lea    0xdbf(%rip),%rdx
lea    0xd86(%rip),%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %r12,%rdi
lea    -0x48(%rbp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
jne    12a0 <netns_identify+0xe0>
mov    -0x38(%rbp),%rax
cmp    %rax,-0x48(%rbp)
jne    12a0 <netns_identify+0xe0>
mov    -0x30(%rbp),%rax
cmp    %rax,-0x40(%rbp)
jne    12a0 <netns_identify+0xe0>
mov    0x0(%r13),%rsi
lea    0xd3f(%rip),%rdi
call   1040 <printf@plt>
jmp    12a0 <netns_identify+0xe0>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
lea    0xc8b(%rip),%rsi
jmp    1387 <netns_identify+0x1c7>
mov    0x2c52(%rip),%rax
mov    (%rax),%edi
lea    0xc8b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    13fd <netns_identify+0x23d>
mov    0x2c39(%rip),%rax
mov    (%rax),%edi
lea    0xc8d(%rip),%rsi
mov    %r15,%rdx
jmp    13f6 <netns_identify+0x236>
mov    0x2c24(%rip),%rax
mov    (%rax),%ebx
mov    0x2c13(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xc9d(%rip),%rsi
jmp    13f1 <netns_identify+0x231>
mov    %rbx,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
jmp    1402 <netns_identify+0x242>
mov    0x2bf7(%rip),%rax
mov    (%rax),%ebx
mov    0x2be6(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xc93(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bb0(%rip),%rax
mov    (%rax),%rdi
mov    0x2b96(%rip),%rcx
xor    %eax,%eax
cmp    (%rcx),%rdi
je     1402 <netns_identify+0x242>
mov    0x2ba0(%rip),%rax
mov    (%rax),%ebx
call   10c0 <strerror@plt>
lea    0xc6f(%rip),%rsi
lea    0xc59(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    13fd <netns_identify+0x23d>

LLVM IR (-O0):
%struct.stat = type { i64, i64 }
%struct.dirent = type { i8* }
@MAXPATHLEN = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"No pid specified\0A\00"
@.str.1 = [27 x i8] c"extra arguments specified\0A\00"
@.str.2 = [36 x i8] c"Specified string '%s' is not a pid\0A\00"
@.str.3 = [16 x i8] c"/proc/%s/ns/net\00"
@O_RDONLY = global i32 0
@.str.4 = [35 x i8] c"Cannot open network namespace: %s\0A\00"
@errno = global i64 0
@.str.5 = [26 x i8] c"Stat of netns failed: %s\0A\00"
@.str.6 = [15 x i8] c"/var/run/netns\00"
@ENOENT = global i64 0
@.str.7 = [32 x i8] c"Failed to open directory %s:%s\0A\00"
@.str.8 = [2 x i8] c".\00"
@.str.9 = [3 x i8] c"..\00"
@.str.10 = [6 x i8] c"%s/%s\00"
@.str.11 = [4 x i8] c"%s\0A\00"
define i32 @netns_identify(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca %struct.stat
%11 = alloca i32*
%12 = alloca %struct.dirent*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i64
%16 = alloca %struct.stat
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* @MAXPATHLEN
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %7
%20 = alloca i8, i64 %18
store i64 %18, i64* %8
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %13
br label %136
26: ; preds = %2
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %13
br label %136
32: ; preds = %26
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
store i8* %35, i8** %6
%36 = load i8*, i8** %6
%37 = call i32 @is_pid(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %6
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %41)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %136
43: ; preds = %32
%44 = trunc i64 %18 to i32
%45 = load i8*, i8** %6
%46 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %20, i32 %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i32, i32* @O_RDONLY
%48 = call i32 @open(i8* %20, i32 %47)
store i32 %48, i32* %9
%49 = load i32, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %43
%52 = load i32, i32* @stderr
%53 = load i64, i64* @errno
%54 = call i8* @strerror(i64 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %54)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %136
56: ; preds = %43
%57 = load i32, i32* %9
%58 = call i64 @fstat(i32 %57, %struct.stat* %10)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = load i64, i64* @errno
%63 = call i8* @strerror(i64 %62)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %63)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %136
65: ; preds = %56
%66 = call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
store i32* %66, i32** %11
%67 = load i32*, i32** %11
%68 = icmp ne i32* %67, null
br i1 %68, label %79, label %69
69: ; preds = %65
%70 = load i64, i64* @errno
%71 = load i64, i64* @ENOENT
%72 = icmp eq i64 %70, %71
br i1 %72, label %73, label %74
73: ; preds = %69
store i32 0, i32* %3
store i32 1, i32* %13
br label %136
74: ; preds = %69
%75 = load i32, i32* @stderr
%76 = load i64, i64* @errno
%77 = call i8* @strerror(i64 %76)
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %77)
store i32 -1, i32* %3
store i32 1, i32* %13
br label %136
79: ; preds = %65
br label %80
80: ; preds = %132, %129, %79
%81 = load i32*, i32** %11
%82 = call %struct.dirent* @readdir(i32* %81)
store %struct.dirent* %82, %struct.dirent** %12
%83 = icmp ne %struct.dirent* %82, null
br i1 %83, label %84, label %133
84: ; preds = %80
%85 = load i32, i32* @MAXPATHLEN
%86 = zext i32 %85 to i64
%87 = call i8* @llvm.stacksave()
store i8* %87, i8** %14
%88 = alloca i8, i64 %86
store i64 %86, i64* %15
%89 = load %struct.dirent*, %struct.dirent** %12
%90 = getelementptr inbounds %struct.dirent, %struct.dirent* %89, i32 0, i32 0
%91 = load i8*, i8** %90
%92 = call i64 @strcmp(i8* %91, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%93 = icmp eq i64 %92, 0
br i1 %93, label %94, label %95
94: ; preds = %84
store i32 2, i32* %13
br label %129
95: ; preds = %84
%96 = load %struct.dirent*, %struct.dirent** %12
%97 = getelementptr inbounds %struct.dirent, %struct.dirent* %96, i32 0, i32 0
%98 = load i8*, i8** %97
%99 = call i64 @strcmp(i8* %98, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%100 = icmp eq i64 %99, 0
br i1 %100, label %101, label %102
101: ; preds = %95
store i32 2, i32* %13
br label %129
102: ; preds = %95
%103 = trunc i64 %86 to i32
%104 = load %struct.dirent*, %struct.dirent** %12
%105 = getelementptr inbounds %struct.dirent, %struct.dirent* %104, i32 0, i32 0
%106 = load i8*, i8** %105
%107 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %88, i32 %103, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %106)
%108 = call i64 @stat(i8* %88, %struct.stat* %16)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %102
store i32 2, i32* %13
br label %129
111: ; preds = %102
%112 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%113 = load i64, i64* %112
%114 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%115 = load i64, i64* %114
%116 = icmp eq i64 %113, %115
br i1 %116, label %117, label %128
117: ; preds = %111
%118 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 1
%119 = load i64, i64* %118
%120 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%121 = load i64, i64* %120
%122 = icmp eq i64 %119, %121
br i1 %122, label %123, label %128
123: ; preds = %117
%124 = load %struct.dirent*, %struct.dirent** %12
%125 = getelementptr inbounds %struct.dirent, %struct.dirent* %124, i32 0, i32 0
%126 = load i8*, i8** %125
%127 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %126)
br label %128
128: ; preds = %123, %117, %111
store i32 0, i32* %13
br label %129
129: ; preds = %128, %110, %101, %94
%130 = load i8*, i8** %14
%131 = load i32, i32* %13
switch i32 %131, label %139 [
i32 0, label %132
i32 2, label %80
]
132: ; preds = %129
br label %80
133: ; preds = %80
%134 = load i32*, i32** %11
%135 = call i32 @closedir(i32* %134)
store i32 0, i32* %3
store i32 1, i32* %13
br label %136
136: ; preds = %133, %74, %73, %60, %51, %39, %29, %23
%137 = load i8*, i8** %7
%138 = load i32, i32* %3
ret i32 %138
139: ; preds = %129
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64, i64 }
%struct.dirent = type { i8* }
@MAXPATHLEN = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"No pid specified\0A\00"
@.str.1 = [27 x i8] c"extra arguments specified\0A\00"
@.str.2 = [36 x i8] c"Specified string '%s' is not a pid\0A\00"
@.str.3 = [16 x i8] c"/proc/%s/ns/net\00"
@O_RDONLY = global i32 0
@.str.4 = [35 x i8] c"Cannot open network namespace: %s\0A\00"
@errno = global i64 0
@.str.5 = [26 x i8] c"Stat of netns failed: %s\0A\00"
@.str.6 = [15 x i8] c"/var/run/netns\00"
@ENOENT = global i64 0
@.str.7 = [32 x i8] c"Failed to open directory %s:%s\0A\00"
@.str.8 = [2 x i8] c".\00"
@.str.9 = [3 x i8] c"..\00"
@.str.10 = [6 x i8] c"%s/%s\00"
@.str.11 = [4 x i8] c"%s\0A\00"
define i32 @netns_identify(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = bitcast %struct.stat* %3 to i8*
%9 = icmp slt i32 %0, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %98
13: ; preds = %2
%14 = icmp eq i32 %0, 1
br i1 %14, label %18, label %15
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %98
18: ; preds = %13
%19 = load i8*, i8** %1
%20 = tail call i32 @is_pid(i8* %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %98
25: ; preds = %18
%26 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %7, i32 %27)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i64, i64* @errno
%33 = call i8* @strerror(i64 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %98
35: ; preds = %25
%36 = call i64 @fstat(i32 %28, %struct.stat* %3)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = load i64, i64* @errno
%41 = call i8* @strerror(i64 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %41)
br label %98
43: ; preds = %35
%44 = call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %57, label %46
46: ; preds = %43
%47 = call %struct.dirent* @readdir(i32* %44)
%48 = icmp eq %struct.dirent* %47, null
br i1 %48, label %96, label %49
49: ; preds = %46
%50 = bitcast %struct.stat* %4 to i8*
%51 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%52 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%53 = load i64, i64* %52
%54 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%55 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%56 = load i64, i64* %55
br label %65
57: ; preds = %43
%58 = load i64, i64* @errno
%59 = load i64, i64* @ENOENT
%60 = icmp eq i64 %58, %59
br i1 %60, label %98, label %61
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = call i8* @strerror(i64 %58)
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %63)
br label %98
65: ; preds = %49, %93
%66 = phi %struct.dirent* [ %47, %49 ], [ %94, %93 ]
%67 = load i32, i32* @MAXPATHLEN
%68 = zext i32 %67 to i64
%69 = call i8* @llvm.stacksave()
%70 = alloca i8, i64 %68
%71 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i64 0, i32 0
%72 = load i8*, i8** %71
%73 = call i64 @strcmp(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%74 = icmp eq i64 %73, 0
br i1 %74, label %93, label %75
75: ; preds = %65
%76 = load i8*, i8** %71
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %93, label %79
79: ; preds = %75
%80 = load i8*, i8** %71
%81 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %70, i32 %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %80)
%82 = call i64 @stat(i8* %70, %struct.stat* %4)
%83 = icmp eq i64 %82, 0
%84 = load i64, i64* %51
%85 = icmp eq i64 %84, %53
%86 = select i1 %83, i1 %85, i1 false
%87 = load i64, i64* %54
%88 = icmp eq i64 %87, %56
%89 = select i1 %86, i1 %88, i1 false
br i1 %89, label %90, label %93
90: ; preds = %79
%91 = load i8*, i8** %71
%92 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %90, %79, %75, %65
%94 = call %struct.dirent* @readdir(i32* %44)
%95 = icmp eq %struct.dirent* %94, null
br i1 %95, label %96, label %65
96: ; preds = %93, %46
%97 = call i32 @closedir(i32* %44)
br label %98
98: ; preds = %57, %96, %61, %38, %30, %22, %15, %10
%99 = phi i32 [ -1, %10 ], [ -1, %15 ], [ -1, %30 ], [ -1, %38 ], [ 0, %96 ], [ -1, %61 ], [ -1, %22 ], [ 0, %57 ]
ret i32 %99
}