#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 execl(char *, char *, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int setns(int, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int status;
  if (argc != 3) {
    printf("Usage: %s <namespace fd> <command>\n", argv[0]);
    return 1;
  }
  int fd = open(argv[1], O_RDONLY);
  if (!fd) {
    perror("open");
    return 1;
  }
  if ((status = setns(fd, 0))) {
    perror("setns");
    return status;
  }
  if ((status = execl(argv[2], argv[2], NULL))) {
    perror("exec");
    return status;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    122e <main+0xde>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11ca <main+0x7a>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    122e <main+0xde>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1040 <setns@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11f7 <main+0xa7>
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122e <main+0xde>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execl@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     122e <main+0xde>
lea    0xe0c(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11a7 <main+0x57>
mov    0x8(%rbx),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
je     11c4 <main+0x74>
xor    %r14d,%r14d
mov    %eax,%edi
xor    %esi,%esi
call   1040 <setns@plt>
test   %eax,%eax
jne    11d2 <main+0x82>
mov    0x10(%rbx),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execl@plt>
test   %eax,%eax
je     11bc <main+0x6c>
mov    %eax,%ebx
lea    0xe92(%rip),%rdi
call   1060 <perror@plt>
mov    %ebx,%r14d
jmp    11bc <main+0x6c>
mov    (%rbx),%rsi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
jmp    11b6 <main+0x66>
mov    %eax,%ebp
lea    0xe4e(%rip),%rdi
call   1060 <perror@plt>
mov    %ebp,%r14d
jmp    11bc <main+0x6c>

LLVM IR (-O0):
@.str = [36 x i8] c"Usage: %s <namespace fd> <command>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"setns\00"
@.str.3 = [5 x i8] c"exec\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %44
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %44
25: ; preds = %15
%26 = load i32, i32* %7
%27 = call i32 @setns(i32 %26, i32 0)
store i32 %27, i32* %6
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* %6
store i32 %31, i32* %3
br label %44
32: ; preds = %25
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @execl(i8* %35, i8* %38, i32* null)
store i32 %39, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %32
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* %6
store i32 %43, i32* %3
br label %44
44: ; preds = %10, %23, %29, %41, %32
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [36 x i8] c"Usage: %s <namespace fd> <command>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"setns\00"
@.str.3 = [5 x i8] c"exec\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %27
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %27
15: ; preds = %7
%16 = tail call i32 @setns(i32 %11, i32 0)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %27
20: ; preds = %15
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @execl(i8* %22, i8* %22, i32* null)
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %13, %18, %25, %20, %4
%28 = phi i32 [ 1, %4 ], [ %16, %18 ], [ %23, %25 ], [ 1, %13 ], [ 0, %20 ]
ret i32 %28
}