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

/* Variables and functions */
int BTN_MISC;
unsigned int BTN_TRIGGER_HAPPY;
int EV_KEY;
unsigned int KEY_OK;
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, ...);
void test_key(struct udev *udev, const unsigned long *bitmask_ev,
              const unsigned long *bitmask_key) {
  unsigned i;
  unsigned long found;
  unsigned long mask;
  if (!((bitmask_ev[((EV_KEY) / (sizeof(unsigned long) * 8))] >>
         ((EV_KEY) % (sizeof(unsigned long) * 8))) &
        1)) {
    udev_log_null(udev, "test_key: no EV_KEY capability\n");
    return;
  }
  found = 0;
  for (i = 0; i < BTN_MISC / (sizeof(unsigned long) * 8); ++i) {
    found |= bitmask_key[i];
    udev_log_null(udev,
                  "test_key: checking bit block %lu for any keys; found=%i\n",
                  i * (sizeof(unsigned long) * 8), found > 0);
  }
  if (!found) {
    for (i = KEY_OK; i < BTN_TRIGGER_HAPPY; ++i) {
      if (((bitmask_key[((i) / (sizeof(unsigned long) * 8))] >>
            ((i) % (sizeof(unsigned long) * 8))) &
           1)) {
        udev_log_null(udev, "test_key: Found key %x in high block\n", i);
        found = 1;
        break;
      }
    }
  }
  if (found > 0)
    puts("ID_INPUT_KEY=1");
  mask = 0xFFFFFFFE;
  if ((bitmask_key[0] & mask) == mask)
    puts("ID_INPUT_KEYBOARD=1");
}


