#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 */
#define EFAULT 130
#define EINVAL 129
#define ENOSYS 128
int /*<<< orphan*/ PR_GET_SECCOMP;
int /*<<< orphan*/ PR_SET_SECCOMP;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int prctl(int /*<<< orphan*/, int, int /*<<< orphan*/ *, int /*<<< orphan*/,
          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int check_seccomp_filter(void) {
  int ret;
  ret = prctl(PR_GET_SECCOMP, 0, 0, 0, 0);
  if (ret < 0) {
    switch (errno) {
    case ENOSYS:
      printf("seccomp not available: pre-2.6.23\n");
      return 0;
    case EINVAL:
      printf("seccomp not available: not built in\n");
      return 0;
    default:
      fprintf(stderr, "unknown PR_GET_SECCOMP error: %s\n", strerror(errno));
      return 0;
    }
  }
  printf("seccomp available\n");
  ret = prctl(PR_SET_SECCOMP, 2, NULL, 0, 0);
  if (ret < 0) {
    switch (errno) {
    case EINVAL:
      printf("seccomp filter not available\n");
      return 0;
    case EFAULT:
      printf("seccomp filter available\n");
      return 1;
    default:
      fprintf(stderr, "unknown PR_SET_SECCOMP error: %s\n", strerror(errno));
      return 0;
    }
  }
  printf("PR_SET_SECCOMP unexpectedly succeeded?!\n");
  return 1;
}


x86 assembly (clang, -O0):
<check_seccomp_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%edx
mov    %r8d,%esi
mov    %r8d,%ecx
call   1050 <prctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1207 <check_seccomp_filter+0xc7>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
sub    $0x80,%eax
je     119f <check_seccomp_filter+0x5f>
jmp    118c <check_seccomp_filter+0x4c>
mov    -0xc(%rbp),%eax
sub    $0x81,%eax
je     11b7 <check_seccomp_filter+0x77>
jmp    11cf <check_seccomp_filter+0x8f>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <check_seccomp_filter+0x1a7>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <check_seccomp_filter+0x1a7>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe52(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <check_seccomp_filter+0x1a7>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
xor    %eax,%eax
mov    %eax,%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1050 <prctl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12d4 <check_seccomp_filter+0x194>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x81,%eax
je     126c <check_seccomp_filter+0x12c>
jmp    1259 <check_seccomp_filter+0x119>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
je     1284 <check_seccomp_filter+0x144>
jmp    129c <check_seccomp_filter+0x15c>
lea    0xe0a(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <check_seccomp_filter+0x1a7>
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e7 <check_seccomp_filter+0x1a7>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xdf2(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e7 <check_seccomp_filter+0x1a7>
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_seccomp_filter>:
push   %rbx
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <prctl@plt>
test   %eax,%eax
js     1199 <check_seccomp_filter+0x59>
lea    0xee1(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <prctl@plt>
test   %eax,%eax
js     11bb <check_seccomp_filter+0x7b>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
ret
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
cmp    $0x81,%edi
je     11dd <check_seccomp_filter+0x9d>
cmp    $0x80,%edi
jne    11eb <check_seccomp_filter+0xab>
lea    0xf1f(%rip),%rdi
jmp    11e4 <check_seccomp_filter+0xa4>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
cmp    $0x82,%edi
je     1202 <check_seccomp_filter+0xc2>
cmp    $0x81,%edi
jne    120b <check_seccomp_filter+0xcb>
lea    0xebc(%rip),%rdi
jmp    11e4 <check_seccomp_filter+0xa4>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
jmp    122a <check_seccomp_filter+0xea>
mov    0x2de6(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe00(%rip),%rsi
jmp    1220 <check_seccomp_filter+0xe0>
lea    0xe75(%rip),%rdi
jmp    118d <check_seccomp_filter+0x4d>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ebx
call   1060 <strerror@plt>
lea    0xe02(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PR_GET_SECCOMP = global i32 0
@errno = global i32 0
@.str = [35 x i8] c"seccomp not available: pre-2.6.23\0A\00"
@.str.1 = [37 x i8] c"seccomp not available: not built in\0A\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"unknown PR_GET_SECCOMP error: %s\0A\00"
@.str.3 = [19 x i8] c"seccomp available\0A\00"
@PR_SET_SECCOMP = global i32 0
@.str.4 = [30 x i8] c"seccomp filter not available\0A\00"
@.str.5 = [26 x i8] c"seccomp filter available\0A\00"
@.str.6 = [34 x i8] c"unknown PR_SET_SECCOMP error: %s\0A\00"
@.str.7 = [41 x i8] c"PR_SET_SECCOMP unexpectedly succeeded?!\0A\00"
define i32 @check_seccomp_filter() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @PR_GET_SECCOMP
%4 = call i32 @prctl(i32 %3, i32 0, i32* null, i32 0, i32 0)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %0
%8 = load i32, i32* @errno
switch i32 %8, label %13 [
i32 128, label %9
i32 129, label %11
]
9: ; preds = %7
%10 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %37
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %37
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %16)
store i32 0, i32* %1
br label %37
18: ; preds = %0
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @PR_SET_SECCOMP
%21 = call i32 @prctl(i32 %20, i32 2, i32* null, i32 0, i32 0)
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %35
24: ; preds = %18
%25 = load i32, i32* @errno
switch i32 %25, label %30 [
i32 129, label %26
i32 130, label %28
]
26: ; preds = %24
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %1
br label %37
28: ; preds = %24
%29 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %37
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %33)
store i32 0, i32* %1
br label %37
35: ; preds = %18
%36 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %1
br label %37
37: ; preds = %35, %30, %28, %26, %13, %11, %9
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@PR_GET_SECCOMP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str.2 = [34 x i8] c"unknown PR_GET_SECCOMP error: %s\0A\00"
@PR_SET_SECCOMP = global i32 0
@.str.6 = [34 x i8] c"unknown PR_SET_SECCOMP error: %s\0A\00"
@str = [18 x i8] c"seccomp available\00"
@str.8 = [40 x i8] c"PR_SET_SECCOMP unexpectedly succeeded?!\00"
@str.9 = [25 x i8] c"seccomp filter available\00"
@str.10 = [29 x i8] c"seccomp filter not available\00"
@str.11 = [36 x i8] c"seccomp not available: not built in\00"
@str.12 = [34 x i8] c"seccomp not available: pre-2.6.23\00"
define i32 @check_seccomp_filter() {
%1 = load i32, i32* @PR_GET_SECCOMP
%2 = tail call i32 @prctl(i32 %1, i32 0, i32* null, i32 0, i32 0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0
%5 = load i32, i32* @errno
switch i32 %5, label %10 [
i32 128, label %6
i32 129, label %8
]
6: ; preds = %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.12, i64 0, i64 0))
br label %31
8: ; preds = %4
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.11, i64 0, i64 0))
br label %31
10: ; preds = %4
%11 = load i32, i32* @stderr
%12 = tail call i8* @strerror(i32 %5)
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %31
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @PR_SET_SECCOMP
%17 = tail call i32 @prctl(i32 %16, i32 2, i32* null, i32 0, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = load i32, i32* @errno
switch i32 %20, label %25 [
i32 129, label %21
i32 130, label %23
]
21: ; preds = %19
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.10, i64 0, i64 0))
br label %31
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
br label %31
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = tail call i8* @strerror(i32 %20)
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %27)
br label %31
29: ; preds = %14
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
br label %31
31: ; preds = %29, %25, %23, %21, %10, %8, %6
%32 = phi i32 [ 0, %10 ], [ 0, %8 ], [ 0, %6 ], [ 0, %25 ], [ 1, %23 ], [ 0, %21 ], [ 1, %29 ]
ret i32 %32
}