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

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execle(char *, char *, char *, char *, char *, char const *,
                          int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ geteuid();
int setuid(int /*<<< orphan*/);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int waitpid(int, int *, int /*<<< orphan*/);
int remove_mount(const char *progname, const char *mnt) {
  int res;
  int status;
  sigset_t blockmask;
  sigset_t oldmask;
  sigemptyset(&blockmask);
  sigaddset(&blockmask, SIGCHLD);
  res = sigprocmask(SIG_BLOCK, &blockmask, &oldmask);
  if (res == -1) {
    fprintf(stderr, "%s: sigprocmask: %s\n", progname, strerror(errno));
    return -1;
  }
  res = fork();
  if (res == -1) {
    fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
    goto out_restore;
  }
  if (res == 0) {
    char *env = NULL;
    sigprocmask(SIG_SETMASK, &oldmask, NULL);
    if (setuid(geteuid()) == -1) {
      fprintf(stderr, "%s: setuid: %s\n", progname, strerror(errno));
      res = -1;
      goto out_restore;
    }
    execle("/bin/umount", "/bin/umount", "--no-canonicalize", "-i", "--fake",
           mnt, NULL, &env);
    fprintf(stderr, "%s: failed to execute /bin/umount: %s\n", progname,
            strerror(errno));
    exit(1);
  }
  res = waitpid(res, &status, 0);
  if (res == -1)
    fprintf(stderr, "%s: waitpid: %s\n", progname, strerror(errno));
  if (status != 0)
    res = -1;
out_restore:
  sigprocmask(SIG_SETMASK, &oldmask, NULL);
  return res;
}


x86 assembly (clang, -O0):
<remove_mount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x24(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    -0x24(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1245 <remove_mount+0x95>
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    141b <remove_mount+0x26b>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1296 <remove_mount+0xe6>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xd89(%rip),%rsi
call   1050 <fprintf@plt>
jmp    13ff <remove_mount+0x24f>
cmpl   $0x0,-0x1c(%rbp)
jne    1396 <remove_mount+0x1e6>
movq   $0x0,-0x30(%rbp)
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,%edi
call   10a0 <setuid@plt>
cmp    $0xffffffff,%eax
jne    1319 <remove_mount+0x169>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xd1b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    13ff <remove_mount+0x24f>
mov    -0x18(%rbp),%r9
lea    0xd0f(%rip),%rsi
lea    0xd14(%rip),%rdx
lea    0xd1f(%rip),%rcx
lea    0xd1b(%rip),%r8
xor    %eax,%eax
lea    -0x30(%rbp),%rax
mov    %rsi,%rdi
movq   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
call   1090 <execle@plt>
mov    0x2c75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xcd4(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    13e9 <remove_mount+0x239>
mov    0x2c18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xc9e(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x20(%rbp)
je     13fa <remove_mount+0x24a>
movl   $0xffffffff,-0x1c(%rbp)
jmp    13ff <remove_mount+0x24f>
mov    0x2be2(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_mount>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10c0 <sigaddset@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rdx
mov    %rbp,%rsi
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     1230 <remove_mount+0x80>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     1265 <remove_mount+0xb5>
cmp    $0xffffffff,%eax
jne    12cc <remove_mount+0x11c>
mov    0x2dbc(%rip),%rax
mov    (%rax),%ebx
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdea(%rip),%rsi
jmp    12b8 <remove_mount+0x108>
mov    0x2d99(%rip),%rax
mov    (%rax),%ebx
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdb2(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    132d <remove_mount+0x17d>
movq   $0x0,0x8(%rsp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%edi
call   10a0 <setuid@plt>
cmp    $0xffffffff,%eax
jne    133a <remove_mount+0x18a>
mov    0x2d2f(%rip),%rax
mov    (%rax),%ebx
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd6b(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1318 <remove_mount+0x168>
lea    0x8(%rsp),%rsi
xor    %r15d,%r15d
mov    %eax,%edi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    130f <remove_mount+0x15f>
mov    0x2ce5(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd80(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
cmp    0x8(%rsp),%r15d
sbb    %ebx,%ebx
or     %ebp,%ebx
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0x4(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x8(%rsp),%rax
lea    0xced(%rip),%rdi
lea    0xcf2(%rip),%rdx
lea    0xcfd(%rip),%rcx
lea    0xcf9(%rip),%r8
mov    %rdi,%rsi
mov    %rbx,%r9
push   %rax
push   $0x0
call   1090 <execle@plt>
add    $0x10,%rsp
mov    0x2c5c(%rip),%rax
mov    (%rax),%ebx
mov    0x2c4b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcd0(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIG_BLOCK = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"%s: sigprocmask: %s\0A\00"
@errno = global i32 0
@.str.1 = [14 x i8] c"%s: fork: %s\0A\00"
@SIG_SETMASK = global i32 0
@.str.2 = [16 x i8] c"%s: setuid: %s\0A\00"
@.str.3 = [12 x i8] c"/bin/umount\00"
@.str.4 = [18 x i8] c"--no-canonicalize\00"
@.str.5 = [3 x i8] c"-i\00"
@.str.6 = [7 x i8] c"--fake\00"
@.str.7 = [39 x i8] c"%s: failed to execute /bin/umount: %s\0A\00"
@.str.8 = [17 x i8] c"%s: waitpid: %s\0A\00"
define i32 @remove_mount(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = call i32 @sigemptyset(i32* %8)
%12 = load i32, i32* @SIGCHLD
%13 = call i32 @sigaddset(i32* %8, i32 %12)
%14 = load i32, i32* @SIG_BLOCK
%15 = call i32 @sigprocmask(i32 %14, i32* %8, i32* %9)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %4
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %22)
store i32 -1, i32* %3
br label %78
24: ; preds = %2
%25 = call i32 (...) @fork()
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %4
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %32)
br label %74
34: ; preds = %24
%35 = load i32, i32* %6
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %58
37: ; preds = %34
store i8* null, i8** %10
%38 = load i32, i32* @SIG_SETMASK
%39 = call i32 @sigprocmask(i32 %38, i32* %9, i32* null)
%40 = call i32 (...) @geteuid()
%41 = call i32 @setuid(i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %49
43: ; preds = %37
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %4
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %47)
store i32 -1, i32* %6
br label %74
49: ; preds = %37
%50 = load i8*, i8** %5
%51 = call i32 @execle(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %50, i32* null, i8** %10)
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %4
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %53, i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %34
%59 = load i32, i32* %6
%60 = call i32 @waitpid(i32 %59, i32* %7, i32 0)
store i32 %60, i32* %6
%61 = load i32, i32* %6
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %69
63: ; preds = %58
%64 = load i32, i32* @stderr
%65 = load i8*, i8** %4
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %65, i8* %67)
br label %69
69: ; preds = %63, %58
%70 = load i32, i32* %7
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %69
store i32 -1, i32* %6
br label %73
73: ; preds = %72, %69
br label %74
74: ; preds = %73, %43, %28
%75 = load i32, i32* @SIG_SETMASK
%76 = call i32 @sigprocmask(i32 %75, i32* %9, i32* null)
%77 = load i32, i32* %6
store i32 %77, i32* %3
br label %78
78: ; preds = %74, %18
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIG_BLOCK = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"%s: sigprocmask: %s\0A\00"
@errno = global i32 0
@.str.1 = [14 x i8] c"%s: fork: %s\0A\00"
@SIG_SETMASK = global i32 0
@.str.2 = [16 x i8] c"%s: setuid: %s\0A\00"
@.str.3 = [12 x i8] c"/bin/umount\00"
@.str.4 = [18 x i8] c"--no-canonicalize\00"
@.str.5 = [3 x i8] c"-i\00"
@.str.6 = [7 x i8] c"--fake\00"
@.str.7 = [39 x i8] c"%s: failed to execute /bin/umount: %s\0A\00"
@.str.8 = [17 x i8] c"%s: waitpid: %s\0A\00"
define i32 @remove_mount(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @sigemptyset(i32* %4)
%11 = load i32, i32* @SIGCHLD
%12 = call i32 @sigaddset(i32* %4, i32 %11)
%13 = load i32, i32* @SIG_BLOCK
%14 = call i32 @sigprocmask(i32 %13, i32* %4, i32* %5)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %19)
br label %63
21: ; preds = %2
%22 = call i32 (...) @fork()
switch i32 %22, label %47 [
i32 -1, label %23
i32 0, label %28
]
23: ; preds = %21
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %26)
br label %59
28: ; preds = %21
%29 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%30 = load i32, i32* @SIG_SETMASK
%31 = call i32 @sigprocmask(i32 %30, i32* %5, i32* null)
%32 = call i32 (...) @geteuid()
%33 = call i32 @setuid(i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %38)
br label %59
40: ; preds = %28
%41 = call i32 @execle(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %1, i32* null, i8** %6)
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %44)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %21
%48 = call i32 @waitpid(i32 %22, i32* %3, i32 0)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i8* %0, i8* %53)
br label %55
55: ; preds = %50, %47
%56 = load i32, i32* %3
%57 = icmp eq i32 %56, 0
%58 = select i1 %57, i32 %48, i32 -1
br label %59
59: ; preds = %55, %35, %23
%60 = phi i32 [ -1, %23 ], [ -1, %35 ], [ %58, %55 ]
%61 = load i32, i32* @SIG_SETMASK
%62 = call i32 @sigprocmask(i32 %61, i32* %5, i32* null)
br label %63
63: ; preds = %59, %16
%64 = phi i32 [ -1, %16 ], [ %60, %59 ]
ret i32 %64
}