#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 bpf_cgroup_dev_ctx {
  int access_type;
  int major;
  int minor;
};

/* Variables and functions */
short BPF_DEVCG_DEV_CHAR;
__attribute__((section("cgroup/dev"), used)) int
bpf_prog1(struct bpf_cgroup_dev_ctx *ctx) {
  short type = ctx->access_type & 0xFFFF;
  if (ctx->major != 1 || type != BPF_DEVCG_DEV_CHAR)
    return 0;
  switch (ctx->minor) {
  case 5:
  case 9:
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<bpf_prog1>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
and    $0xffff,%eax
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,0x4(%rax)
jne    113b <bpf_prog1+0x3b>
movswl -0x12(%rbp),%eax
mov    0x2ec8(%rip),%rcx
movswl (%rcx),%ecx
cmp    %ecx,%eax
je     1147 <bpf_prog1+0x47>
movl   $0x0,-0x4(%rbp)
jmp    1183 <bpf_prog1+0x83>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x18(%rbp)
sub    $0x5,%eax
je     1170 <bpf_prog1+0x70>
jmp    115f <bpf_prog1+0x5f>
mov    -0x18(%rbp),%eax
sub    $0x9,%eax
jne    117c <bpf_prog1+0x7c>
jmp    1170 <bpf_prog1+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1183 <bpf_prog1+0x83>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<bpf_prog1>:
xor    %eax,%eax
cmpl   $0x1,0x4(%rdi)
jne    112a <bpf_prog1+0x2a>
movswl (%rdi),%ecx
mov    0x2ee6(%rip),%rdx
movswl (%rdx),%edx
cmp    %edx,%ecx
jne    112a <bpf_prog1+0x2a>
mov    0x8(%rdi),%ecx
add    $0xfffffffb,%ecx
xor    %eax,%eax
test   $0xfffffffb,%ecx
sete   %al
ret

LLVM IR (-O0):
%struct.bpf_cgroup_dev_ctx = type { i32, i32, i32 }
@BPF_DEVCG_DEV_CHAR = global i16 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.bpf_cgroup_dev_ctx*)* @bpf_prog1 to i8*)], section "llvm.metadata"
define i32 @bpf_prog1(%struct.bpf_cgroup_dev_ctx* %0) section "cgroup/dev" {
%2 = alloca i32
%3 = alloca %struct.bpf_cgroup_dev_ctx*
%4 = alloca i16
store %struct.bpf_cgroup_dev_ctx* %0, %struct.bpf_cgroup_dev_ctx** %3
%5 = load %struct.bpf_cgroup_dev_ctx*, %struct.bpf_cgroup_dev_ctx** %3
%6 = getelementptr inbounds %struct.bpf_cgroup_dev_ctx, %struct.bpf_cgroup_dev_ctx* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = and i32 %7, 65535
%9 = trunc i32 %8 to i16
store i16 %9, i16* %4
%10 = load %struct.bpf_cgroup_dev_ctx*, %struct.bpf_cgroup_dev_ctx** %3
%11 = getelementptr inbounds %struct.bpf_cgroup_dev_ctx, %struct.bpf_cgroup_dev_ctx* %10, i32 0, i32 1
%12 = load i32, i32* %11
%13 = icmp ne i32 %12, 1
br i1 %13, label %20, label %14
14: ; preds = %1
%15 = load i16, i16* %4
%16 = sext i16 %15 to i32
%17 = load i16, i16* @BPF_DEVCG_DEV_CHAR
%18 = sext i16 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %21
20: ; preds = %14, %1
store i32 0, i32* %2
br label %27
21: ; preds = %14
%22 = load %struct.bpf_cgroup_dev_ctx*, %struct.bpf_cgroup_dev_ctx** %3
%23 = getelementptr inbounds %struct.bpf_cgroup_dev_ctx, %struct.bpf_cgroup_dev_ctx* %22, i32 0, i32 2
%24 = load i32, i32* %23
switch i32 %24, label %26 [
i32 5, label %25
i32 9, label %25
]
25: ; preds = %21, %21
store i32 1, i32* %2
br label %27
26: ; preds = %21
store i32 0, i32* %2
br label %27
27: ; preds = %26, %25, %20
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
%struct.bpf_cgroup_dev_ctx = type { i32, i32, i32 }
@BPF_DEVCG_DEV_CHAR = global i16 0
@llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32 (%struct.bpf_cgroup_dev_ctx*)* @bpf_prog1 to i8*)], section "llvm.metadata"
define i32 @bpf_prog1(%struct.bpf_cgroup_dev_ctx* nocapture %0) section "cgroup/dev" {
%2 = getelementptr inbounds %struct.bpf_cgroup_dev_ctx, %struct.bpf_cgroup_dev_ctx* %0, i64 0, i32 1
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %20
5: ; preds = %1
%6 = getelementptr inbounds %struct.bpf_cgroup_dev_ctx, %struct.bpf_cgroup_dev_ctx* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = shl i32 %7, 16
%9 = ashr exact i32 %8, 16
%10 = load i16, i16* @BPF_DEVCG_DEV_CHAR
%11 = sext i16 %10 to i32
%12 = icmp eq i32 %9, %11
br i1 %12, label %13, label %20
13: ; preds = %5
%14 = getelementptr inbounds %struct.bpf_cgroup_dev_ctx, %struct.bpf_cgroup_dev_ctx* %0, i64 0, i32 2
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 5
%17 = icmp eq i32 %15, 9
%18 = or i1 %16, %17
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %13, %1, %5
%21 = phi i32 [ 0, %5 ], [ 0, %1 ], [ %19, %13 ]
ret i32 %21
}