#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int max_keypermod;
  scalar_t__ *modifiermap;
};
typedef TYPE_1__ XModifierKeymap;
typedef scalar_t__ KeyCode;

/* Variables and functions */
#define ControlMapIndex 135
unsigned int ControlMask;
#define LockMapIndex 134
unsigned int LockMask;
#define Mod1MapIndex 133
unsigned int Mod1Mask;
#define Mod2MapIndex 132
unsigned int Mod2Mask;
#define Mod3MapIndex 131
unsigned int Mod3Mask;
#define Mod4MapIndex 130
unsigned int Mod4Mask;
#define Mod5MapIndex 129
unsigned int Mod5Mask;
#define ShiftMapIndex 128
unsigned int ShiftMask;
unsigned int keycode_to_modifier(XModifierKeymap *xmodmap, KeyCode keycode) {
  int i = 0;
  int j = 0;
  int max = xmodmap->max_keypermod;
  for (i = 0; i < 8; i++) {
    for (j = 0; j < max && xmodmap->modifiermap[(i * max) + j]; j++) {
      if (keycode == xmodmap->modifiermap[(i * max) + j]) {
        switch (i) {
        case ShiftMapIndex:
          return ShiftMask;
          break;
        case LockMapIndex:
          return LockMask;
          break;
        case ControlMapIndex:
          return ControlMask;
          break;
        case Mod1MapIndex:
          return Mod1Mask;
          break;
        case Mod2MapIndex:
          return Mod2Mask;
          break;
        case Mod3MapIndex:
          return Mod3Mask;
          break;
        case Mod4MapIndex:
          return Mod4Mask;
          break;
        case Mod5MapIndex:
          return Mod5Mask;
          break;
        }
      }
    }
  }
  return (KeyCode)0;
}


x86 assembly (clang, -O0):
<keycode_to_modifier>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    127b <keycode_to_modifier+0x17b>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x24(%rbp),%ecx
mov    %al,-0x25(%rbp)
jge    116c <keycode_to_modifier+0x6c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    117c <keycode_to_modifier+0x7c>
jmp    1268 <keycode_to_modifier+0x168>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
mov    -0x1c(%rbp),%edx
imul   -0x24(%rbp),%edx
add    -0x20(%rbp),%edx
movslq %edx,%rdx
cmp    (%rcx,%rdx,8),%rax
jne    1255 <keycode_to_modifier+0x155>
mov    -0x1c(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x7,%eax
ja     1250 <keycode_to_modifier+0x150>
mov    -0x30(%rbp),%rax
lea    0xe41(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1282 <keycode_to_modifier+0x182>
jmp    1255 <keycode_to_modifier+0x155>
jmp    125a <keycode_to_modifier+0x15a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    113b <keycode_to_modifier+0x3b>
jmp    126d <keycode_to_modifier+0x16d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <keycode_to_modifier+0x2a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<keycode_to_modifier>:
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64* }
@ShiftMask = global i32 0
@LockMask = global i32 0
@ControlMask = global i32 0
@Mod1Mask = global i32 0
@Mod2Mask = global i32 0
@Mod3Mask = global i32 0
@Mod4Mask = global i32 0
@Mod5Mask = global i32 0
define i32 @keycode_to_modifier(%struct.TYPE_3__* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.TYPE_3__*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %4
store i64 %1, i64* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* %8
store i32 0, i32* %6
br label %12
12: ; preds = %73, %2
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 8
br i1 %14, label %15, label %76
15: ; preds = %12
store i32 0, i32* %7
br label %16
16: ; preds = %69, %15
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 1
%23 = load i64*, i64** %22
%24 = load i32, i32* %6
%25 = load i32, i32* %8
%26 = mul nsw i32 %24, %25
%27 = load i32, i32* %7
%28 = add nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i64, i64* %23, i64 %29
%31 = load i64, i64* %30
%32 = icmp ne i64 %31, 0
br label %33
33: ; preds = %20, %16
%34 = phi i1 [ false, %16 ], [ %32, %20 ]
br i1 %34, label %35, label %72
35: ; preds = %33
%36 = load i64, i64* %5
%37 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 1
%39 = load i64*, i64** %38
%40 = load i32, i32* %6
%41 = load i32, i32* %8
%42 = mul nsw i32 %40, %41
%43 = load i32, i32* %7
%44 = add nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i64, i64* %39, i64 %45
%47 = load i64, i64* %46
%48 = icmp eq i64 %36, %47
br i1 %48, label %49, label %68
49: ; preds = %35
%50 = load i32, i32* %6
switch i32 %50, label %67 [
i32 128, label %51
i32 134, label %53
i32 135, label %55
i32 133, label %57
i32 132, label %59
i32 131, label %61
i32 130, label %63
i32 129, label %65
]
51: ; preds = %49
%52 = load i32, i32* @ShiftMask
store i32 %52, i32* %3
br label %77
53: ; preds = %49
%54 = load i32, i32* @LockMask
store i32 %54, i32* %3
br label %77
55: ; preds = %49
%56 = load i32, i32* @ControlMask
store i32 %56, i32* %3
br label %77
57: ; preds = %49
%58 = load i32, i32* @Mod1Mask
store i32 %58, i32* %3
br label %77
59: ; preds = %49
%60 = load i32, i32* @Mod2Mask
store i32 %60, i32* %3
br label %77
61: ; preds = %49
%62 = load i32, i32* @Mod3Mask
store i32 %62, i32* %3
br label %77
63: ; preds = %49
%64 = load i32, i32* @Mod4Mask
store i32 %64, i32* %3
br label %77
65: ; preds = %49
%66 = load i32, i32* @Mod5Mask
store i32 %66, i32* %3
br label %77
67: ; preds = %49
br label %68
68: ; preds = %67, %35
br label %69
69: ; preds = %68
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
br label %16
72: ; preds = %33
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %12
76: ; preds = %12
store i32 0, i32* %3
br label %77
77: ; preds = %76, %65, %63, %61, %59, %57, %55, %53, %51
%78 = load i32, i32* %3
ret i32 %78
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i64* }
@ShiftMask = global i32 0
@LockMask = global i32 0
@ControlMask = global i32 0
@Mod1Mask = global i32 0
@Mod2Mask = global i32 0
@Mod3Mask = global i32 0
@Mod4Mask = global i32 0
@Mod5Mask = global i32 0
define i32 @keycode_to_modifier(%struct.TYPE_3__* nocapture %0, i64 %1) {
ret i32 0
}