#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_ino;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef scalar_t__ ino_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int asprintf(char **, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, int /*<<< orphan*/);
char *strerror(scalar_t__);
int inode_in_nspath(ino_t inode) {
  DIR *nsdir;
  char *nspath;
  struct dirent *ns;
  struct stat nsstat;
  if ((nsdir = opendir("/var/run/netns")) == NULL) {
    perror("nsdo"
           ": opendir(\""
           "/var/run/netns"
           "\")");
    return -1;
  }
  while ((ns = readdir(nsdir)) != NULL) {
    if (strcmp(".", ns->d_name) == 0 || strcmp("..", ns->d_name) == 0)
      continue;
    if (asprintf(&nspath, "%s/%s", "/var/run/netns", ns->d_name) == -1) {
      perror("nsdo"
             ": asprintf");
      return -1;
    }
    if (stat(nspath, &nsstat) == -1) {
      fprintf(stderr,
              "nsdo"
              ": stat(\"%s\"): %s\n",
              nspath, strerror(errno));
      return -1;
    }
    free(nspath);
    if (nsstat.st_ino == inode)
      return 1;
  }
  if (errno != 0) {
    perror("nsdo"
           ": readdir(\""
           "/var/run/netns"
           "\")");
    return -1;
  }
  closedir(nsdir);
  return 0;
}


