#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ MS_BIND;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int mkdir(char const *, int);
scalar_t__ mount(char *, char const *, int /*<<< orphan*/ *, int /*<<< orphan*/,
                 char *);
scalar_t__ rmdir(char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ umount(char const *);
int main(int argc, char *argv[]) {
  int ret;
  const char *mntpnt;
  if (argc > 1) {
    mntpnt = argv[1];
  } else {
    mntpnt = "/bindproc";
  }
  ret = mkdir(mntpnt, 0700);
  if (ret != 0 && errno != EEXIST) {
    return 77;
  }
  if (ret == 0) {
    if (mount("/proc", mntpnt, NULL, MS_BIND, "")) {
      fprintf(stderr, "Failed to mount proc errno=%d\n", errno);
      if (rmdir(mntpnt) != 0) {
        umount(mntpnt);
        rmdir(mntpnt);
      }
      return 1;
    }
    umount(mntpnt);
    rmdir(mntpnt);
  }
  return 0;
}


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   $0x1,-0x8(%rbp)
jle    1181 <main+0x31>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    118c <main+0x3c>
lea    0xe78(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11cd <main+0x7d>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <main+0x7d>
movl   $0x4d,-0x4(%rbp)
jmp    126e <main+0x11e>
cmpl   $0x0,-0x14(%rbp)
jne    1267 <main+0x117>
mov    -0x20(%rbp),%rsi
mov    0x2e06(%rip),%rax
mov    (%rax),%ecx
lea    0xe1f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    0xe38(%rip),%r8
call   1060 <mount@plt>
cmp    $0x0,%rax
je     1255 <main+0x105>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%rdx
lea    0xdf1(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
je     1249 <main+0xf9>
mov    -0x20(%rbp),%rdi
call   1040 <umount@plt>
mov    -0x20(%rbp),%rdi
call   1050 <rmdir@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <main+0x11e>
mov    -0x20(%rbp),%rdi
call   1040 <umount@plt>
mov    -0x20(%rbp),%rdi
call   1050 <rmdir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     115f <main+0xf>
mov    0x8(%rsi),%r14
jmp    1166 <main+0x16>
lea    0xe9a(%rip),%r14
mov    %r14,%rdi
mov    $0x1c0,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
je     1197 <main+0x47>
mov    0x2e4a(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
xor    %edx,%edx
cmp    (%rcx),%rax
mov    $0x4d,%ebx
cmove  %edx,%ebx
jmp    1200 <main+0xb0>
mov    0x2e4a(%rip),%rax
mov    (%rax),%ecx
lea    0xe63(%rip),%rdi
lea    0xe80(%rip),%r8
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <mount@plt>
test   %rax,%rax
je     11f0 <main+0xa0>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%rdx
lea    0xe37(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1050 <rmdir@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1200 <main+0xb0>
mov    %r14,%rdi
call   1040 <umount@plt>
mov    %r14,%rdi
call   1050 <rmdir@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"/bindproc\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [6 x i8] c"/proc\00"
@MS_BIND = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.3 = [31 x i8] c"Failed to mount proc errno=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %7
br label %15
14: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %7
br label %15
15: ; preds = %14, %10
%16 = load i8*, i8** %7
%17 = call i32 @mkdir(i8* %16, i32 448)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i64, i64* @errno
%22 = load i64, i64* @EEXIST
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 77, i32* %3
br label %52
25: ; preds = %20, %15
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %51
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = load i32, i32* @MS_BIND
%31 = call i64 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32* null, i32 %30, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i64, i64* @errno
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %35)
%37 = load i8*, i8** %7
%38 = call i64 @rmdir(i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %33
%41 = load i8*, i8** %7
%42 = call i32 @umount(i8* %41)
%43 = load i8*, i8** %7
%44 = call i64 @rmdir(i8* %43)
br label %45
45: ; preds = %40, %33
store i32 1, i32* %3
br label %52
46: ; preds = %28
%47 = load i8*, i8** %7
%48 = call i32 @umount(i8* %47)
%49 = load i8*, i8** %7
%50 = call i64 @rmdir(i8* %49)
br label %51
51: ; preds = %46, %25
store i32 0, i32* %3
br label %52
52: ; preds = %51, %45, %24
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [10 x i8] c"/bindproc\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [6 x i8] c"/proc\00"
@MS_BIND = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.3 = [31 x i8] c"Failed to mount proc errno=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
br label %7
7: ; preds = %2, %4
%8 = phi i8* [ %6, %4 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%9 = tail call i32 @mkdir(i8* %8, i32 448)
%10 = icmp eq i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = load i64, i64* @errno
%13 = load i64, i64* @EEXIST
%14 = icmp eq i64 %12, %13
%15 = select i1 %14, i32 0, i32 77
br label %32
16: ; preds = %7
%17 = load i32, i32* @MS_BIND
%18 = tail call i64 @mount(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8, i32* null, i32 %17, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i64, i64* @errno
%23 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %22)
%24 = tail call i64 @rmdir(i8* %8)
%25 = icmp eq i64 %24, 0
br i1 %25, label %32, label %26
26: ; preds = %20
%27 = tail call i32 @umount(i8* %8)
%28 = tail call i64 @rmdir(i8* %8)
br label %32
29: ; preds = %16
%30 = tail call i32 @umount(i8* %8)
%31 = tail call i64 @rmdir(i8* %8)
br label %32
32: ; preds = %11, %29, %20, %26
%33 = phi i32 [ 1, %26 ], [ 1, %20 ], [ 0, %29 ], [ %15, %11 ]
ret i32 %33
}