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

/* Variables and functions */
int /*<<< orphan*/ MS_BIND;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int getpid();
int mount(char *, char *, char *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int umount2(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int res;
  FILE *fp;
  if (argc != 3) {
    fprintf(stderr, "usage: %s from to\n", argv[0]);
    exit(1);
  }
  fp = fopen("/proc/fs/redir2/mount_pid", "w");
  if (fp == NULL) {
    perror("opening /proc/fs/redir2/mount_pid");
    exit(1);
  }
  fprintf(fp, "%u", getpid());
  fclose(fp);
  if (argv[1][0] == '-') {
    res = umount2(argv[2], 0);
    if (res == -1) {
      perror("umount failed");
      exit(1);
    }
  } else {
    res = mount(argv[1], argv[2], "none", MS_BIND, NULL);
    if (res == -1) {
      perror("mount failed");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c9 <main+0x49>
mov    0x2e31(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe4d(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1201 <main+0x81>
lea    0xe23(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1278 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %esi,%esi
call   1040 <umount2@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1273 <main+0xf3>
lea    0xdd6(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12ca <main+0x14a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0x2d59(%rip),%rax
mov    (%rax),%ecx
lea    0xdb0(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <mount@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12c5 <main+0x145>
lea    0xd85(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12ca <main+0x14a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x3,%edi
jne    121d <main+0x9d>
lea    0xe86(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1242 <main+0xc2>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rsi
cmpb   $0x2d,(%rdi)
jne    11f6 <main+0x76>
mov    %rsi,%rdi
xor    %esi,%esi
call   1040 <umount2@plt>
cmp    $0xffffffff,%eax
jne    1213 <main+0x93>
lea    0xe46(%rip),%rdi
jmp    1252 <main+0xd2>
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
lea    0xe42(%rip),%rdx
xor    %r8d,%r8d
call   1060 <mount@plt>
cmp    $0xffffffff,%eax
je     124b <main+0xcb>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2db4(%rip),%rax
movslq (%rax),%rdi
mov    (%r14),%rdx
lea    0xdcf(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdcc(%rip),%rdi
jmp    1252 <main+0xd2>
lea    0xde9(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s from to\0A\00"
@.str.1 = [26 x i8] c"/proc/fs/redir2/mount_pid\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [34 x i8] c"opening /proc/fs/redir2/mount_pid\00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [14 x i8] c"umount failed\00"
@.str.6 = [5 x i8] c"none\00"
@MS_BIND = global i32 0
@.str.7 = [13 x i8] c"mount failed\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 %19
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = sext i32 %11 to i64
%13 = inttoptr i64 %12 to i32*
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = load i32*, i32** %7
%28 = call i32 (...) @getpid()
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 45
br i1 %38, label %39, label %50
39: ; preds = %26
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @umount2(i8* %42, i32 0)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %39
br label %65
50: ; preds = %26
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = load i32, i32* @MS_BIND
%58 = call i32 @mount(i8* %53, i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %57, i32* null)
store i32 %58, i32* %6
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %64
61: ; preds = %50
%62 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %50
br label %65
65: ; preds = %64, %49
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s from to\0A\00"
@.str.1 = [26 x i8] c"/proc/fs/redir2/mount_pid\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [34 x i8] c"opening /proc/fs/redir2/mount_pid\00"
@.str.4 = [3 x i8] c"%u\00"
@.str.5 = [14 x i8] c"umount failed\00"
@.str.6 = [5 x i8] c"none\00"
@MS_BIND = global i32 0
@.str.7 = [13 x i8] c"mount failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = load i8*, i8** %1
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = tail call i32* @fopen(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = tail call i32 (...) @getpid()
%19 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = tail call i32 @fclose(i32* %12)
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 45
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
br i1 %24, label %27, label %33
27: ; preds = %17
%28 = tail call i32 @umount2(i8* %26, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %17
%34 = load i32, i32* @MS_BIND
%35 = tail call i32 @mount(i8* %22, i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 %34, i32* null)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%39 = tail call i32 @exit(i32 1)
unreachable
40: ; preds = %33, %27
ret i32 0
}