#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*/ execl(char *, char *, char *, char *, char *, char *,
                         char const *, char *, char const *, char const *,
                         char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ geteuid();
int /*<<< orphan*/ 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 add_mount(const char *progname, const char *fsname, const char *mnt,
              const char *type, const char *opts) {
  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) {
    sigprocmask(SIG_SETMASK, &oldmask, NULL);
    setuid(geteuid());
    execl("/bin/mount", "/bin/mount", "--no-canonicalize", "-i", "-f", "-t",
          type, "-o", opts, fsname, mnt, NULL);
    fprintf(stderr, "%s: failed to execute /bin/mount: %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):
<add_mount>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0xb0,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x38(%rbp)
mov    %r8,-0x40(%rbp)
lea    -0x4c(%rbp),%rdi
call   1060 <sigemptyset@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    -0x4c(%rbp),%rdi
call   10c0 <sigaddset@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    -0x4c(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1254 <add_mount+0xa4>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xdbd(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    140b <add_mount+0x25b>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    12a5 <add_mount+0xf5>
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rdx
mov    %rax,%rcx
lea    0xd7a(%rip),%rsi
call   1050 <fprintf@plt>
jmp    13ef <add_mount+0x23f>
cmpl   $0x0,-0x44(%rbp)
jne    137a <add_mount+0x1ca>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    $0x0,%al
call   1040 <geteuid@plt>
mov    %eax,%edi
call   1090 <setuid@plt>
mov    -0x38(%rbp),%r14
mov    -0x40(%rbp),%r11
mov    -0x28(%rbp),%r10
mov    -0x30(%rbp),%rax
lea    0xd39(%rip),%rsi
lea    0xd3d(%rip),%rdx
lea    0xd48(%rip),%rcx
lea    0xd44(%rip),%r8
lea    0xd40(%rip),%r9
lea    0xd3c(%rip),%rbx
xor    %edi,%edi
mov    %rsi,%rdi
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x0,0x28(%rsp)
call   10b0 <execl@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x7c(%rbp),%edi
mov    -0x78(%rbp),%rdx
mov    %rax,%rcx
lea    0xce1(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x44(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    13d9 <add_mount+0x229>
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %rax,%rcx
lea    0xc9e(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x48(%rbp)
je     13ea <add_mount+0x23a>
movl   $0xffffffff,-0x44(%rbp)
jmp    13ef <add_mount+0x23f>
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_mount>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x14(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <sigemptyset@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10c0 <sigaddset@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rdx
mov    %rbp,%rsi
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     126e <add_mount+0xbe>
xor    %eax,%eax
call   10d0 <fork@plt>
cmp    $0xffffffff,%eax
je     12a0 <add_mount+0xf0>
test   %eax,%eax
je     12f6 <add_mount+0x146>
lea    0x10(%rsp),%rsi
xor    %r15d,%r15d
mov    %eax,%edi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1263 <add_mount+0xb3>
mov    0x2d93(%rip),%rax
mov    (%rax),%r14d
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe1d(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
cmp    0x10(%rsp),%r15d
sbb    %ebx,%ebx
or     %ebp,%ebx
jmp    12d0 <add_mount+0x120>
mov    0x2d5b(%rip),%rax
mov    (%rax),%ebp
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd74(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    12e5 <add_mount+0x135>
mov    0x2d29(%rip),%rax
mov    (%rax),%ebp
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd57(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
xor    %eax,%eax
call   1040 <geteuid@plt>
mov    %eax,%edi
call   1090 <setuid@plt>
lea    0xd29(%rip),%rax
lea    0xcfc(%rip),%rdi
lea    0xd00(%rip),%rdx
lea    0xd0b(%rip),%rcx
lea    0xd07(%rip),%r8
lea    0xd03(%rip),%r9
mov    %rdi,%rsi
push   $0x0
push   %r13
push   %r12
push   %r15
push   %rax
push   %r14
call   10b0 <execl@plt>
add    $0x30,%rsp
mov    0x2c6f(%rip),%rax
mov    (%rax),%ebp
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xcd4(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%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 = [11 x i8] c"/bin/mount\00"
@.str.3 = [18 x i8] c"--no-canonicalize\00"
@.str.4 = [3 x i8] c"-i\00"
@.str.5 = [3 x i8] c"-f\00"
@.str.6 = [3 x i8] c"-t\00"
@.str.7 = [3 x i8] c"-o\00"
@.str.8 = [38 x i8] c"%s: failed to execute /bin/mount: %s\0A\00"
@.str.9 = [17 x i8] c"%s: waitpid: %s\0A\00"
define i32 @add_mount(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = call i32 @sigemptyset(i32* %14)
%17 = load i32, i32* @SIGCHLD
%18 = call i32 @sigaddset(i32* %14, i32 %17)
%19 = load i32, i32* @SIG_BLOCK
%20 = call i32 @sigprocmask(i32 %19, i32* %14, i32* %15)
store i32 %20, i32* %12
%21 = load i32, i32* %12
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %5
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %7
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %27)
store i32 -1, i32* %6
br label %78
29: ; preds = %5
%30 = call i32 (...) @fork()
store i32 %30, i32* %12
%31 = load i32, i32* %12
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %7
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %37)
br label %74
39: ; preds = %29
%40 = load i32, i32* %12
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %58
42: ; preds = %39
%43 = load i32, i32* @SIG_SETMASK
%44 = call i32 @sigprocmask(i32 %43, i32* %15, i32* null)
%45 = call i32 (...) @geteuid()
%46 = call i32 @setuid(i32 %45)
%47 = load i8*, i8** %10
%48 = load i8*, i8** %11
%49 = load i8*, i8** %8
%50 = load i8*, i8** %9
%51 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %48, i8* %49, i8* %50, i32* null)
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %7
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %53, i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %39
%59 = load i32, i32* %12
%60 = call i32 @waitpid(i32 %59, i32* %13, i32 0)
store i32 %60, i32* %12
%61 = load i32, i32* %12
%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** %7
%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.9, i64 0, i64 0), i8* %65, i8* %67)
br label %69
69: ; preds = %63, %58
%70 = load i32, i32* %13
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %69
store i32 -1, i32* %12
br label %73
73: ; preds = %72, %69
br label %74
74: ; preds = %73, %33
%75 = load i32, i32* @SIG_SETMASK
%76 = call i32 @sigprocmask(i32 %75, i32* %15, i32* null)
%77 = load i32, i32* %12
store i32 %77, i32* %6
br label %78
78: ; preds = %74, %23
%79 = load i32, i32* %6
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 = [11 x i8] c"/bin/mount\00"
@.str.3 = [18 x i8] c"--no-canonicalize\00"
@.str.4 = [3 x i8] c"-i\00"
@.str.5 = [3 x i8] c"-f\00"
@.str.6 = [3 x i8] c"-t\00"
@.str.7 = [3 x i8] c"-o\00"
@.str.8 = [38 x i8] c"%s: failed to execute /bin/mount: %s\0A\00"
@.str.9 = [17 x i8] c"%s: waitpid: %s\0A\00"
define i32 @add_mount(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = bitcast i32* %8 to i8*
%12 = call i32 @sigemptyset(i32* %7)
%13 = load i32, i32* @SIGCHLD
%14 = call i32 @sigaddset(i32* %7, i32 %13)
%15 = load i32, i32* @SIG_BLOCK
%16 = call i32 @sigprocmask(i32 %15, i32* %7, i32* %8)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %5
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %21)
br label %57
23: ; preds = %5
%24 = call i32 (...) @fork()
switch i32 %24, label %41 [
i32 -1, label %25
i32 0, label %30
]
25: ; preds = %23
%26 = load i32, i32* @stderr
%27 = load i32, i32* @errno
%28 = call i8* @strerror(i32 %27)
%29 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %28)
br label %53
30: ; preds = %23
%31 = load i32, i32* @SIG_SETMASK
%32 = call i32 @sigprocmask(i32 %31, i32* %8, i32* null)
%33 = call i32 (...) @geteuid()
%34 = call i32 @setuid(i32 %33)
%35 = call i32 @execl(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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 ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %4, i8* %1, i8* %2, i32* null)
%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 ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0), i8* %0, i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %23
%42 = call i32 @waitpid(i32 %24, i32* %6, i32 0)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0), i8* %0, i8* %47)
br label %49
49: ; preds = %44, %41
%50 = load i32, i32* %6
%51 = icmp eq i32 %50, 0
%52 = select i1 %51, i32 %42, i32 -1
br label %53
53: ; preds = %49, %25
%54 = phi i32 [ -1, %25 ], [ %52, %49 ]
%55 = load i32, i32* @SIG_SETMASK
%56 = call i32 @sigprocmask(i32 %55, i32* %8, i32* null)
br label %57
57: ; preds = %53, %18
%58 = phi i32 [ -1, %18 ], [ %54, %53 ]
ret i32 %58
}