#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 dummy;
};
struct sock_filter {
  int dummy;
};

/* Variables and functions */
scalar_t__ BPF_ABS;
scalar_t__ BPF_B;
scalar_t__ BPF_LD;
scalar_t__ BPF_MISC;
struct sock_filter BPF_STMT(scalar_t__, scalar_t__);
scalar_t__ BPF_TAX;
scalar_t__ SKF_AD_ALU_XOR_X;
scalar_t__ SKF_AD_OFF;
scalar_t__ SKF_AD_VLAN_TAG;
int __add_inst(struct sock_fprog *, struct sock_filter *);
int bpf_vlan_hash(struct sock_fprog *fprog) {
  int err;
  {
    struct sock_filter inst =
        BPF_STMT(BPF_LD + BPF_B + BPF_ABS, SKF_AD_OFF + SKF_AD_VLAN_TAG);
    err = __add_inst(fprog, &inst);
    if (err)
      goto err_add_inst;
  };
  {
    struct sock_filter inst =
        BPF_STMT(BPF_LD + BPF_B + BPF_ABS, SKF_AD_OFF + SKF_AD_ALU_XOR_X);
    err = __add_inst(fprog, &inst);
    if (err)
      goto err_add_inst;
  };
  {
    struct sock_filter inst = BPF_STMT(BPF_MISC + BPF_TAX, 0);
    err = __add_inst(fprog, &inst);
    if (err)
      goto err_add_inst;
  };
  ;
err_add_inst:
  return err;
}


