#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 */
struct sock_fprog {
  unsigned short len;
  struct sock_filter *filter;
};
struct sock_filter {
  int dummy;
};
typedef int /*<<< orphan*/ filter;

/* Variables and functions */
scalar_t__ BPF_K;
scalar_t__ BPF_RET;
struct sock_filter BPF_STMT(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ PR_SET_SECCOMP;
int /*<<< orphan*/ SECCOMP_RET_ALLOW;
int /*<<< orphan*/ perror(char *);
scalar_t__ prctl(int /*<<< orphan*/, int, struct sock_fprog *);
void install_accept_all_seccomp(void) {
  struct sock_filter filter[] = {
      BPF_STMT(BPF_RET + BPF_K, SECCOMP_RET_ALLOW),
  };
  struct sock_fprog prog = {
      .len = (unsigned short)(sizeof(filter) / sizeof(filter[0])),
      .filter = filter,
  };
  if (prctl(PR_SET_SECCOMP, 2, &prog)) {
    perror("prctl");
  }
}


x86 assembly (clang, -O0):
<install_accept_all_seccomp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%rdi
mov    0x2e9f(%rip),%rax
add    (%rax),%rdi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
call   1040 <BPF_STMT@plt>
mov    %eax,-0x8(%rbp)
movw   $0x1,-0x18(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    $0x2,%esi
lea    -0x18(%rbp),%rdx
call   1030 <prctl@plt>
cmp    $0x0,%rax
je     1198 <install_accept_all_seccomp+0x68>
lea    0xe6d(%rip),%rdi
call   1050 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<install_accept_all_seccomp>:
sub    $0x18,%rsp
mov    0x2ea5(%rip),%rax
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%rdi
add    (%rax),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1040 <BPF_STMT@plt>
mov    %eax,(%rsp)
movw   $0x1,0x8(%rsp)
mov    %rsp,%rax
mov    %rax,0x10(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    $0x2,%esi
call   1030 <prctl@plt>
test   %rax,%rax
jne    118a <install_accept_all_seccomp+0x5a>
add    $0x18,%rsp
ret
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sock_filter = type { i32 }
%struct.sock_fprog = type { i16, %struct.sock_filter* }
@BPF_RET = global i64 0
@BPF_K = global i64 0
@SECCOMP_RET_ALLOW = global i32 0
@PR_SET_SECCOMP = global i32 0
@.str = [6 x i8] c"prctl\00"
define void @install_accept_all_seccomp() {
%1 = alloca [1 x %struct.sock_filter]
%2 = alloca %struct.sock_fprog
%3 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %1, i64 0, i64 0
%4 = load i64, i64* @BPF_RET
%5 = load i64, i64* @BPF_K
%6 = add nsw i64 %4, %5
%7 = load i32, i32* @SECCOMP_RET_ALLOW
%8 = call i32 @BPF_STMT(i64 %6, i32 %7)
%9 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %3, i32 0, i32 0
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %2, i32 0, i32 0
store i16 1, i16* %10
%11 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %2, i32 0, i32 1
%12 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %1, i64 0, i64 0
store %struct.sock_filter* %12, %struct.sock_filter** %11
%13 = load i32, i32* @PR_SET_SECCOMP
%14 = call i64 @prctl(i32 %13, i32 2, %struct.sock_fprog* %2)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %0
ret void
}

LLVM IR (-O2):
%struct.sock_filter = type { i32 }
%struct.sock_fprog = type { i16, %struct.sock_filter* }
@BPF_RET = global i64 0
@BPF_K = global i64 0
@SECCOMP_RET_ALLOW = global i32 0
@PR_SET_SECCOMP = global i32 0
@.str = [6 x i8] c"prctl\00"
define void @install_accept_all_seccomp() {
%1 = alloca [1 x %struct.sock_filter]
%2 = alloca %struct.sock_fprog
%3 = bitcast [1 x %struct.sock_filter]* %1 to i8*
%4 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %1, i64 0, i64 0
%5 = load i64, i64* @BPF_RET
%6 = load i64, i64* @BPF_K
%7 = add nsw i64 %6, %5
%8 = load i32, i32* @SECCOMP_RET_ALLOW
%9 = tail call i32 @BPF_STMT(i64 %7, i32 %8)
%10 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %1, i64 0, i64 0, i32 0
store i32 %9, i32* %10
%11 = bitcast %struct.sock_fprog* %2 to i8*
%12 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %2, i64 0, i32 0
store i16 1, i16* %12
%13 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %2, i64 0, i32 1
store %struct.sock_filter* %4, %struct.sock_filter** %13
%14 = load i32, i32* @PR_SET_SECCOMP
%15 = call i64 @prctl(i32 %14, i32 2, %struct.sock_fprog* %2)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %0
ret void
}