#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*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int setns(int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ umount(char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "%s pid mount ...\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  int pid = atoi(argv[1]);
  char file[64];
  sprintf(file, "/proc/%d/ns/mnt", pid);
  int fd = open(file, O_RDONLY);
  if (fd == -1) {
    do {
      perror("open");
      exit(EXIT_FAILURE);
    } while (0);
  }
  if (setns(fd, 0) == -1) {
    do {
      perror("setns");
      exit(EXIT_FAILURE);
    } while (0);
  }
  int error = 0;
  for (int i = 2; i < argc; i++) {
    if (umount(argv[i]) != 0) {
      error = 1;
      perror(argv[i]);
    }
  }
  if (error) {
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ca <main+0x4a>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe2a(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    122b <main+0xab>
jmp    1211 <main+0x91>
lea    0xe0a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x64(%rbp),%edi
xor    %esi,%esi
call   1040 <setns@plt>
cmp    $0xffffffff,%eax
jne    125d <main+0xdd>
jmp    1243 <main+0xc3>
lea    0xddd(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x0,-0x68(%rbp)
movl   $0x2,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12bd <main+0x13d>
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <umount@plt>
cmp    $0x0,%rax
je     12aa <main+0x12a>
movl   $0x1,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x6c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <perror@plt>
jmp    12af <main+0x12f>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    126b <main+0xeb>
cmpl   $0x0,-0x68(%rbp)
je     12d5 <main+0x155>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%r12
cmp    $0x2,%edi
jle    122c <main+0xac>
mov    %edi,%r15d
mov    0x8(%r12),%rdi
call   1080 <atoi@plt>
lea    0xe66(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1247 <main+0xc7>
xor    %r14d,%r14d
mov    %eax,%edi
xor    %esi,%esi
call   1040 <setns@plt>
cmp    $0xffffffff,%eax
je     1250 <main+0xd0>
mov    %r15d,%ebp
mov    $0x2,%ebx
jmp    11f9 <main+0x79>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1218 <main+0x98>
mov    (%r12,%rbx,8),%rdi
call   1030 <umount@plt>
test   %rax,%rax
je     11f0 <main+0x70>
mov    (%r12,%rbx,8),%rdi
call   1070 <perror@plt>
mov    $0x1,%r14d
jmp    11f0 <main+0x70>
test   %r14d,%r14d
jne    125c <main+0xdc>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xdc0(%rip),%rsi
call   1050 <fprintf@plt>
jmp    125c <main+0xdc>
lea    0xdd4(%rip),%rdi
jmp    1257 <main+0xd7>
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"%s pid mount ...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"/proc/%d/ns/mnt\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"setns\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%27 = load i32, i32* %6
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %40
34: ; preds = %21
br label %35
35: ; preds = %34
%36 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; No predecessors!
br label %40
40: ; preds = %39, %21
%41 = load i32, i32* %8
%42 = call i32 @setns(i32 %41, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %40
br label %45
45: ; preds = %44
%46 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; No predecessors!
br label %50
50: ; preds = %49, %40
store i32 0, i32* %9
store i32 2, i32* %10
br label %51
51: ; preds = %71, %50
%52 = load i32, i32* %10
%53 = load i32, i32* %4
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %74
55: ; preds = %51
%56 = load i8**, i8*** %5
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = call i64 @umount(i8* %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %70
63: ; preds = %55
store i32 1, i32* %9
%64 = load i8**, i8*** %5
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 @perror(i8* %68)
br label %70
70: ; preds = %63, %55
br label %71
71: ; preds = %70
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %51
74: ; preds = %51
%75 = load i32, i32* %9
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %74
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"%s pid mount ...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [16 x i8] c"/proc/%d/ns/mnt\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"setns\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i8]
%4 = icmp slt i32 %0, 3
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %15, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %11
%21 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %11
%25 = tail call i32 @setns(i32 %18, i32 0)
%26 = icmp eq i32 %25, -1
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = zext i32 %0 to i64
br label %35
29: ; preds = %24
%30 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* @EXIT_FAILURE
%32 = tail call i32 @exit(i32 %31)
unreachable
33: ; preds = %45
%34 = icmp eq i32 %46, 0
br i1 %34, label %52, label %49
35: ; preds = %27, %45
%36 = phi i64 [ 2, %27 ], [ %47, %45 ]
%37 = phi i32 [ 0, %27 ], [ %46, %45 ]
%38 = getelementptr inbounds i8*, i8** %1, i64 %36
%39 = load i8*, i8** %38
%40 = tail call i64 @umount(i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %35
%43 = load i8*, i8** %38
%44 = tail call i32 @perror(i8* %43)
br label %45
45: ; preds = %35, %42
%46 = phi i32 [ 1, %42 ], [ %37, %35 ]
%47 = add nuw nsw i64 %36, 1
%48 = icmp eq i64 %47, %28
br i1 %48, label %33, label %35
49: ; preds = %33
%50 = load i32, i32* @EXIT_FAILURE
%51 = tail call i32 @exit(i32 %50)
unreachable
52: ; preds = %33
ret i32 0
}