#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;
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ setns(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  int fd;
  if (argc < 3) {
    fprintf(stderr, "%s <mount_namespace_fd> <-m|-u> <mount_args>\n", argv[0]);
    exit(-1);
  }
  fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    perror("open mount namespace fd failed");
    exit(-1);
  }
  if (setns(fd, 0) != 0) {
    perror("failed to switch namespace");
    exit(-1);
  }
  if (strncmp(argv[2], "-m", 2) == 0) {
    argv[2] = "mount";
    if (execvp("mount", &argv[2]) != 0) {
      perror("mount failed");
      exit(-1);
    }
  } else if (strncmp(argv[2], "-u", 2) == 0) {
    argv[2] = "umount";
    if (execvp("umount", &argv[2]) != 0) {
      perror("umount failed");
      exit(-1);
    }
  } else {
    fprintf(stderr, "unrecognize parameter!");
    exit(-1);
  }
}


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)
jge    11b8 <main+0x48>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f1 <main+0x81>
lea    0xe4c(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1040 <setns@plt>
cmp    $0x0,%rax
je     121b <main+0xab>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1286 <main+0x116>
mov    -0x10(%rbp),%rax
lea    0xe26(%rip),%rcx
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
lea    0xe13(%rip),%rdi
call   1080 <execvp@plt>
cmp    $0x0,%rax
je     1281 <main+0x111>
lea    0xe04(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1317 <main+0x1a7>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12f1 <main+0x181>
mov    -0x10(%rbp),%rax
lea    0xdba(%rip),%rcx
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
lea    0xda7(%rip),%rdi
call   1080 <execvp@plt>
cmp    $0x0,%rax
je     12ec <main+0x17c>
lea    0xd98(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1312 <main+0x1a2>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1317 <main+0x1a7>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jle    121c <main+0xac>
mov    0x8(%rbx),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0xd0>
mov    %eax,%edi
xor    %esi,%esi
call   1040 <setns@plt>
test   %rax,%rax
jne    1249 <main+0xd9>
mov    0x10(%rbx),%rdi
add    $0x10,%rbx
lea    0xeaf(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1201 <main+0x91>
mov    (%rbx),%rdi
lea    0xe99(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1252 <main+0xe2>
lea    0xe86(%rip),%rdi
mov    %rdi,(%rbx)
mov    %rbx,%rsi
call   1080 <execvp@plt>
test   %rax,%rax
je     1218 <main+0xa8>
lea    0xe76(%rip),%rdi
jmp    127a <main+0x10a>
lea    0xe67(%rip),%rdi
mov    %rdi,(%rbx)
mov    %rbx,%rsi
call   1080 <execvp@plt>
test   %rax,%rax
jne    1273 <main+0x103>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdd1(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xde7(%rip),%rdi
jmp    127a <main+0x10a>
lea    0xdfd(%rip),%rdi
jmp    127a <main+0x10a>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xdfc(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"%s <mount_namespace_fd> <-m|-u> <mount_args>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [31 x i8] c"open mount namespace fd failed\00"
@.str.2 = [27 x i8] c"failed to switch namespace\00"
@.str.3 = [3 x i8] c"-m\00"
@.str.4 = [6 x i8] c"mount\00"
@.str.5 = [13 x i8] c"mount failed\00"
@.str.6 = [3 x i8] c"-u\00"
@.str.7 = [7 x i8] c"umount\00"
@.str.8 = [14 x i8] c"umount failed\00"
@.str.9 = [23 x i8] c"unrecognize parameter!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %16
%28 = load i32, i32* %6
%29 = call i64 @setns(i32 %28, i32 0)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 -1)
unreachable
34: ; preds = %27
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i64 @strncmp(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %34
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %42
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = call i64 @execvp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%49 = call i32 @exit(i32 -1)
unreachable
50: ; preds = %40
br label %73
51: ; preds = %34
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i64 @strncmp(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %68
57: ; preds = %51
%58 = load i8**, i8*** %5
%59 = getelementptr inbounds i8*, i8** %58, i64 2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %59
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
%62 = call i64 @execvp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %57
%65 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %57
br label %72
68: ; preds = %51
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%71 = call i32 @exit(i32 -1)
unreachable
72: ; preds = %67
br label %73
73: ; preds = %72, %50
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"%s <mount_namespace_fd> <-m|-u> <mount_args>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [31 x i8] c"open mount namespace fd failed\00"
@.str.2 = [27 x i8] c"failed to switch namespace\00"
@.str.3 = [3 x i8] c"-m\00"
@.str.4 = [6 x i8] c"mount\00"
@.str.5 = [13 x i8] c"mount failed\00"
@.str.6 = [3 x i8] c"-u\00"
@.str.7 = [7 x i8] c"umount\00"
@.str.8 = [14 x i8] c"umount failed\00"
@.str.9 = [23 x i8] c"unrecognize parameter!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %9
%19 = tail call i64 @setns(i32 %13, i32 0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %18
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %24
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %25
%30 = tail call i64 @execvp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %25)
%31 = icmp eq i64 %30, 0
br i1 %31, label %49, label %32
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %24
%36 = load i8*, i8** %25
%37 = tail call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %35
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %25
%40 = tail call i64 @execvp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8** %25)
%41 = icmp eq i64 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %39
%43 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
%44 = tail call i32 @exit(i32 -1)
unreachable
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%48 = tail call i32 @exit(i32 -1)
unreachable
49: ; preds = %39, %29
ret i32 0
}