#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ setns(int, int /*<<< orphan*/);
int attachToNS(char *path) {
  int nsid;
  nsid = open(path, O_RDONLY);
  if (nsid < 0) {
    perror(path);
    return 1;
  }
  if (setns(nsid, 0) != 0) {
    perror("setns");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<attachToNS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1170 <attachToNS+0x40>
mov    -0x10(%rbp),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <attachToNS+0x73>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1030 <setns@plt>
cmp    $0x0,%rax
je     119c <attachToNS+0x6c>
lea    0xe75(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a3 <attachToNS+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attachToNS>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
test   %eax,%eax
js     1161 <attachToNS+0x31>
xor    %ebx,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1030 <setns@plt>
test   %rax,%rax
jne    115a <attachToNS+0x2a>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe9f(%rip),%rbx
mov    %rbx,%rdi
call   1050 <perror@plt>
mov    $0x1,%ebx
jmp    1156 <attachToNS+0x26>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [6 x i8] c"setns\00"
define i32 @attachToNS(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @perror(i8* %11)
store i32 1, i32* %2
br label %20
13: ; preds = %1
%14 = load i32, i32* %4
%15 = call i64 @setns(i32 %14, i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %20
19: ; preds = %13
store i32 0, i32* %2
br label %20
20: ; preds = %19, %17, %10
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [6 x i8] c"setns\00"
define i32 @attachToNS(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i64 @setns(i32 %3, i32 0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5, %1
%9 = phi i8* [ %0, %1 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %5 ]
%10 = tail call i32 @perror(i8* %9)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 0, %5 ], [ 1, %8 ]
ret i32 %12
}