#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 member_0;
  int member_1;
  int member_2;
  int member_3;
};
typedef int /*<<< orphan*/ bpf_prog;
typedef int /*<<< orphan*/ bpf_filter;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ATTACH_FILTER;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                      struct sock_fprog *, int);
__attribute__((__unused__)) void pair_udp_setfilter(int fd) {
  struct sock_filter bpf_filter[] = {
      {0x28, 0, 0, 0x0000000c}, {0x15, 0, 8, 0x00000800},
      {0x30, 0, 0, 0x00000017}, {0x15, 0, 6, 0x00000011},
      {0x80, 0, 0, 0000000000}, {0x35, 0, 4, 0x00000064},
      {0x30, 0, 0, 0x00000050}, {0x15, 1, 0, 0x00000061},
      {0x15, 0, 1, 0x00000062}, {0x06, 0, 0, 0xffffffff},
      {0x06, 0, 0, 0000000000},
  };
  struct sock_fprog bpf_prog;
  bpf_prog.filter = bpf_filter;
  bpf_prog.len = sizeof(bpf_filter) / sizeof(struct sock_filter);
  if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_prog,
                 sizeof(bpf_prog))) {
    perror("setsockopt SO_ATTACH_FILTER");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<pair_udp_setfilter>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xea4(%rip),%rsi
mov    $0xb0,%edx
call   1040 <memcpy@plt>
lea    -0xc0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
movl   $0xb,-0xd0(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edx
lea    -0xd0(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
cmp    $0x0,%rax
je     11c5 <pair_udp_setfilter+0x85>
lea    0xefa(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pair_udp_setfilter>:
push   %rbp
push   %rbx
sub    $0xc8,%rsp
mov    %edi,%ebp
lea    0xeae(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    $0xb0,%edx
mov    %rbx,%rdi
call   1040 <memcpy@plt>
mov    %rbx,0x8(%rsp)
movl   $0xb,(%rsp)
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
test   %rax,%rax
jne    11a1 <pair_udp_setfilter+0x61>
add    $0xc8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xf08(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sock_filter = type { i32, i32, i32, i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@__const.pair_udp_setfilter.bpf_filter = [11 x %struct.sock_filter] [%struct.sock_filter { i32 40, i32 0, i32 0, i32 12 }, %struct.sock_filter { i32 21, i32 0, i32 8, i32 2048 }, %struct.sock_filter { i32 48, i32 0, i32 0, i32 23 }, %struct.sock_filter { i32 21, i32 0, i32 6, i32 17 }, %struct.sock_filter { i32 128, i32 0, i32 0, i32 0 }, %struct.sock_filter { i32 53, i32 0, i32 4, i32 100 }, %struct.sock_filter { i32 48, i32 0, i32 0, i32 80 }, %struct.sock_filter { i32 21, i32 1, i32 0, i32 97 }, %struct.sock_filter { i32 21, i32 0, i32 1, i32 98 }, %struct.sock_filter { i32 6, i32 0, i32 0, i32 -1 }, %struct.sock_filter { i32 6, i32 0, i32 0, i32 0 }]
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
@.str = [28 x i8] c"setsockopt SO_ATTACH_FILTER\00"
define void @pair_udp_setfilter(i32 %0) {
%2 = alloca i32
%3 = alloca [11 x %struct.sock_filter]
%4 = alloca %struct.sock_fprog
store i32 %0, i32* %2
%5 = bitcast [11 x %struct.sock_filter]* %3 to i8*
%6 = getelementptr inbounds [11 x %struct.sock_filter], [11 x %struct.sock_filter]* %3, i64 0, i64 0
%7 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %4, i32 0, i32 1
store %struct.sock_filter* %6, %struct.sock_filter** %7
%8 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %4, i32 0, i32 0
store i32 11, i32* %8
%9 = load i32, i32* %2
%10 = load i32, i32* @SOL_SOCKET
%11 = load i32, i32* @SO_ATTACH_FILTER
%12 = call i64 @setsockopt(i32 %9, i32 %10, i32 %11, %struct.sock_fprog* %4, i32 16)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
ret void
}

LLVM IR (-O2):
%struct.sock_filter = type { i32, i32, i32, i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@__const.pair_udp_setfilter.bpf_filter = [11 x %struct.sock_filter] [%struct.sock_filter { i32 40, i32 0, i32 0, i32 12 }, %struct.sock_filter { i32 21, i32 0, i32 8, i32 2048 }, %struct.sock_filter { i32 48, i32 0, i32 0, i32 23 }, %struct.sock_filter { i32 21, i32 0, i32 6, i32 17 }, %struct.sock_filter { i32 128, i32 0, i32 0, i32 0 }, %struct.sock_filter { i32 53, i32 0, i32 4, i32 100 }, %struct.sock_filter { i32 48, i32 0, i32 0, i32 80 }, %struct.sock_filter { i32 21, i32 1, i32 0, i32 97 }, %struct.sock_filter { i32 21, i32 0, i32 1, i32 98 }, %struct.sock_filter { i32 6, i32 0, i32 0, i32 -1 }, %struct.sock_filter { i32 6, i32 0, i32 0, i32 0 }]
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
@.str = [28 x i8] c"setsockopt SO_ATTACH_FILTER\00"
define void @pair_udp_setfilter(i32 %0) {
%2 = alloca [11 x %struct.sock_filter]
%3 = alloca %struct.sock_fprog
%4 = bitcast [11 x %struct.sock_filter]* %2 to i8*
%5 = bitcast %struct.sock_fprog* %3 to i8*
%6 = getelementptr inbounds [11 x %struct.sock_filter], [11 x %struct.sock_filter]* %2, i64 0, i64 0
%7 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %3, i64 0, i32 1
store %struct.sock_filter* %6, %struct.sock_filter** %7
%8 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %3, i64 0, i32 0
store i32 11, i32* %8
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_ATTACH_FILTER
%11 = call i64 @setsockopt(i32 %0, i32 %9, i32 %10, %struct.sock_fprog* %3, i32 16)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
ret void
}