#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void bpf_decode_action(uint32_t k) {
  uint32_t act = k & 0xffff0000U;
  uint32_t data = k & 0x0000ffffU;
  switch (act) {
  case 0x80000000U:
    printf("KILL_PROCESS");
    break;
  case 0x00000000U:
    printf("KILL");
    break;
  case 0x00030000U:
    printf("TRAP");
    break;
  case 0x00050000U:
    printf("ERRNO(%u)", data);
    break;
  case 0x7ff00000U:
    printf("TRACE(%u)", data);
    break;
  case 0x7ffc0000U:
    printf("LOG");
    break;
  case 0x7fff0000U:
    printf("ALLOW");
    break;
  default:
    printf("0x%.8x", k);
  }
}


x86 assembly (clang, -O0):
<bpf_decode_action>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movzwl -0x2(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x8(%rbp)
movzwl -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x80000000,%eax
je     11b1 <bpf_decode_action+0xa1>
jmp    1142 <bpf_decode_action+0x32>
mov    -0x10(%rbp),%eax
test   %eax,%eax
je     11c4 <bpf_decode_action+0xb4>
jmp    1152 <bpf_decode_action+0x42>
mov    -0x10(%rbp),%eax
sub    $0x30000,%eax
je     11d7 <bpf_decode_action+0xc7>
jmp    1165 <bpf_decode_action+0x55>
mov    -0x10(%rbp),%eax
sub    $0x50000,%eax
je     11ea <bpf_decode_action+0xda>
jmp    1178 <bpf_decode_action+0x68>
mov    -0x10(%rbp),%eax
sub    $0x7ff00000,%eax
je     1200 <bpf_decode_action+0xf0>
jmp    118b <bpf_decode_action+0x7b>
mov    -0x10(%rbp),%eax
sub    $0x7ffc0000,%eax
je     1216 <bpf_decode_action+0x106>
jmp    119e <bpf_decode_action+0x8e>
mov    -0x10(%rbp),%eax
sub    $0x7fff0000,%eax
je     1229 <bpf_decode_action+0x119>
jmp    123c <bpf_decode_action+0x12c>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
mov    -0xc(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
mov    -0xc(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <bpf_decode_action+0x13d>
mov    -0x4(%rbp),%esi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_decode_action>:
mov    %edi,%eax
mov    %edi,%ecx
and    $0xffff0000,%ecx
cmp    $0x4ffff,%ecx
jle    114b <bpf_decode_action+0x3b>
cmp    $0x7ffbffff,%ecx
jg     116d <bpf_decode_action+0x5d>
movzwl %ax,%esi
cmp    $0x50000,%ecx
je     118b <bpf_decode_action+0x7b>
cmp    $0x7ff00000,%ecx
jne    11b5 <bpf_decode_action+0xa5>
lea    0xedd(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0x80000000,%ecx
je     1199 <bpf_decode_action+0x89>
test   %ecx,%ecx
je     11c5 <bpf_decode_action+0xb5>
cmp    $0x30000,%ecx
jne    11b5 <bpf_decode_action+0xa5>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0x7ffc0000,%ecx
je     11a7 <bpf_decode_action+0x97>
cmp    $0x7fff0000,%ecx
jne    11b5 <bpf_decode_action+0xa5>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe60(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe79(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
jmp    1030 <printf@plt>
lea    0xe41(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"KILL_PROCESS\00"
@.str.1 = [5 x i8] c"KILL\00"
@.str.2 = [5 x i8] c"TRAP\00"
@.str.3 = [10 x i8] c"ERRNO(%u)\00"
@.str.4 = [10 x i8] c"TRACE(%u)\00"
@.str.5 = [4 x i8] c"LOG\00"
@.str.6 = [6 x i8] c"ALLOW\00"
@.str.7 = [7 x i8] c"0x%.8x\00"
define void @bpf_decode_action(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = and i32 %5, -65536
store i32 %6, i32* %3
%7 = load i32, i32* %2
%8 = and i32 %7, 65535
store i32 %8, i32* %4
%9 = load i32, i32* %3
switch i32 %9, label %26 [
i32 -2147483648, label %10
i32 0, label %12
i32 196608, label %14
i32 327680, label %16
i32 2146435072, label %19
i32 2147221504, label %22
i32 2147418112, label %24
]
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %29
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %29
14: ; preds = %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
16: ; preds = %1
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %29
19: ; preds = %1
%20 = load i32, i32* %4
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %20)
br label %29
22: ; preds = %1
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %29
24: ; preds = %1
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %29
26: ; preds = %1
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %26, %24, %22, %19, %16, %14, %12, %10
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"KILL_PROCESS\00"
@.str.1 = [5 x i8] c"KILL\00"
@.str.2 = [5 x i8] c"TRAP\00"
@.str.3 = [10 x i8] c"ERRNO(%u)\00"
@.str.4 = [10 x i8] c"TRACE(%u)\00"
@.str.5 = [4 x i8] c"LOG\00"
@.str.6 = [6 x i8] c"ALLOW\00"
@.str.7 = [7 x i8] c"0x%.8x\00"
define void @bpf_decode_action(i32 %0) {
%2 = and i32 %0, -65536
%3 = and i32 %0, 65535
switch i32 %2, label %18 [
i32 -2147483648, label %4
i32 0, label %6
i32 196608, label %8
i32 327680, label %10
i32 2146435072, label %12
i32 2147221504, label %14
i32 2147418112, label %16
]
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %20
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %20
10: ; preds = %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %3)
br label %20
12: ; preds = %1
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %3)
br label %20
14: ; preds = %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
br label %20
16: ; preds = %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %20
18: ; preds = %1
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %0)
br label %20
20: ; preds = %18, %16, %14, %12, %10, %8, %6, %4
ret void
}