x86 assembly (clang, -O0):
<bpf_vlan_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%rdi
mov    0x2e7b(%rip),%rax
add    (%rax),%rdi
mov    0x2ea1(%rip),%rax
add    (%rax),%rdi
mov    0x2e7f(%rip),%rax
mov    (%rax),%rsi
mov    0x2e7d(%rip),%rax
add    (%rax),%rsi
call   1030 <BPF_STMT@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <__add_inst@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1185 <bpf_vlan_hash+0x65>
jmp    1222 <bpf_vlan_hash+0x102>
mov    0x2e34(%rip),%rax
mov    (%rax),%rdi
mov    0x2e22(%rip),%rax
add    (%rax),%rdi
mov    0x2e48(%rip),%rax
add    (%rax),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%rsi
mov    0x2dec(%rip),%rax
add    (%rax),%rsi
call   1030 <BPF_STMT@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <__add_inst@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11de <bpf_vlan_hash+0xbe>
jmp    1222 <bpf_vlan_hash+0x102>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rdi
mov    0x2db9(%rip),%rax
add    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <BPF_STMT@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <__add_inst@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     121d <bpf_vlan_hash+0xfd>
jmp    1222 <bpf_vlan_hash+0x102>
jmp    1222 <bpf_vlan_hash+0x102>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_vlan_hash>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    0x2e89(%rip),%r14
mov    0x2e7a(%rip),%r12
mov    (%r12),%rdi
add    (%r14),%rdi
mov    0x2e9c(%rip),%r13
add    0x0(%r13),%rdi
mov    0x2e79(%rip),%r15
mov    0x2e7a(%rip),%rax
mov    (%rax),%rsi
add    (%r15),%rsi
call   1030 <BPF_STMT@plt>
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <__add_inst@plt>
test   %eax,%eax
jne    11dc <bpf_vlan_hash+0xbc>
mov    (%r12),%rdi
add    (%r14),%rdi
add    0x0(%r13),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%rsi
add    (%r15),%rsi
call   1030 <BPF_STMT@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <__add_inst@plt>
test   %eax,%eax
jne    11dc <bpf_vlan_hash+0xbc>
mov    0x2e29(%rip),%rax
mov    0x2dea(%rip),%rcx
mov    (%rcx),%rdi
add    (%rax),%rdi
xor    %esi,%esi
call   1030 <BPF_STMT@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <__add_inst@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sock_fprog = type { i32 }
%struct.sock_filter = type { i32 }
@BPF_LD = global i64 0
@BPF_B = global i64 0
@BPF_ABS = global i64 0
@SKF_AD_OFF = global i64 0
@SKF_AD_VLAN_TAG = global i64 0
@SKF_AD_ALU_XOR_X = global i64 0
@BPF_MISC = global i64 0
@BPF_TAX = global i64 0
define i32 @bpf_vlan_hash(%struct.sock_fprog* %0) {
%2 = alloca %struct.sock_fprog*
%3 = alloca i32
%4 = alloca %struct.sock_filter
%5 = alloca %struct.sock_filter
%6 = alloca %struct.sock_filter
store %struct.sock_fprog* %0, %struct.sock_fprog** %2
%7 = load i64, i64* @BPF_LD
%8 = load i64, i64* @BPF_B
%9 = add nsw i64 %7, %8
%10 = load i64, i64* @BPF_ABS
%11 = add nsw i64 %9, %10
%12 = load i64, i64* @SKF_AD_OFF
%13 = load i64, i64* @SKF_AD_VLAN_TAG
%14 = add nsw i64 %12, %13
%15 = call i32 @BPF_STMT(i64 %11, i64 %14)
%16 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %4, i32 0, i32 0
store i32 %15, i32* %16
%17 = load %struct.sock_fprog*, %struct.sock_fprog** %2
%18 = call i32 @__add_inst(%struct.sock_fprog* %17, %struct.sock_filter* %4)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %1
br label %50
22: ; preds = %1
%23 = load i64, i64* @BPF_LD
%24 = load i64, i64* @BPF_B
%25 = add nsw i64 %23, %24
%26 = load i64, i64* @BPF_ABS
%27 = add nsw i64 %25, %26
%28 = load i64, i64* @SKF_AD_OFF
%29 = load i64, i64* @SKF_AD_ALU_XOR_X
%30 = add nsw i64 %28, %29
%31 = call i32 @BPF_STMT(i64 %27, i64 %30)
%32 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %5, i32 0, i32 0
store i32 %31, i32* %32
%33 = load %struct.sock_fprog*, %struct.sock_fprog** %2
%34 = call i32 @__add_inst(%struct.sock_fprog* %33, %struct.sock_filter* %5)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %22
br label %50
38: ; preds = %22
%39 = load i64, i64* @BPF_MISC
%40 = load i64, i64* @BPF_TAX
%41 = add nsw i64 %39, %40
%42 = call i32 @BPF_STMT(i64 %41, i64 0)
%43 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %6, i32 0, i32 0
store i32 %42, i32* %43
%44 = load %struct.sock_fprog*, %struct.sock_fprog** %2
%45 = call i32 @__add_inst(%struct.sock_fprog* %44, %struct.sock_filter* %6)
store i32 %45, i32* %3
%46 = load i32, i32* %3
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %38
br label %50
49: ; preds = %38
br label %50
50: ; preds = %49, %48, %37, %21
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
%struct.sock_fprog = type { i32 }
%struct.sock_filter = type { i32 }
@BPF_LD = global i64 0
@BPF_B = global i64 0
@BPF_ABS = global i64 0
@SKF_AD_OFF = global i64 0
@SKF_AD_VLAN_TAG = global i64 0
@SKF_AD_ALU_XOR_X = global i64 0
@BPF_MISC = global i64 0
@BPF_TAX = global i64 0
define i32 @bpf_vlan_hash(%struct.sock_fprog* %0) {
%2 = alloca %struct.sock_filter
%3 = alloca %struct.sock_filter
%4 = alloca %struct.sock_filter
%5 = bitcast %struct.sock_filter* %2 to i8*
%6 = load i64, i64* @BPF_LD
%7 = load i64, i64* @BPF_B
%8 = add nsw i64 %7, %6
%9 = load i64, i64* @BPF_ABS
%10 = add nsw i64 %8, %9
%11 = load i64, i64* @SKF_AD_OFF
%12 = load i64, i64* @SKF_AD_VLAN_TAG
%13 = add nsw i64 %12, %11
%14 = tail call i32 @BPF_STMT(i64 %10, i64 %13)
%15 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %2, i64 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @__add_inst(%struct.sock_fprog* %0, %struct.sock_filter* %2)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %1
%19 = bitcast %struct.sock_filter* %3 to i8*
%20 = load i64, i64* @BPF_LD
%21 = load i64, i64* @BPF_B
%22 = add nsw i64 %21, %20
%23 = load i64, i64* @BPF_ABS
%24 = add nsw i64 %22, %23
%25 = load i64, i64* @SKF_AD_OFF
%26 = load i64, i64* @SKF_AD_ALU_XOR_X
%27 = add nsw i64 %26, %25
%28 = call i32 @BPF_STMT(i64 %24, i64 %27)
%29 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %3, i64 0, i32 0
store i32 %28, i32* %29
%30 = call i32 @__add_inst(%struct.sock_fprog* %0, %struct.sock_filter* %3)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %18
%33 = bitcast %struct.sock_filter* %4 to i8*
%34 = load i64, i64* @BPF_MISC
%35 = load i64, i64* @BPF_TAX
%36 = add nsw i64 %35, %34
%37 = call i32 @BPF_STMT(i64 %36, i64 0)
%38 = getelementptr inbounds %struct.sock_filter, %struct.sock_filter* %4, i64 0, i32 0
store i32 %37, i32* %38
%39 = call i32 @__add_inst(%struct.sock_fprog* %0, %struct.sock_filter* %4)
br label %40
40: ; preds = %32, %18, %1
%41 = phi i32 [ %16, %1 ], [ %30, %18 ], [ %39, %32 ]
ret i32 %41
}