#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;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int mkdir(char const *, int);
scalar_t__ mount(int /*<<< orphan*/ *, char const *, char *, 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 = "/fakeproc";
  }
  ret = mkdir(mntpnt, 0700);
  if (ret != 0 && errno != EEXIST) {
    return 77;
  }
  if (ret == 0) {
    if (mount(NULL, mntpnt, "proc", 0, "")) {
      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    0x2e22(%rip),%rax
mov    (%rax),%rax
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <main+0x7d>
movl   $0x4d,-0x4(%rbp)
jmp    1267 <main+0x117>
cmpl   $0x0,-0x14(%rbp)
jne    1260 <main+0x110>
mov    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1f(%rip),%rdx
xor    %ecx,%ecx
lea    0xe39(%rip),%r8
call   1060 <mount@plt>
cmp    $0x0,%rax
je     124e <main+0xfe>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%rdx
lea    0xdf2(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <rmdir@plt>
cmp    $0x0,%rax
je     1242 <main+0xf2>
mov    -0x20(%rbp),%rdi
call   1040 <umount@plt>
mov    -0x20(%rbp),%rdi
call   1050 <rmdir@plt>
movl   $0x1,-0x4(%rbp)
jmp    1267 <main+0x117>
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    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
xor    %edx,%edx
cmp    (%rcx),%rax
mov    $0x4d,%ebx
cmove  %edx,%ebx
jmp    11f9 <main+0xa9>
lea    0xe67(%rip),%rdx
lea    0xe83(%rip),%r8
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1060 <mount@plt>
test   %rax,%rax
je     11e9 <main+0x99>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%rdx
lea    0xe38(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1050 <rmdir@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     11f9 <main+0xa9>
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"/fakeproc\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [5 x i8] c"proc\00"
@.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 %51
25: ; preds = %20, %15
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %50
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = call i64 @mount(i32* null, i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = load i64, i64* @errno
%35 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %34)
%36 = load i8*, i8** %7
%37 = call i64 @rmdir(i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i8*, i8** %7
%41 = call i32 @umount(i8* %40)
%42 = load i8*, i8** %7
%43 = call i64 @rmdir(i8* %42)
br label %44
44: ; preds = %39, %32
store i32 1, i32* %3
br label %51
45: ; preds = %28
%46 = load i8*, i8** %7
%47 = call i32 @umount(i8* %46)
%48 = load i8*, i8** %7
%49 = call i64 @rmdir(i8* %48)
br label %50
50: ; preds = %45, %25
store i32 0, i32* %3
br label %51
51: ; preds = %50, %44, %24
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [10 x i8] c"/fakeproc\00"
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [5 x i8] c"proc\00"
@.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 %31
16: ; preds = %7
%17 = tail call i64 @mount(i32* null, i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i64, i64* @errno
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i64 %21)
%23 = tail call i64 @rmdir(i8* %8)
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = tail call i32 @umount(i8* %8)
%27 = tail call i64 @rmdir(i8* %8)
br label %31
28: ; preds = %16
%29 = tail call i32 @umount(i8* %8)
%30 = tail call i64 @rmdir(i8* %8)
br label %31
31: ; preds = %11, %28, %19, %25
%32 = phi i32 [ 1, %25 ], [ 1, %19 ], [ 0, %28 ], [ %15, %11 ]
ret i32 %32
}