x86 assembly (clang, -O0):
<test_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ea1(%rip),%rcx
movslq (%rcx),%rcx
shr    $0x6,%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2e8f(%rip),%rcx
movslq (%rcx),%rcx
and    $0x3f,%rcx
shr    %cl,%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    1180 <test_key+0x60>
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <udev_log_null@plt>
jmp    12bd <test_key+0x19d>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e2f(%rip),%rcx
movslq (%rcx),%rcx
shr    $0x6,%rcx
cmp    %rcx,%rax
jae    11f2 <test_key+0xd2>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
or     -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
shl    $0x6,%rdx
cmpq   $0x0,-0x28(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%ecx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1040 <udev_log_null@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118f <test_key+0x6f>
cmpq   $0x0,-0x28(%rbp)
jne    127c <test_key+0x15c>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%eax
jae    1277 <test_key+0x157>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shr    $0x6,%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x1c(%rbp),%ecx
and    $0x3f,%rcx
shr    %cl,%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1264 <test_key+0x144>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1040 <udev_log_null@plt>
movq   $0x1,-0x28(%rbp)
jmp    1277 <test_key+0x157>
jmp    1269 <test_key+0x149>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1209 <test_key+0xe9>
jmp    127c <test_key+0x15c>
cmpq   $0x0,-0x28(%rbp)
jbe    1293 <test_key+0x173>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%eax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
and    -0x30(%rbp),%rax
cmp    -0x30(%rbp),%rax
jne    12bd <test_key+0x19d>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eab(%rip),%rax
movslq (%rax),%rax
mov    %rax,%rcx
shr    $0x6,%rcx
mov    (%rsi,%rcx,8),%rcx
bt     %rax,%rcx
jae    11dd <test_key+0xbd>
mov    %rdx,%r13
mov    0x2e71(%rip),%r12
cmpl   $0x40,(%r12)
jb     11a3 <test_key+0x83>
lea    0xebb(%rip),%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rbp,%rdx
shl    $0x6,%rdx
xor    %ecx,%ecx
or     0x0(%r13,%rbp,8),%rbx
setne  %cl
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <udev_log_null@plt>
add    $0x1,%ebp
movslq (%r12),%rax
shr    $0x6,%rax
cmp    %rbp,%rax
ja     1170 <test_key+0x50>
test   %rbx,%rbx
jne    120d <test_key+0xed>
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
cmp    %eax,%edx
jae    1219 <test_key+0xf9>
nopl   0x0(%rax)
mov    %rdx,%rcx
shr    $0x6,%rcx
mov    0x0(%r13,%rcx,8),%rcx
bt     %rdx,%rcx
jb     11fc <test_key+0xdc>
add    $0x1,%rdx
cmp    %rdx,%rax
jne    11c0 <test_key+0xa0>
jmp    1219 <test_key+0xf9>
lea    0xe1c(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <udev_log_null@plt>
lea    0xe56(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <udev_log_null@plt>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%eax
not    %eax
test   $0xfffffffe,%eax
jne    1240 <test_key+0x120>
lea    0xe61(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.udev = type { i32 }
@EV_KEY = global i32 0
@.str = [32 x i8] c"test_key: no EV_KEY capability\0A\00"
@BTN_MISC = global i32 0
@.str.1 = [57 x i8] c"test_key: checking bit block %lu for any keys; found=%i\0A\00"
@KEY_OK = global i32 0
@BTN_TRIGGER_HAPPY = global i32 0
@.str.2 = [38 x i8] c"test_key: Found key %x in high block\0A\00"
@.str.3 = [15 x i8] c"ID_INPUT_KEY=1\00"
@.str.4 = [20 x i8] c"ID_INPUT_KEYBOARD=1\00"
define void @test_key(%struct.udev* %0, i64* %1, i64* %2) {
%4 = alloca %struct.udev*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store %struct.udev* %0, %struct.udev** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%10 = load i64*, i64** %5
%11 = load i32, i32* @EV_KEY
%12 = sext i32 %11 to i64
%13 = udiv i64 %12, 64
%14 = getelementptr inbounds i64, i64* %10, i64 %13
%15 = load i64, i64* %14
%16 = load i32, i32* @EV_KEY
%17 = sext i32 %16 to i64
%18 = urem i64 %17, 64
%19 = lshr i64 %15, %18
%20 = and i64 %19, 1
%21 = icmp ne i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %3
%23 = load %struct.udev*, %struct.udev** %4
%24 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %98
25: ; preds = %3
store i64 0, i64* %8
store i32 0, i32* %7
br label %26
26: ; preds = %49, %25
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = load i32, i32* @BTN_MISC
%30 = sext i32 %29 to i64
%31 = udiv i64 %30, 64
%32 = icmp ult i64 %28, %31
br i1 %32, label %33, label %52
33: ; preds = %26
%34 = load i64*, i64** %6
%35 = load i32, i32* %7
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i64, i64* %34, i64 %36
%38 = load i64, i64* %37
%39 = load i64, i64* %8
%40 = or i64 %39, %38
store i64 %40, i64* %8
%41 = load %struct.udev*, %struct.udev** %4
%42 = load i32, i32* %7
%43 = zext i32 %42 to i64
%44 = mul i64 %43, 64
%45 = load i64, i64* %8
%46 = icmp ugt i64 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %41, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i64 %44, i32 %47)
br label %49
49: ; preds = %33
%50 = load i32, i32* %7
%51 = add i32 %50, 1
store i32 %51, i32* %7
br label %26
52: ; preds = %26
%53 = load i64, i64* %8
%54 = icmp ne i64 %53, 0
br i1 %54, label %83, label %55
55: ; preds = %52
%56 = load i32, i32* @KEY_OK
store i32 %56, i32* %7
br label %57
57: ; preds = %79, %55
%58 = load i32, i32* %7
%59 = load i32, i32* @BTN_TRIGGER_HAPPY
%60 = icmp ult i32 %58, %59
br i1 %60, label %61, label %82
61: ; preds = %57
%62 = load i64*, i64** %6
%63 = load i32, i32* %7
%64 = zext i32 %63 to i64
%65 = udiv i64 %64, 64
%66 = getelementptr inbounds i64, i64* %62, i64 %65
%67 = load i64, i64* %66
%68 = load i32, i32* %7
%69 = zext i32 %68 to i64
%70 = urem i64 %69, 64
%71 = lshr i64 %67, %70
%72 = and i64 %71, 1
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %61
%75 = load %struct.udev*, %struct.udev** %4
%76 = load i32, i32* %7
%77 = call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %75, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %76)
store i64 1, i64* %8
br label %82
78: ; preds = %61
br label %79
79: ; preds = %78
%80 = load i32, i32* %7
%81 = add i32 %80, 1
store i32 %81, i32* %7
br label %57
82: ; preds = %74, %57
br label %83
83: ; preds = %82, %52
%84 = load i64, i64* %8
%85 = icmp ugt i64 %84, 0
br i1 %85, label %86, label %88
86: ; preds = %83
%87 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %88
88: ; preds = %86, %83
store i64 4294967294, i64* %9
%89 = load i64*, i64** %6
%90 = getelementptr inbounds i64, i64* %89, i64 0
%91 = load i64, i64* %90
%92 = load i64, i64* %9
%93 = and i64 %91, %92
%94 = load i64, i64* %9
%95 = icmp eq i64 %93, %94
br i1 %95, label %96, label %98
96: ; preds = %88
%97 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %98
98: ; preds = %22, %96, %88
ret void
}

LLVM IR (-O2):
%struct.udev = type { i32 }
@EV_KEY = global i32 0
@.str = [32 x i8] c"test_key: no EV_KEY capability\0A\00"
@BTN_MISC = global i32 0
@.str.1 = [57 x i8] c"test_key: checking bit block %lu for any keys; found=%i\0A\00"
@KEY_OK = global i32 0
@BTN_TRIGGER_HAPPY = global i32 0
@.str.2 = [38 x i8] c"test_key: Found key %x in high block\0A\00"
@.str.3 = [15 x i8] c"ID_INPUT_KEY=1\00"
@.str.4 = [20 x i8] c"ID_INPUT_KEYBOARD=1\00"
define void @test_key(%struct.udev* %0, i64* nocapture %1, i64* nocapture %2) {
%4 = load i32, i32* @EV_KEY
%5 = sext i32 %4 to i64
%6 = lshr i64 %5, 6
%7 = getelementptr inbounds i64, i64* %1, i64 %6
%8 = load i64, i64* %7
%9 = and i64 %5, 63
%10 = shl nuw i64 1, %9
%11 = and i64 %10, %8
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* @BTN_MISC
%15 = icmp ult i32 %14, 64
br i1 %15, label %36, label %18
16: ; preds = %3
%17 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %66
18: ; preds = %13, %18
%19 = phi i64 [ %29, %18 ], [ 0, %13 ]
%20 = phi i64 [ %23, %18 ], [ 0, %13 ]
%21 = getelementptr inbounds i64, i64* %2, i64 %19
%22 = load i64, i64* %21
%23 = or i64 %22, %20
%24 = shl nuw nsw i64 %19, 6
%25 = icmp ne i64 %23, 0
%26 = zext i1 %25 to i32
%27 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i64 %24, i32 %26)
%28 = add nuw nsw i64 %19, 1
%29 = and i64 %28, 4294967295
%30 = load i32, i32* @BTN_MISC
%31 = sext i32 %30 to i64
%32 = lshr i64 %31, 6
%33 = icmp ugt i64 %32, %29
br i1 %33, label %18, label %34
34: ; preds = %18
%35 = icmp eq i64 %23, 0
br i1 %35, label %36, label %58
36: ; preds = %13, %34
%37 = load i32, i32* @KEY_OK
%38 = load i32, i32* @BTN_TRIGGER_HAPPY
%39 = icmp ult i32 %37, %38
br i1 %39, label %40, label %60
40: ; preds = %36
%41 = zext i32 %37 to i64
%42 = zext i32 %38 to i64
br label %43
43: ; preds = %40, %55
%44 = phi i64 [ %41, %40 ], [ %56, %55 ]
%45 = lshr i64 %44, 6
%46 = getelementptr inbounds i64, i64* %2, i64 %45
%47 = load i64, i64* %46
%48 = and i64 %44, 63
%49 = shl nuw i64 1, %48
%50 = and i64 %47, %49
%51 = icmp eq i64 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %43
%53 = trunc i64 %44 to i32
%54 = tail call i32 (%struct.udev*, i8*, ...) @udev_log_null(%struct.udev* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %53)
br label %58
55: ; preds = %43
%56 = add nuw nsw i64 %44, 1
%57 = icmp eq i64 %56, %42
br i1 %57, label %60, label %43
58: ; preds = %34, %52
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %55, %36, %58
%61 = load i64, i64* %2
%62 = and i64 %61, 4294967294
%63 = icmp eq i64 %62, 4294967294
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %60, %64, %16
ret void
}