x86 assembly (clang, -O0):
<inode_in_nspath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe4d(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11de <inode_in_nspath+0x3e>
lea    0xe42(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <inode_in_nspath+0x191>
jmp    11e3 <inode_in_nspath+0x43>
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12f8 <inode_in_nspath+0x158>
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xe29(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1232 <inode_in_nspath+0x92>
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
lea    0xe0c(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1237 <inode_in_nspath+0x97>
jmp    11e3 <inode_in_nspath+0x43>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rdi
lea    0xdea(%rip),%rsi
lea    0xdb1(%rip),%rdx
call   10a0 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    1275 <inode_in_nspath+0xd5>
lea    0xdd4(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <inode_in_nspath+0x191>
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    12d0 <inode_in_nspath+0x130>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd88(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <inode_in_nspath+0x191>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    12f3 <inode_in_nspath+0x153>
movl   $0x1,-0x4(%rbp)
jmp    1331 <inode_in_nspath+0x191>
jmp    11e3 <inode_in_nspath+0x43>
mov    0x2cd9(%rip),%rax
cmpq   $0x0,(%rax)
je     1321 <inode_in_nspath+0x181>
lea    0xd4d(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <inode_in_nspath+0x191>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inode_in_nspath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xe48(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12df <inode_in_nspath+0x13f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1281 <inode_in_nspath+0xe1>
mov    %rax,%r13
lea    0xe4c(%rip),%r15
lea    0xe44(%rip),%r12
lea    0x10(%rsp),%rbp
jmp    1210 <inode_in_nspath+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1281 <inode_in_nspath+0xe1>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1200 <inode_in_nspath+0x60>
mov    0x0(%r13),%esi
mov    %r12,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1200 <inode_in_nspath+0x60>
mov    0x0(%r13),%ecx
lea    0x8(%rsp),%rdi
lea    0xdf0(%rip),%rsi
lea    0xdb7(%rip),%rdx
call   10a0 <asprintf@plt>
cmp    $0xffffffff,%eax
je     12fb <inode_in_nspath+0x15b>
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     12a7 <inode_in_nspath+0x107>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
cmp    %r14,0x10(%rsp)
jne    1200 <inode_in_nspath+0x60>
mov    $0x1,%eax
jmp    1298 <inode_in_nspath+0xf8>
mov    0x2d50(%rip),%rax
cmpq   $0x0,(%rax)
jne    12e8 <inode_in_nspath+0x148>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d32(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rbp
mov    0x2d1c(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xd7c(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1298 <inode_in_nspath+0xf8>
lea    0xd29(%rip),%rdi
jmp    12ef <inode_in_nspath+0x14f>
lea    0xd6e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%eax
jmp    1298 <inode_in_nspath+0xf8>
lea    0xd36(%rip),%rdi
jmp    12ef <inode_in_nspath+0x14f>

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stat = type { i64 }
@.str = [15 x i8] c"/var/run/netns\00"
@.str.1 = [32 x i8] c"nsdo: opendir(\22/var/run/netns\22)\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [15 x i8] c"nsdo: asprintf\00"
@stderr = global i32 0
@.str.6 = [22 x i8] c"nsdo: stat(\22%s\22): %s\0A\00"
@errno = global i64 0
@.str.7 = [32 x i8] c"nsdo: readdir(\22/var/run/netns\22)\00"
define i32 @inode_in_nspath(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca %struct.dirent*
%7 = alloca %struct.stat
store i64 %0, i64* %3
%8 = call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %65
12: ; preds = %1
br label %13
13: ; preds = %56, %29, %12
%14 = load i32*, i32** %4
%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 %57
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %6
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %17
%24 = load %struct.dirent*, %struct.dirent** %6
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23, %17
br label %13
30: ; preds = %23
%31 = load %struct.dirent*, %struct.dirent** %6
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %2
br label %65
38: ; preds = %30
%39 = load i8*, i8** %5
%40 = call i32 @stat(i8* %39, %struct.stat* %7)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %5
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %44, i8* %46)
store i32 -1, i32* %2
br label %65
48: ; preds = %38
%49 = load i8*, i8** %5
%50 = call i32 @free(i8* %49)
%51 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* %3
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %56
55: ; preds = %48
store i32 1, i32* %2
br label %65
56: ; preds = %48
br label %13
57: ; preds = %13
%58 = load i64, i64* @errno
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %57
%61 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %2
br label %65
62: ; preds = %57
%63 = load i32*, i32** %4
%64 = call i32 @closedir(i32* %63)
store i32 0, i32* %2
br label %65
65: ; preds = %62, %60, %55, %42, %36, %10
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
%struct.stat = type { i64 }
%struct.dirent = type { i32 }
@.str = [15 x i8] c"/var/run/netns\00"
@.str.1 = [32 x i8] c"nsdo: opendir(\22/var/run/netns\22)\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [15 x i8] c"nsdo: asprintf\00"
@stderr = global i32 0
@.str.6 = [22 x i8] c"nsdo: stat(\22%s\22): %s\0A\00"
@errno = global i64 0
@.str.7 = [32 x i8] c"nsdo: readdir(\22/var/run/netns\22)\00"
define i32 @inode_in_nspath(i64 %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = bitcast i8** %2 to i8*
%5 = bitcast %struct.stat* %3 to i8*
%6 = tail call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %13, label %8
8: ; preds = %1
%9 = call %struct.dirent* @readdir(i32* %6)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %49, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %15
13: ; preds = %1
%14 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %56
15: ; preds = %11, %25
%16 = phi %struct.dirent* [ %9, %11 ], [ %26, %25 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %15
%22 = load i32, i32* %17
%23 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %15, %21, %44
%26 = call %struct.dirent* @readdir(i32* %6)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %49, label %15
28: ; preds = %21
%29 = load i32, i32* %17
%30 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %56
34: ; preds = %28
%35 = load i8*, i8** %2
%36 = call i32 @stat(i8* %35, %struct.stat* %3)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %2
%41 = load i64, i64* @errno
%42 = call i8* @strerror(i64 %41)
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i8* %40, i8* %42)
br label %56
44: ; preds = %34
%45 = load i8*, i8** %2
%46 = call i32 @free(i8* %45)
%47 = load i64, i64* %12
%48 = icmp eq i64 %47, %0
br i1 %48, label %56, label %25
49: ; preds = %25, %8
%50 = load i64, i64* @errno
%51 = icmp eq i64 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %56
54: ; preds = %49
%55 = call i32 @closedir(i32* %6)
br label %56
56: ; preds = %44, %54, %52, %38, %32, %13
%57 = phi i32 [ -1, %13 ], [ -1, %32 ], [ -1, %38 ], [ -1, %52 ], [ 0, %54 ], [ 1, %44 ]
ret i32 %57
}