#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ target;
struct seccomp_notif_resp {
  int /*<<< orphan*/ error;
  scalar_t__ val;
  int /*<<< orphan*/ id;
};
struct TYPE_2__ {
  scalar_t__ nr;
  int *args;
};
struct seccomp_notif {
  int pid;
  TYPE_1__ data;
  int /*<<< orphan*/ id;
};
typedef int /*<<< orphan*/ source;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ EPERM;
int MS_BIND;
int /*<<< orphan*/ O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ SECCOMP_IOCTL_NOTIF_ID_VALID;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ __NR_mount;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
scalar_t__ mount(char *, char *, int /*<<< orphan*/ *, int,
                 int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int handle_req(struct seccomp_notif *req, struct seccomp_notif_resp *resp,
               int listener) {
  char path[PATH_MAX], source[PATH_MAX], target[PATH_MAX];
  int ret = -1, mem;
  resp->id = req->id;
  resp->error = -EPERM;
  resp->val = 0;
  if (req->data.nr != __NR_mount) {
    fprintf(stderr, "huh? trapped something besides mount? %d\n", req->data.nr);
    return -1;
  }
  if (!(req->data.args[3] & MS_BIND))
    return 0;
  snprintf(path, sizeof(path), "/proc/%d/mem", req->pid);
  mem = open(path, O_RDONLY);
  if (mem < 0) {
    perror("open mem");
    return -1;
  }
  if (ioctl(listener, SECCOMP_IOCTL_NOTIF_ID_VALID, &req->id) < 0) {
    fprintf(stderr, "task died before we could map its memory\n");
    goto out;
  }
  if (lseek(mem, req->data.args[0], SEEK_SET) < 0) {
    perror("seek");
    goto out;
  }
  ret = read(mem, source, sizeof(source));
  if (ret < 0) {
    perror("read");
    goto out;
  }
  if (lseek(mem, req->data.args[1], SEEK_SET) < 0) {
    perror("seek");
    goto out;
  }
  ret = read(mem, target, sizeof(target));
  if (ret < 0) {
    perror("read");
    goto out;
  }
  if (!strncmp(source, "/tmp/", 5) && !strncmp(target, "/tmp/", 5)) {
    if (mount(source, target, NULL, req->data.args[3], NULL) < 0) {
      ret = -1;
      perror("actual mount");
      goto out;
    }
    resp->error = 0;
  }
  ret = 0;
out:
  close(mem);
  return ret;
}


x86 assembly (clang, -O0):
<handle_req>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x80(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x78(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%ecx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x10(%rax)
xor    %ecx,%ecx
mov    0x2d58(%rip),%rax
sub    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
je     12a6 <handle_req+0x106>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd74(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14e0 <handle_req+0x340>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0xc(%rax),%eax
mov    0x2d18(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    12d6 <handle_req+0x136>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14e0 <handle_req+0x340>
mov    -0x78(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xd3d(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x78(%rbp),%rdi
mov    0x2cdb(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    1330 <handle_req+0x190>
lea    0xd1f(%rip),%rdi
call   10c0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14e0 <handle_req+0x340>
mov    -0x1c(%rbp),%edi
mov    0x2c8e(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
add    $0x18,%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    136f <handle_req+0x1cf>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    14cb <handle_req+0x32b>
mov    -0x48(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%esi
mov    0x2c2d(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    13a5 <handle_req+0x205>
lea    0xccf(%rip),%rdi
call   10c0 <perror@plt>
jmp    14cb <handle_req+0x32b>
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rax
mov    -0x48(%rbp),%edi
mov    %eax,%edx
call   1090 <read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    13d5 <handle_req+0x235>
lea    0xca4(%rip),%rdi
call   10c0 <perror@plt>
jmp    14cb <handle_req+0x32b>
mov    -0x48(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0x4(%rax),%esi
mov    0x2bc6(%rip),%rax
mov    (%rax),%edx
call   1060 <lseek@plt>
cmp    $0x0,%rax
jge    140c <handle_req+0x26c>
lea    0xc68(%rip),%rdi
call   10c0 <perror@plt>
jmp    14cb <handle_req+0x32b>
mov    -0x58(%rbp),%rsi
mov    -0x60(%rbp),%rax
mov    -0x48(%rbp),%edi
mov    %eax,%edx
call   1090 <read@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    143c <handle_req+0x29c>
lea    0xc3d(%rip),%rdi
call   10c0 <perror@plt>
jmp    14cb <handle_req+0x32b>
mov    -0x68(%rbp),%rdi
lea    0xc2d(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    14c4 <handle_req+0x324>
mov    -0x58(%rbp),%rdi
lea    0xc0f(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    14c4 <handle_req+0x324>
mov    -0x58(%rbp),%rsi
mov    -0x68(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    0xc(%rax),%ecx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   1040 <mount@plt>
cmp    $0x0,%rax
jge    14ba <handle_req+0x31a>
movl   $0xffffffff,-0x44(%rbp)
lea    0xbca(%rip),%rdi
call   10c0 <perror@plt>
jmp    14cb <handle_req+0x32b>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x44(%rbp)
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_req>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r8d
mov    0x2e35(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r15
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %rsp,%r13
sub    %rax,%r13
mov    %r13,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
mov    0x18(%rdi),%eax
mov    %eax,0x10(%rsi)
mov    0x2db3(%rip),%rdx
xor    %eax,%eax
xor    %ecx,%ecx
sub    (%rdx),%ecx
mov    %ecx,(%rsi)
movq   $0x0,0x8(%rsi)
mov    0x8(%rdi),%rdx
mov    0x2de0(%rip),%rcx
cmp    (%rcx),%rdx
jne    135b <handle_req+0x1bb>
mov    %rdi,%r12
mov    0x10(%rdi),%rdx
mov    0x2db1(%rip),%rcx
mov    (%rcx),%ecx
test   %ecx,0xc(%rdx)
je     13a0 <handle_req+0x200>
mov    %r8d,-0x2c(%rbp)
mov    %rsi,-0x40(%rbp)
mov    (%r12),%ecx
lea    0xded(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,-0x38(%rbp)
mov    %ebx,%esi
call   1050 <snprintf@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10b0 <open@plt>
test   %eax,%eax
js     13c0 <handle_req+0x220>
mov    %eax,%r15d
lea    0x18(%r12),%rdx
mov    0x2d55(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edi
call   1070 <ioctl@plt>
test   %rax,%rax
js     1379 <handle_req+0x1d9>
mov    0x10(%r12),%rax
mov    (%rax),%esi
mov    0x2d1c(%rip),%rbx
mov    (%rbx),%edx
mov    %r15d,%edi
call   1060 <lseek@plt>
test   %rax,%rax
js     13d3 <handle_req+0x233>
mov    %r15d,%edi
mov    %r13,%rsi
mov    -0x38(%rbp),%rdx
call   1090 <read@plt>
test   %eax,%eax
js     13af <handle_req+0x20f>
mov    %rbx,%rcx
mov    %rax,%rbx
mov    0x10(%r12),%rax
mov    0x4(%rax),%esi
mov    (%rcx),%edx
mov    %r15d,%edi
call   1060 <lseek@plt>
test   %rax,%rax
js     13e1 <handle_req+0x241>
mov    %r15d,%edi
mov    %r14,%rsi
mov    -0x38(%rbp),%rdx
call   1090 <read@plt>
test   %eax,%eax
js     13af <handle_req+0x20f>
lea    0xd77(%rip),%rsi
mov    %r13,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    1395 <handle_req+0x1f5>
lea    0xd59(%rip),%rsi
mov    %r14,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1395 <handle_req+0x1f5>
mov    0x10(%r12),%rax
mov    0xc(%rax),%ecx
xor    %ebx,%ebx
mov    %r13,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %r8d,%r8d
call   1040 <mount@plt>
test   %rax,%rax
js     13ef <handle_req+0x24f>
mov    -0x40(%rbp),%rax
movl   $0x0,(%rax)
jmp    1395 <handle_req+0x1f5>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    13a0 <handle_req+0x200>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
lea    0xcb7(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %r15d,%edi
call   1080 <close@plt>
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rax,%rbx
lea    0xcb6(%rip),%rdi
call   10c0 <perror@plt>
jmp    1395 <handle_req+0x1f5>
lea    0xc70(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%eax
jmp    13a0 <handle_req+0x200>
lea    0xc90(%rip),%rdi
call   10c0 <perror@plt>
jmp    1390 <handle_req+0x1f0>
lea    0xc82(%rip),%rdi
call   10c0 <perror@plt>
jmp    1395 <handle_req+0x1f5>
lea    0xc84(%rip),%rdi
jmp    13da <handle_req+0x23a>

LLVM IR (-O0):
%struct.seccomp_notif = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64, i32* }
%struct.seccomp_notif_resp = type { i32, i64, i32 }
@PATH_MAX = global i32 0
@EPERM = global i32 0
@__NR_mount = global i64 0
@stderr = global i32 0
@.str = [42 x i8] c"huh? trapped something besides mount? %d\0A\00"
@MS_BIND = global i32 0
@.str.1 = [13 x i8] c"/proc/%d/mem\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"open mem\00"
@SECCOMP_IOCTL_NOTIF_ID_VALID = global i32 0
@.str.3 = [42 x i8] c"task died before we could map its memory\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [5 x i8] c"seek\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [6 x i8] c"/tmp/\00"
@.str.7 = [13 x i8] c"actual mount\00"
define i32 @handle_req(%struct.seccomp_notif* %0, %struct.seccomp_notif_resp* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.seccomp_notif*
%6 = alloca %struct.seccomp_notif_resp*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store %struct.seccomp_notif* %0, %struct.seccomp_notif** %5
store %struct.seccomp_notif_resp* %1, %struct.seccomp_notif_resp** %6
store i32 %2, i32* %7
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i32, i32* @PATH_MAX
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
store i64 %20, i64* %10
%22 = load i32, i32* @PATH_MAX
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
store i64 %23, i64* %11
store i32 -1, i32* %12
%25 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%26 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %25, i32 0, i32 2
%27 = load i32, i32* %26
%28 = load %struct.seccomp_notif_resp*, %struct.seccomp_notif_resp** %6
%29 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %28, i32 0, i32 2
store i32 %27, i32* %29
%30 = load i32, i32* @EPERM
%31 = sub nsw i32 0, %30
%32 = load %struct.seccomp_notif_resp*, %struct.seccomp_notif_resp** %6
%33 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load %struct.seccomp_notif_resp*, %struct.seccomp_notif_resp** %6
%35 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %34, i32 0, i32 1
store i64 0, i64* %35
%36 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%37 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %36, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load i64, i64* @__NR_mount
%41 = icmp ne i64 %39, %40
br i1 %41, label %42, label %49
42: ; preds = %3
%43 = load i32, i32* @stderr
%44 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%45 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %44, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 %47)
store i32 -1, i32* %4
store i32 1, i32* %14
br label %149
49: ; preds = %3
%50 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%51 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %50, i32 0, i32 1
%52 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %51, i32 0, i32 1
%53 = load i32*, i32** %52
%54 = getelementptr inbounds i32, i32* %53, i64 3
%55 = load i32, i32* %54
%56 = load i32, i32* @MS_BIND
%57 = and i32 %55, %56
%58 = icmp ne i32 %57, 0
br i1 %58, label %60, label %59
59: ; preds = %49
store i32 0, i32* %4
store i32 1, i32* %14
br label %149
60: ; preds = %49
%61 = trunc i64 %16 to i32
%62 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%63 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i32 @snprintf(i8* %18, i32 %61, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %64)
%66 = load i32, i32* @O_RDONLY
%67 = call i32 @open(i8* %18, i32 %66)
store i32 %67, i32* %13
%68 = load i32, i32* %13
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %60
%71 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %14
br label %149
72: ; preds = %60
%73 = load i32, i32* %7
%74 = load i32, i32* @SECCOMP_IOCTL_NOTIF_ID_VALID
%75 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%76 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %75, i32 0, i32 2
%77 = call i64 @ioctl(i32 %73, i32 %74, i32* %76)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %72
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %145
82: ; preds = %72
%83 = load i32, i32* %13
%84 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%85 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %84, i32 0, i32 1
%86 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %85, i32 0, i32 1
%87 = load i32*, i32** %86
%88 = getelementptr inbounds i32, i32* %87, i64 0
%89 = load i32, i32* %88
%90 = load i32, i32* @SEEK_SET
%91 = call i64 @lseek(i32 %83, i32 %89, i32 %90)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %82
%94 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %145
95: ; preds = %82
%96 = load i32, i32* %13
%97 = trunc i64 %20 to i32
%98 = call i32 @read(i32 %96, i8* %21, i32 %97)
store i32 %98, i32* %12
%99 = load i32, i32* %12
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %95
%102 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %145
103: ; preds = %95
%104 = load i32, i32* %13
%105 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%106 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %105, i32 0, i32 1
%107 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %106, i32 0, i32 1
%108 = load i32*, i32** %107
%109 = getelementptr inbounds i32, i32* %108, i64 1
%110 = load i32, i32* %109
%111 = load i32, i32* @SEEK_SET
%112 = call i64 @lseek(i32 %104, i32 %110, i32 %111)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %103
%115 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %145
116: ; preds = %103
%117 = load i32, i32* %13
%118 = trunc i64 %23 to i32
%119 = call i32 @read(i32 %117, i8* %24, i32 %118)
store i32 %119, i32* %12
%120 = load i32, i32* %12
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %124
122: ; preds = %116
%123 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %145
124: ; preds = %116
%125 = call i32 @strncmp(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%126 = icmp ne i32 %125, 0
br i1 %126, label %144, label %127
127: ; preds = %124
%128 = call i32 @strncmp(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%129 = icmp ne i32 %128, 0
br i1 %129, label %144, label %130
130: ; preds = %127
%131 = load %struct.seccomp_notif*, %struct.seccomp_notif** %5
%132 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %131, i32 0, i32 1
%133 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %132, i32 0, i32 1
%134 = load i32*, i32** %133
%135 = getelementptr inbounds i32, i32* %134, i64 3
%136 = load i32, i32* %135
%137 = call i64 @mount(i8* %21, i8* %24, i32* null, i32 %136, i32* null)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %130
store i32 -1, i32* %12
%140 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %145
141: ; preds = %130
%142 = load %struct.seccomp_notif_resp*, %struct.seccomp_notif_resp** %6
%143 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %142, i32 0, i32 0
store i32 0, i32* %143
br label %144
144: ; preds = %141, %127, %124
store i32 0, i32* %12
br label %145
145: ; preds = %144, %139, %122, %114, %101, %93, %79
%146 = load i32, i32* %13
%147 = call i32 @close(i32 %146)
%148 = load i32, i32* %12
store i32 %148, i32* %4
store i32 1, i32* %14
br label %149
149: ; preds = %145, %70, %59, %42
%150 = load i8*, i8** %8
%151 = load i32, i32* %4
ret i32 %151
}

LLVM IR (-O2):
%struct.seccomp_notif = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64, i32* }
%struct.seccomp_notif_resp = type { i32, i64, i32 }
@PATH_MAX = global i32 0
@EPERM = global i32 0
@__NR_mount = global i64 0
@stderr = global i32 0
@.str = [42 x i8] c"huh? trapped something besides mount? %d\0A\00"
@MS_BIND = global i32 0
@.str.1 = [13 x i8] c"/proc/%d/mem\00"
@O_RDONLY = global i32 0
@.str.2 = [9 x i8] c"open mem\00"
@SECCOMP_IOCTL_NOTIF_ID_VALID = global i32 0
@.str.3 = [42 x i8] c"task died before we could map its memory\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [5 x i8] c"seek\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [6 x i8] c"/tmp/\00"
@.str.7 = [13 x i8] c"actual mount\00"
define i32 @handle_req(%struct.seccomp_notif* %0, %struct.seccomp_notif_resp* nocapture writeonly %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = alloca i8, i64 %5
%8 = alloca i8, i64 %5
%9 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %0, i64 0, i32 2
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %1, i64 0, i32 2
store i32 %10, i32* %11
%12 = load i32, i32* @EPERM
%13 = sub nsw i32 0, %12
%14 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %1, i64 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.seccomp_notif_resp, %struct.seccomp_notif_resp* %1, i64 0, i32 1
store i64 0, i64* %15
%16 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %0, i64 0, i32 1, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @__NR_mount
%19 = icmp eq i64 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 %17)
br label %92
23: ; preds = %3
%24 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %0, i64 0, i32 1, i32 1
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 3
%27 = load i32, i32* %26
%28 = load i32, i32* @MS_BIND
%29 = and i32 %28, %27
%30 = icmp eq i32 %29, 0
br i1 %30, label %92, label %31
31: ; preds = %23
%32 = getelementptr inbounds %struct.seccomp_notif, %struct.seccomp_notif* %0, i64 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @snprintf(i8* %6, i32 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %6, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %92
40: ; preds = %31
%41 = load i32, i32* @SECCOMP_IOCTL_NOTIF_ID_VALID
%42 = call i64 @ioctl(i32 %2, i32 %41, i32* %9)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
br label %89
47: ; preds = %40
%48 = load i32*, i32** %24
%49 = load i32, i32* %48
%50 = load i32, i32* @SEEK_SET
%51 = call i64 @lseek(i32 %36, i32 %49, i32 %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %89
55: ; preds = %47
%56 = call i32 @read(i32 %36, i8* %7, i32 %4)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %89
60: ; preds = %55
%61 = load i32*, i32** %24
%62 = getelementptr inbounds i32, i32* %61, i64 1
%63 = load i32, i32* %62
%64 = load i32, i32* @SEEK_SET
%65 = call i64 @lseek(i32 %36, i32 %63, i32 %64)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %89
69: ; preds = %60
%70 = call i32 @read(i32 %36, i8* %8, i32 %4)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %89
74: ; preds = %69
%75 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %89
77: ; preds = %74
%78 = call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 5)
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %89
80: ; preds = %77
%81 = load i32*, i32** %24
%82 = getelementptr inbounds i32, i32* %81, i64 3
%83 = load i32, i32* %82
%84 = call i64 @mount(i8* %7, i8* %8, i32* null, i32 %83, i32* null)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %80
%87 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %89
88: ; preds = %80
store i32 0, i32* %14
br label %89
89: ; preds = %74, %77, %88, %86, %72, %67, %58, %53, %44
%90 = phi i32 [ -1, %44 ], [ -1, %53 ], [ %56, %58 ], [ %56, %67 ], [ %70, %72 ], [ -1, %86 ], [ 0, %88 ], [ 0, %77 ], [ 0, %74 ]
%91 = call i32 @close(i32 %36)
br label %92
92: ; preds = %23, %89, %38, %20
%93 = phi i32 [ -1, %20 ], [ -1, %38 ], [ %90, %89 ], [ 0, %23 ]
ret i32 %93
}