#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 {
  int len;
  struct sock_filter *filter;
};
struct sock_filter {
  int dummy;
};
typedef int /*<<< orphan*/ prog;
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*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ATTACH_FILTER;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct sock_fprog *, int);
void set_filter_null(int fd) {
  struct sock_filter filter[] = {
      BPF_STMT(BPF_RET + BPF_K, 0),
  };
  struct sock_fprog prog = {};
  prog.filter = filter;
  prog.len = sizeof(filter) / sizeof(struct sock_filter);
  if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog)))
    error(1, errno, "setsockopt filter");
}


x86 assembly (clang, -O0):
<set_filter_null>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%rdi
mov    0x2e84(%rip),%rax
add    (%rax),%rdi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11d0 <set_filter_null+0x90>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe35(%rip),%rdx
call   1050 <error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_filter_null>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    0x2e9a(%rip),%rax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%rdi
add    (%rax),%rdi
xor    %esi,%esi
call   1050 <BPF_STMT@plt>
mov    %eax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
movl   $0x1,0x10(%rsp)
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
je     11b4 <set_filter_null+0x84>
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sock_filter = type { i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@BPF_RET = global i64 0
@BPF_K = global i64 0
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
@errno = global i32 0
@.str = [18 x i8] c"setsockopt filter\00"
define void @set_filter_null(i32 %0) {
%2 = alloca i32
%3 = alloca [1 x %struct.sock_filter]
%4 = alloca %struct.sock_fprog
store i32 %0, i32* %2
%5 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %3, i64 0, i64 0
%6 = load i64, i64* @BPF_RET
%7 = load i64, i64* @BPF_K
%8 = add nsw i64 %6, %7
%9 = call i32 @BPF_STMT(i64 %8, i32 0)
%10 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %5, i32 0, i32 0
store i32 %9, i32* %10
%11 = bitcast %struct.sock_fprog* %4 to i8*
%12 = getelementptr inbounds [1 x %struct.sock_filter], [1 x %struct.sock_filter]* %3, i64 0, i64 0
%13 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %4, i32 0, i32 1
store %struct.sock_filter* %12, %struct.sock_filter** %13
%14 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %4, i32 0, i32 0
store i32 1, i32* %14
%15 = load i32, i32* %2
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_ATTACH_FILTER
%18 = call i64 @setsockopt(i32 %15, i32 %16, i32 %17, %struct.sock_fprog* %4, i32 16)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = load i32, i32* @errno
%22 = call i32 @error(i32 1, i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %1
ret void
}

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