#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*/ filter_prog;
typedef int /*<<< orphan*/ filter_instr;

/* Variables and functions */
int BPF_ABS;
int BPF_ADD;
int BPF_ALU;
int BPF_AND;
int BPF_B;
int BPF_H;
int BPF_IMM;
int BPF_IND;
int BPF_JEQ;
int BPF_JMP;
struct sock_filter BPF_JUMP(int, int, int, int);
int BPF_K;
int BPF_LD;
int BPF_LDX;
int BPF_MEM;
int BPF_MUL;
int BPF_RET;
int BPF_ST;
struct sock_filter BPF_STMT(int, int);
int BPF_W;
int BPF_X;
int ETH_P_IP;
int IPPROTO_TCP;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ATTACH_FILTER;
int /*<<< orphan*/ memset(struct sock_fprog *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, struct sock_fprog *,
               int);
int attach_mkap_conn_filter(int sock, unsigned int linktype) {
  struct sock_filter raw_ip_patch = BPF_STMT(BPF_LDX | BPF_W | BPF_IMM, 0);
  struct sock_filter filter_instr[] = {
      BPF_STMT(BPF_LDX | BPF_W | BPF_IMM, 14),
      BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x8100, 0, 2),
      BPF_STMT(BPF_LDX | BPF_W | BPF_IMM, 18),
      BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, ETH_P_IP, 0, 12),
      BPF_STMT(BPF_LD | BPF_B | BPF_IND, 9),
      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, IPPROTO_TCP, 0, 10),
      BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0),
      BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F),
      BPF_STMT(BPF_ALU | BPF_MUL | BPF_K, 4),
      BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0),
      BPF_STMT(BPF_ST, 0),
      BPF_STMT(BPF_LDX | BPF_W | BPF_MEM, 0),
      BPF_STMT(BPF_LD | BPF_H | BPF_IND, 0),
      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 54321, 3, 0),
      BPF_STMT(BPF_LD | BPF_H | BPF_IND, 2),
      BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 54321, 1, 0),
      BPF_STMT(BPF_RET | BPF_K, 0x00FFFFFF),
      BPF_STMT(BPF_RET | BPF_K, 0),
  };
  struct sock_fprog filter_prog;
  memset(&filter_prog, 0, sizeof(filter_prog));
  filter_prog.len = sizeof(filter_instr) / sizeof(filter_instr[0]);
  filter_prog.filter = filter_instr;
  if (linktype == 12) {
    filter_instr[5] = raw_ip_patch;
    filter_prog.len -= 5;
    filter_prog.filter = &filter_instr[5];
  }
  return setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
                    sizeof(filter_prog));
}


