#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 */
typedef int /*<<< orphan*/ ino_t;

/* Variables and functions */
int /*<<< orphan*/ current_ns_inode(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int inode_in_nspath(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int already_in_namespace(void) {
  int status;
  ino_t inode;
  if (!current_ns_inode(&inode))
    return 1;
  if ((status = inode_in_nspath(inode)) == 0) {
    return 0;
  } else {
    if (status == 1)
      fprintf(stderr,
              "nsdo"
              ": oops! i can run only in network namespaces not found in "
              "/var/run/netns"
              "\n");
    return 1;
  }
}


x86 assembly (clang, -O0):
<already_in_namespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0xc(%rbp),%rdi
call   1050 <current_ns_inode@plt>
cmp    $0x0,%eax
jne    1156 <already_in_namespace+0x26>
movl   $0x1,-0x4(%rbp)
jmp    119c <already_in_namespace+0x6c>
mov    -0xc(%rbp),%edi
call   1030 <inode_in_nspath@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jne    1176 <already_in_namespace+0x46>
movl   $0x0,-0x4(%rbp)
jmp    119c <already_in_namespace+0x6c>
cmpl   $0x1,-0x8(%rbp)
jne    1195 <already_in_namespace+0x65>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<already_in_namespace>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1050 <current_ns_inode@plt>
mov    $0x1,%ebx
test   %eax,%eax
je     1173 <already_in_namespace+0x43>
mov    0xc(%rsp),%edi
call   1030 <inode_in_nspath@plt>
test   %eax,%eax
je     1171 <already_in_namespace+0x41>
cmp    $0x1,%eax
jne    1173 <already_in_namespace+0x43>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1173 <already_in_namespace+0x43>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [78 x i8] c"nsdo: oops! i can run only in network namespaces not found in /var/run/netns\0A\00"
define i32 @already_in_namespace() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @current_ns_inode(i32* %3)
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
store i32 1, i32* %1
br label %19
7: ; preds = %0
%8 = load i32, i32* %3
%9 = call i32 @inode_in_nspath(i32 %8)
store i32 %9, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7
store i32 0, i32* %1
br label %19
12: ; preds = %7
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %12
store i32 1, i32* %1
br label %19
19: ; preds = %18, %11, %6
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [78 x i8] c"nsdo: oops! i can run only in network namespaces not found in /var/run/netns\0A\00"
define i32 @already_in_namespace() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @current_ns_inode(i32* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = load i32, i32* %1
%7 = call i32 @inode_in_nspath(i32 %6)
switch i32 %7, label %11 [
i32 0, label %12
i32 1, label %8
]
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %5, %8
br label %12
12: ; preds = %5, %0, %11
%13 = phi i32 [ 1, %11 ], [ 1, %0 ], [ %7, %5 ]
ret i32 %13
}