x86 assembly (clang, -O0):
<attach_mkap_conn_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
mov    0x2e7a(%rip),%rax
or     (%rax),%edi
mov    0x2e11(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x2e55(%rip),%rax
or     (%rax),%edi
mov    0x2dec(%rip),%rax
or     (%rax),%edi
mov    $0xe,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x60(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2dbd(%rip),%rax
or     (%rax),%edi
mov    0x2dec(%rip),%rax
or     (%rax),%edi
mov    $0xc,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x5c(%rbp)
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
or     (%rax),%edi
mov    0x2ddc(%rip),%rax
or     (%rax),%edi
mov    $0x8100,%esi
xor    %edx,%edx
mov    $0x2,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,-0x58(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dd6(%rip),%rax
or     (%rax),%edi
mov    0x2d6d(%rip),%rax
or     (%rax),%edi
mov    $0x12,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x54(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x2d3e(%rip),%rax
or     (%rax),%edi
mov    0x2d6d(%rip),%rax
or     (%rax),%edi
mov    $0x10,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x50(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    0x2d76(%rip),%rax
or     (%rax),%edi
mov    0x2d5d(%rip),%rax
or     (%rax),%edi
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0xc,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,-0x4c(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
mov    0x2cdb(%rip),%rax
or     (%rax),%edi
mov    0x2caa(%rip),%rax
or     (%rax),%edi
mov    $0x9,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x48(%rbp)
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
mov    0x2d1b(%rip),%rax
or     (%rax),%edi
mov    0x2d02(%rip),%rax
or     (%rax),%edi
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0xa,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,-0x44(%rbp)
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
mov    0x2c80(%rip),%rax
or     (%rax),%edi
mov    0x2c4f(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x40(%rbp)
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
mov    0x2cf3(%rip),%rax
or     (%rax),%edi
mov    0x2caa(%rip),%rax
or     (%rax),%edi
mov    $0xf,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x3c(%rbp)
mov    0x2c2c(%rip),%rax
mov    (%rax),%edi
mov    0x2cc3(%rip),%rax
or     (%rax),%edi
mov    0x2c82(%rip),%rax
or     (%rax),%edi
mov    $0x4,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x38(%rbp)
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
mov    0x2c43(%rip),%rax
or     (%rax),%edi
mov    0x2c22(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x34(%rbp)
mov    0x2bb7(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x30(%rbp)
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
mov    0x2c4b(%rip),%rax
or     (%rax),%edi
mov    0x2bb2(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
mov    0x2bb6(%rip),%rax
or     (%rax),%edi
mov    0x2b7d(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x28(%rbp)
mov    0x2b8a(%rip),%rax
mov    (%rax),%edi
mov    0x2bf1(%rip),%rax
or     (%rax),%edi
mov    0x2bd8(%rip),%rax
or     (%rax),%edi
mov    $0xd431,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,-0x24(%rbp)
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
mov    0x2b62(%rip),%rax
or     (%rax),%edi
mov    0x2b29(%rip),%rax
or     (%rax),%edi
mov    $0x2,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x20(%rbp)
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
mov    0x2b9a(%rip),%rax
or     (%rax),%edi
mov    0x2b81(%rip),%rax
or     (%rax),%edi
mov    $0xd431,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2b5c(%rip),%rax
mov    (%rax),%edi
mov    0x2b5b(%rip),%rax
or     (%rax),%edi
mov    $0xffffff,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x18(%rbp)
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
mov    0x2b3c(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,-0x14(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0x14,-0x70(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpl   $0xc,-0x8(%rbp)
jne    14cc <attach_mkap_conn_filter+0x38c>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x70(%rbp),%eax
sub    $0x5,%eax
mov    %eax,-0x70(%rbp)
lea    -0x60(%rbp),%rax
add    $0x14,%rax
mov    %rax,-0x68(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2aea(%rip),%rax
mov    (%rax),%esi
mov    0x2ac9(%rip),%rax
mov    (%rax),%edx
lea    -0x70(%rbp),%rcx
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<attach_mkap_conn_filter>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e93(%rip),%rcx
mov    0x2e7c(%rip),%rdx
mov    (%rdx),%eax
mov    %rdx,%rbp
or     (%rcx),%eax
mov    %rcx,%rbx
mov    %esi,0x8(%rsp)
mov    %edi,0xc(%rsp)
mov    0x2e03(%rip),%r15
or     (%r15),%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x4(%rsp)
mov    0x0(%rbp),%edi
or     (%rbx),%edi
or     (%r15),%edi
mov    $0xe,%esi
call   1060 <BPF_STMT@plt>
mov    0x2dd2(%rip),%r14
mov    0x2dc3(%rip),%rbp
mov    0x0(%rbp),%edi
or     (%r14),%edi
mov    %eax,0x20(%rsp)
mov    0x2dea(%rip),%rax
or     (%rax),%edi
mov    $0xc,%esi
call   1060 <BPF_STMT@plt>
mov    0x2d8f(%rip),%rcx
mov    0x2df8(%rip),%r13
mov    0x0(%r13),%edi
or     (%rcx),%edi
mov    %rcx,%rbx
mov    %eax,0x24(%rsp)
mov    0x2dd4(%rip),%r12
or     (%r12),%edi
mov    $0x8100,%esi
xor    %edx,%edx
mov    $0x2,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,0x28(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
or     (%rax),%edi
or     (%r15),%edi
mov    $0x12,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x2c(%rsp)
mov    0x0(%rbp),%edi
or     (%r14),%edi
mov    %r14,%rbp
mov    0x2d70(%rip),%rax
or     (%rax),%edi
mov    $0x10,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x30(%rsp)
mov    0x0(%r13),%edi
or     (%rbx),%edi
mov    %rbx,%r14
or     (%r12),%edi
mov    0x2cec(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0xc,%ecx
call   1050 <BPF_JUMP@plt>
mov    0x2cf7(%rip),%rbx
mov    (%rbx),%edi
or     0x0(%rbp),%edi
mov    %eax,0x34(%rsp)
mov    0x2cbf(%rip),%r15
or     (%r15),%edi
mov    $0x9,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x38(%rsp)
mov    0x0(%r13),%edi
or     (%r14),%edi
or     (%r12),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    $0xa,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,0x3c(%rsp)
mov    (%rbx),%edi
or     0x0(%rbp),%edi
or     (%r15),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x40(%rsp)
mov    0x2c88(%rip),%rbx
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
or     (%rbx),%edi
or     (%r12),%edi
mov    $0xf,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x44(%rsp)
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
or     (%rbx),%edi
or     (%r12),%edi
mov    $0x4,%esi
call   1060 <BPF_STMT@plt>
mov    0x2c93(%rip),%rcx
mov    (%rcx),%edi
or     (%rbx),%edi
mov    %eax,0x48(%rsp)
mov    0x2c6c(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x4c(%rsp)
mov    0x2c00(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    0x2ca0(%rip),%rcx
mov    (%rcx),%edi
mov    0x2ca7(%rip),%rcx
or     (%rcx),%edi
mov    %eax,0x50(%rsp)
mov    0x2bfa(%rip),%rax
or     (%rax),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x54(%rsp)
mov    0x2c06(%rip),%rbx
mov    (%rbx),%edi
or     0x0(%rbp),%edi
or     (%r15),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x58(%rsp)
mov    0x0(%r13),%edi
or     (%r14),%edi
or     (%r12),%edi
mov    $0xd431,%esi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,0x5c(%rsp)
mov    (%rbx),%edi
or     0x0(%rbp),%edi
or     (%r15),%edi
mov    $0x2,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x60(%rsp)
mov    0x0(%r13),%edi
or     (%r14),%edi
or     (%r12),%edi
mov    $0xd431,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1050 <BPF_JUMP@plt>
mov    %eax,0x64(%rsp)
mov    0x2bde(%rip),%rbx
mov    (%r12),%edi
or     (%rbx),%edi
mov    $0xffffff,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x68(%rsp)
mov    (%r12),%edi
or     (%rbx),%edi
xor    %esi,%esi
call   1060 <BPF_STMT@plt>
mov    %eax,0x6c(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movl   $0x14,0x10(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x18(%rsp)
cmpl   $0xc,0x8(%rsp)
jne    143b <attach_mkap_conn_filter+0x2fb>
lea    0x34(%rsp),%rax
mov    0x4(%rsp),%ecx
mov    %ecx,0x34(%rsp)
movl   $0xf,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    0x2b7e(%rip),%rax
mov    (%rax),%esi
mov    0x2b5d(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    0xc(%rsp),%edi
mov    $0x10,%r8d
call   1030 <setsockopt@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sock_filter = type { i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@BPF_LDX = global i32 0
@BPF_W = global i32 0
@BPF_IMM = global i32 0
@BPF_LD = global i32 0
@BPF_H = global i32 0
@BPF_ABS = global i32 0
@BPF_JMP = global i32 0
@BPF_JEQ = global i32 0
@BPF_K = global i32 0
@ETH_P_IP = global i32 0
@BPF_B = global i32 0
@BPF_IND = global i32 0
@IPPROTO_TCP = global i32 0
@BPF_ALU = global i32 0
@BPF_AND = global i32 0
@BPF_MUL = global i32 0
@BPF_ADD = global i32 0
@BPF_X = global i32 0
@BPF_ST = global i32 0
@BPF_MEM = global i32 0
@BPF_RET = global i32 0
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
define i32 @attach_mkap_conn_filter(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sock_filter
%6 = alloca [20 x %struct.sock_filter]
%7 = alloca %struct.sock_fprog
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* @BPF_LDX
%9 = load i32, i32* @BPF_W
%10 = or i32 %8, %9
%11 = load i32, i32* @BPF_IMM
%12 = or i32 %10, %11
%13 = call i32 @BPF_STMT(i32 %12, i32 0)
%14 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %5, i32 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %6, i64 0, i64 0
%16 = load i32, i32* @BPF_LDX
%17 = load i32, i32* @BPF_W
%18 = or i32 %16, %17
%19 = load i32, i32* @BPF_IMM
%20 = or i32 %18, %19
%21 = call i32 @BPF_STMT(i32 %20, i32 14)
%22 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %15, i32 0, i32 0
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %15, i64 1
%24 = load i32, i32* @BPF_LD
%25 = load i32, i32* @BPF_H
%26 = or i32 %24, %25
%27 = load i32, i32* @BPF_ABS
%28 = or i32 %26, %27
%29 = call i32 @BPF_STMT(i32 %28, i32 12)
%30 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %23, i32 0, i32 0
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %23, i64 1
%32 = load i32, i32* @BPF_JMP
%33 = load i32, i32* @BPF_JEQ
%34 = or i32 %32, %33
%35 = load i32, i32* @BPF_K
%36 = or i32 %34, %35
%37 = call i32 @BPF_JUMP(i32 %36, i32 33024, i32 0, i32 2)
%38 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %31, i32 0, i32 0
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %31, i64 1
%40 = load i32, i32* @BPF_LDX
%41 = load i32, i32* @BPF_W
%42 = or i32 %40, %41
%43 = load i32, i32* @BPF_IMM
%44 = or i32 %42, %43
%45 = call i32 @BPF_STMT(i32 %44, i32 18)
%46 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %39, i32 0, i32 0
store i32 %45, i32* %46
%47 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %39, i64 1
%48 = load i32, i32* @BPF_LD
%49 = load i32, i32* @BPF_H
%50 = or i32 %48, %49
%51 = load i32, i32* @BPF_ABS
%52 = or i32 %50, %51
%53 = call i32 @BPF_STMT(i32 %52, i32 16)
%54 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %47, i32 0, i32 0
store i32 %53, i32* %54
%55 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %47, i64 1
%56 = load i32, i32* @BPF_JMP
%57 = load i32, i32* @BPF_JEQ
%58 = or i32 %56, %57
%59 = load i32, i32* @BPF_K
%60 = or i32 %58, %59
%61 = load i32, i32* @ETH_P_IP
%62 = call i32 @BPF_JUMP(i32 %60, i32 %61, i32 0, i32 12)
%63 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %55, i32 0, i32 0
store i32 %62, i32* %63
%64 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %55, i64 1
%65 = load i32, i32* @BPF_LD
%66 = load i32, i32* @BPF_B
%67 = or i32 %65, %66
%68 = load i32, i32* @BPF_IND
%69 = or i32 %67, %68
%70 = call i32 @BPF_STMT(i32 %69, i32 9)
%71 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %64, i32 0, i32 0
store i32 %70, i32* %71
%72 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %64, i64 1
%73 = load i32, i32* @BPF_JMP
%74 = load i32, i32* @BPF_JEQ
%75 = or i32 %73, %74
%76 = load i32, i32* @BPF_K
%77 = or i32 %75, %76
%78 = load i32, i32* @IPPROTO_TCP
%79 = call i32 @BPF_JUMP(i32 %77, i32 %78, i32 0, i32 10)
%80 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %72, i32 0, i32 0
store i32 %79, i32* %80
%81 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %72, i64 1
%82 = load i32, i32* @BPF_LD
%83 = load i32, i32* @BPF_B
%84 = or i32 %82, %83
%85 = load i32, i32* @BPF_IND
%86 = or i32 %84, %85
%87 = call i32 @BPF_STMT(i32 %86, i32 0)
%88 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %81, i32 0, i32 0
store i32 %87, i32* %88
%89 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %81, i64 1
%90 = load i32, i32* @BPF_ALU
%91 = load i32, i32* @BPF_AND
%92 = or i32 %90, %91
%93 = load i32, i32* @BPF_K
%94 = or i32 %92, %93
%95 = call i32 @BPF_STMT(i32 %94, i32 15)
%96 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %89, i32 0, i32 0
store i32 %95, i32* %96
%97 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %89, i64 1
%98 = load i32, i32* @BPF_ALU
%99 = load i32, i32* @BPF_MUL
%100 = or i32 %98, %99
%101 = load i32, i32* @BPF_K
%102 = or i32 %100, %101
%103 = call i32 @BPF_STMT(i32 %102, i32 4)
%104 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %97, i32 0, i32 0
store i32 %103, i32* %104
%105 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %97, i64 1
%106 = load i32, i32* @BPF_ALU
%107 = load i32, i32* @BPF_ADD
%108 = or i32 %106, %107
%109 = load i32, i32* @BPF_X
%110 = or i32 %108, %109
%111 = call i32 @BPF_STMT(i32 %110, i32 0)
%112 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %105, i32 0, i32 0
store i32 %111, i32* %112
%113 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %105, i64 1
%114 = load i32, i32* @BPF_ST
%115 = call i32 @BPF_STMT(i32 %114, i32 0)
%116 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %113, i32 0, i32 0
store i32 %115, i32* %116
%117 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %113, i64 1
%118 = load i32, i32* @BPF_LDX
%119 = load i32, i32* @BPF_W
%120 = or i32 %118, %119
%121 = load i32, i32* @BPF_MEM
%122 = or i32 %120, %121
%123 = call i32 @BPF_STMT(i32 %122, i32 0)
%124 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %117, i32 0, i32 0
store i32 %123, i32* %124
%125 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %117, i64 1
%126 = load i32, i32* @BPF_LD
%127 = load i32, i32* @BPF_H
%128 = or i32 %126, %127
%129 = load i32, i32* @BPF_IND
%130 = or i32 %128, %129
%131 = call i32 @BPF_STMT(i32 %130, i32 0)
%132 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %125, i32 0, i32 0
store i32 %131, i32* %132
%133 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %125, i64 1
%134 = load i32, i32* @BPF_JMP
%135 = load i32, i32* @BPF_JEQ
%136 = or i32 %134, %135
%137 = load i32, i32* @BPF_K
%138 = or i32 %136, %137
%139 = call i32 @BPF_JUMP(i32 %138, i32 54321, i32 3, i32 0)
%140 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %133, i32 0, i32 0
store i32 %139, i32* %140
%141 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %133, i64 1
%142 = load i32, i32* @BPF_LD
%143 = load i32, i32* @BPF_H
%144 = or i32 %142, %143
%145 = load i32, i32* @BPF_IND
%146 = or i32 %144, %145
%147 = call i32 @BPF_STMT(i32 %146, i32 2)
%148 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %141, i32 0, i32 0
store i32 %147, i32* %148
%149 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %141, i64 1
%150 = load i32, i32* @BPF_JMP
%151 = load i32, i32* @BPF_JEQ
%152 = or i32 %150, %151
%153 = load i32, i32* @BPF_K
%154 = or i32 %152, %153
%155 = call i32 @BPF_JUMP(i32 %154, i32 54321, i32 1, i32 0)
%156 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %149, i32 0, i32 0
store i32 %155, i32* %156
%157 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %149, i64 1
%158 = load i32, i32* @BPF_RET
%159 = load i32, i32* @BPF_K
%160 = or i32 %158, %159
%161 = call i32 @BPF_STMT(i32 %160, i32 16777215)
%162 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %157, i32 0, i32 0
store i32 %161, i32* %162
%163 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %157, i64 1
%164 = load i32, i32* @BPF_RET
%165 = load i32, i32* @BPF_K
%166 = or i32 %164, %165
%167 = call i32 @BPF_STMT(i32 %166, i32 0)
%168 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %163, i32 0, i32 0
store i32 %167, i32* %168
%169 = call i32 @memset(%struct.sock_fprog* %7, i32 0, i32 16)
%170 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %7, i32 0, i32 0
store i32 20, i32* %170
%171 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %6, i64 0, i64 0
%172 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %7, i32 0, i32 1
store %struct.sock_filter* %171, %struct.sock_filter** %172
%173 = load i32, i32* %4
%174 = icmp eq i32 %173, 12
br i1 %174, label %175, label %184
175: ; preds = %2
%176 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %6, i64 0, i64 5
%177 = bitcast %struct.sock_filter* %176 to i8*
%178 = bitcast %struct.sock_filter* %5 to i8*
%179 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %7, i32 0, i32 0
%180 = load i32, i32* %179
%181 = sub nsw i32 %180, 5
store i32 %181, i32* %179
%182 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %6, i64 0, i64 5
%183 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %7, i32 0, i32 1
store %struct.sock_filter* %182, %struct.sock_filter** %183
br label %184
184: ; preds = %175, %2
%185 = load i32, i32* %3
%186 = load i32, i32* @SOL_SOCKET
%187 = load i32, i32* @SO_ATTACH_FILTER
%188 = call i32 @setsockopt(i32 %185, i32 %186, i32 %187, %struct.sock_fprog* %7, i32 16)
ret i32 %188
}

LLVM IR (-O2):
%struct.sock_filter = type { i32 }
%struct.sock_fprog = type { i32, %struct.sock_filter* }
@BPF_LDX = global i32 0
@BPF_W = global i32 0
@BPF_IMM = global i32 0
@BPF_LD = global i32 0
@BPF_H = global i32 0
@BPF_ABS = global i32 0
@BPF_JMP = global i32 0
@BPF_JEQ = global i32 0
@BPF_K = global i32 0
@ETH_P_IP = global i32 0
@BPF_B = global i32 0
@BPF_IND = global i32 0
@IPPROTO_TCP = global i32 0
@BPF_ALU = global i32 0
@BPF_AND = global i32 0
@BPF_MUL = global i32 0
@BPF_ADD = global i32 0
@BPF_X = global i32 0
@BPF_ST = global i32 0
@BPF_MEM = global i32 0
@BPF_RET = global i32 0
@SOL_SOCKET = global i32 0
@SO_ATTACH_FILTER = global i32 0
define i32 @attach_mkap_conn_filter(i32 %0, i32 %1) {
%3 = alloca [20 x %struct.sock_filter]
%4 = alloca %struct.sock_fprog
%5 = load i32, i32* @BPF_LDX
%6 = load i32, i32* @BPF_W
%7 = or i32 %6, %5
%8 = load i32, i32* @BPF_IMM
%9 = or i32 %7, %8
%10 = tail call i32 @BPF_STMT(i32 %9, i32 0)
%11 = bitcast [20 x %struct.sock_filter]* %3 to i8*
%12 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 0
%13 = load i32, i32* @BPF_LDX
%14 = load i32, i32* @BPF_W
%15 = or i32 %14, %13
%16 = load i32, i32* @BPF_IMM
%17 = or i32 %15, %16
%18 = tail call i32 @BPF_STMT(i32 %17, i32 14)
%19 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @BPF_LD
%21 = load i32, i32* @BPF_H
%22 = or i32 %21, %20
%23 = load i32, i32* @BPF_ABS
%24 = or i32 %22, %23
%25 = tail call i32 @BPF_STMT(i32 %24, i32 12)
%26 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 1, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @BPF_JMP
%28 = load i32, i32* @BPF_JEQ
%29 = or i32 %28, %27
%30 = load i32, i32* @BPF_K
%31 = or i32 %29, %30
%32 = tail call i32 @BPF_JUMP(i32 %31, i32 33024, i32 0, i32 2)
%33 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 2, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* @BPF_LDX
%35 = load i32, i32* @BPF_W
%36 = or i32 %35, %34
%37 = load i32, i32* @BPF_IMM
%38 = or i32 %36, %37
%39 = tail call i32 @BPF_STMT(i32 %38, i32 18)
%40 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 3, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* @BPF_LD
%42 = load i32, i32* @BPF_H
%43 = or i32 %42, %41
%44 = load i32, i32* @BPF_ABS
%45 = or i32 %43, %44
%46 = tail call i32 @BPF_STMT(i32 %45, i32 16)
%47 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 4, i32 0
store i32 %46, i32* %47
%48 = load i32, i32* @BPF_JMP
%49 = load i32, i32* @BPF_JEQ
%50 = or i32 %49, %48
%51 = load i32, i32* @BPF_K
%52 = or i32 %50, %51
%53 = load i32, i32* @ETH_P_IP
%54 = tail call i32 @BPF_JUMP(i32 %52, i32 %53, i32 0, i32 12)
%55 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 5, i32 0
store i32 %54, i32* %55
%56 = load i32, i32* @BPF_LD
%57 = load i32, i32* @BPF_B
%58 = or i32 %57, %56
%59 = load i32, i32* @BPF_IND
%60 = or i32 %58, %59
%61 = tail call i32 @BPF_STMT(i32 %60, i32 9)
%62 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 6, i32 0
store i32 %61, i32* %62
%63 = load i32, i32* @BPF_JMP
%64 = load i32, i32* @BPF_JEQ
%65 = or i32 %64, %63
%66 = load i32, i32* @BPF_K
%67 = or i32 %65, %66
%68 = load i32, i32* @IPPROTO_TCP
%69 = tail call i32 @BPF_JUMP(i32 %67, i32 %68, i32 0, i32 10)
%70 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 7, i32 0
store i32 %69, i32* %70
%71 = load i32, i32* @BPF_LD
%72 = load i32, i32* @BPF_B
%73 = or i32 %72, %71
%74 = load i32, i32* @BPF_IND
%75 = or i32 %73, %74
%76 = tail call i32 @BPF_STMT(i32 %75, i32 0)
%77 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 8, i32 0
store i32 %76, i32* %77
%78 = load i32, i32* @BPF_ALU
%79 = load i32, i32* @BPF_AND
%80 = or i32 %79, %78
%81 = load i32, i32* @BPF_K
%82 = or i32 %80, %81
%83 = tail call i32 @BPF_STMT(i32 %82, i32 15)
%84 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 9, i32 0
store i32 %83, i32* %84
%85 = load i32, i32* @BPF_ALU
%86 = load i32, i32* @BPF_MUL
%87 = or i32 %86, %85
%88 = load i32, i32* @BPF_K
%89 = or i32 %87, %88
%90 = tail call i32 @BPF_STMT(i32 %89, i32 4)
%91 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 10, i32 0
store i32 %90, i32* %91
%92 = load i32, i32* @BPF_ALU
%93 = load i32, i32* @BPF_ADD
%94 = or i32 %93, %92
%95 = load i32, i32* @BPF_X
%96 = or i32 %94, %95
%97 = tail call i32 @BPF_STMT(i32 %96, i32 0)
%98 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 11, i32 0
store i32 %97, i32* %98
%99 = load i32, i32* @BPF_ST
%100 = tail call i32 @BPF_STMT(i32 %99, i32 0)
%101 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 12, i32 0
store i32 %100, i32* %101
%102 = load i32, i32* @BPF_LDX
%103 = load i32, i32* @BPF_W
%104 = or i32 %103, %102
%105 = load i32, i32* @BPF_MEM
%106 = or i32 %104, %105
%107 = tail call i32 @BPF_STMT(i32 %106, i32 0)
%108 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 13, i32 0
store i32 %107, i32* %108
%109 = load i32, i32* @BPF_LD
%110 = load i32, i32* @BPF_H
%111 = or i32 %110, %109
%112 = load i32, i32* @BPF_IND
%113 = or i32 %111, %112
%114 = tail call i32 @BPF_STMT(i32 %113, i32 0)
%115 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 14, i32 0
store i32 %114, i32* %115
%116 = load i32, i32* @BPF_JMP
%117 = load i32, i32* @BPF_JEQ
%118 = or i32 %117, %116
%119 = load i32, i32* @BPF_K
%120 = or i32 %118, %119
%121 = tail call i32 @BPF_JUMP(i32 %120, i32 54321, i32 3, i32 0)
%122 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 15, i32 0
store i32 %121, i32* %122
%123 = load i32, i32* @BPF_LD
%124 = load i32, i32* @BPF_H
%125 = or i32 %124, %123
%126 = load i32, i32* @BPF_IND
%127 = or i32 %125, %126
%128 = tail call i32 @BPF_STMT(i32 %127, i32 2)
%129 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 16, i32 0
store i32 %128, i32* %129
%130 = load i32, i32* @BPF_JMP
%131 = load i32, i32* @BPF_JEQ
%132 = or i32 %131, %130
%133 = load i32, i32* @BPF_K
%134 = or i32 %132, %133
%135 = tail call i32 @BPF_JUMP(i32 %134, i32 54321, i32 1, i32 0)
%136 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 17, i32 0
store i32 %135, i32* %136
%137 = load i32, i32* @BPF_RET
%138 = load i32, i32* @BPF_K
%139 = or i32 %138, %137
%140 = tail call i32 @BPF_STMT(i32 %139, i32 16777215)
%141 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 18, i32 0
store i32 %140, i32* %141
%142 = load i32, i32* @BPF_RET
%143 = load i32, i32* @BPF_K
%144 = or i32 %143, %142
%145 = tail call i32 @BPF_STMT(i32 %144, i32 0)
%146 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 19, i32 0
store i32 %145, i32* %146
%147 = bitcast %struct.sock_fprog* %4 to i8*
%148 = call i32 @memset(%struct.sock_fprog* %4, i32 0, i32 16)
%149 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %4, i64 0, i32 0
store i32 20, i32* %149
%150 = getelementptr inbounds %struct.sock_fprog, %struct.sock_fprog* %4, i64 0, i32 1
store %struct.sock_filter* %12, %struct.sock_filter** %150
%151 = icmp eq i32 %1, 12
br i1 %151, label %152, label %154
152: ; preds = %2
store i32 %10, i32* %55
store i32 15, i32* %149
%153 = getelementptr inbounds [20 x %struct.sock_filter], [20 x %struct.sock_filter]* %3, i64 0, i64 5
store %struct.sock_filter* %153, %struct.sock_filter** %150
br label %154
154: ; preds = %152, %2
%155 = load i32, i32* @SOL_SOCKET
%156 = load i32, i32* @SO_ATTACH_FILTER
%157 = call i32 @setsockopt(i32 %0, i32 %155, i32 %156, %struct.sock_fprog* %4, i32 16)
ret i32 %157
}