#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_7__ TYPE_2__;
typedef struct TYPE_6__ TYPE_1__;

/* Type definitions */
typedef TYPE_2__ *XkbDescPtr;
struct TYPE_7__ {
  TYPE_1__ *names;
  int /*<<< orphan*/ dpy;
};
struct TYPE_6__ {
  int /*<<< orphan*/ *vmods;
};
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ True;
char *XGetAtomName(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ XkbAllComponentsMask;
int /*<<< orphan*/ XkbFreeKeyboard(TYPE_2__ *, int /*<<< orphan*/,
                                   int /*<<< orphan*/);
TYPE_2__ *XkbGetKeyboard(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ XkbLockModifiers(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                    unsigned int, unsigned int);
int XkbNumVirtualMods;
int /*<<< orphan*/ XkbUseCoreKbd;
int /*<<< orphan*/ XkbVirtualModsToReal(TYPE_2__ *, int, unsigned int *);
scalar_t__ strcmp(char *, char *);
void numlock(Display *c, int onoff) {
  XkbDescPtr xkb;
  unsigned int mask;
  int i;
  xkb = XkbGetKeyboard(c, XkbAllComponentsMask, XkbUseCoreKbd);
  if (!xkb)
    return;
  if (!xkb->names) {
    XkbFreeKeyboard(xkb, 0, True);
    return;
  }
  for (i = 0; i < XkbNumVirtualMods; i++) {
    char *s = XGetAtomName(xkb->dpy, xkb->names->vmods[i]);
    if (!s)
      continue;
    if (strcmp(s, "NumLock"))
      continue;
    XkbVirtualModsToReal(xkb, 1 << i, &mask);
    break;
  }
  XkbFreeKeyboard(xkb, 0, True);
  XkbLockModifiers(c, XkbUseCoreKbd, mask, (onoff ? mask : 0));
}


x86 assembly (clang, -O0):
<numlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
call   1080 <XkbGetKeyboard@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <numlock+0x3e>
jmp    12b7 <numlock+0x157>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c5 <numlock+0x65>
mov    -0x18(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <XkbFreeKeyboard@plt>
jmp    12b7 <numlock+0x157>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2dfa(%rip),%rcx
cmp    (%rcx),%eax
jge    1258 <numlock+0xf8>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <XGetAtomName@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120f <numlock+0xaf>
jmp    124a <numlock+0xea>
mov    -0x28(%rbp),%rdi
lea    0xde6(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     122e <numlock+0xce>
jmp    124a <numlock+0xea>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
lea    -0x1c(%rbp),%rdx
call   1070 <XkbVirtualModsToReal@plt>
jmp    1258 <numlock+0xf8>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11cc <numlock+0x6c>
mov    -0x18(%rbp),%rdi
mov    0x2d7d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <XkbFreeKeyboard@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     129b <numlock+0x13b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    12a5 <numlock+0x145>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    12a5 <numlock+0x145>
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%esi
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%ecx
call   1040 <XkbLockModifiers@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numlock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
call   1080 <XkbGetKeyboard@plt>
test   %rax,%rax
je     125e <numlock+0xfe>
mov    %rax,%rbx
mov    (%rax),%rax
test   %rax,%rax
je     11f5 <numlock+0x95>
mov    0x2e2d(%rip),%r13
cmpl   $0x0,0x0(%r13)
jle    122c <numlock+0xcc>
xor    %ebp,%ebp
lea    0xe49(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx),%edi
mov    (%rax),%rax
mov    (%rax,%rbp,4),%esi
call   1050 <XGetAtomName@plt>
test   %rax,%rax
je     11e3 <numlock+0x83>
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1216 <numlock+0xb6>
add    $0x1,%rbp
movslq 0x0(%r13),%rax
cmp    %rax,%rbp
jge    122c <numlock+0xcc>
mov    (%rbx),%rax
jmp    11c0 <numlock+0x60>
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <XkbFreeKeyboard@plt>
mov    $0x1,%esi
mov    %ebp,%ecx
shl    %cl,%esi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <XkbVirtualModsToReal@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <XkbFreeKeyboard@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
mov    0x4(%rsp),%edx
test   %r15d,%r15d
cmovne %edx,%r15d
mov    %r14,%rdi
mov    %r15d,%ecx
call   1040 <XkbLockModifiers@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { %struct.TYPE_6__*, i32 }
%struct.TYPE_6__ = type { i32* }
@XkbAllComponentsMask = global i32 0
@XkbUseCoreKbd = global i32 0
@True = global i32 0
@XkbNumVirtualMods = global i32 0
@.str = [8 x i8] c"NumLock\00"
define void @numlock(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca %struct.TYPE_7__*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32*, i32** %3
%10 = load i32, i32* @XkbAllComponentsMask
%11 = load i32, i32* @XkbUseCoreKbd
%12 = call %struct.TYPE_7__* @XkbGetKeyboard(i32* %9, i32 %10, i32 %11)
store %struct.TYPE_7__* %12, %struct.TYPE_7__** %5
%13 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%14 = icmp ne %struct.TYPE_7__* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
br label %75
16: ; preds = %2
%17 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%18 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %17, i32 0, i32 0
%19 = load %struct.TYPE_6__*, %struct.TYPE_6__** %18
%20 = icmp ne %struct.TYPE_6__* %19, null
br i1 %20, label %25, label %21
21: ; preds = %16
%22 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%23 = load i32, i32* @True
%24 = call i32 @XkbFreeKeyboard(%struct.TYPE_7__* %22, i32 0, i32 %23)
br label %75
25: ; preds = %16
store i32 0, i32* %7
br label %26
26: ; preds = %57, %25
%27 = load i32, i32* %7
%28 = load i32, i32* @XkbNumVirtualMods
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %60
30: ; preds = %26
%31 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%32 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%35 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %34, i32 0, i32 0
%36 = load %struct.TYPE_6__*, %struct.TYPE_6__** %35
%37 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %36, i32 0, i32 0
%38 = load i32*, i32** %37
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = call i8* @XGetAtomName(i32 %33, i32 %42)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %47, label %46
46: ; preds = %30
br label %57
47: ; preds = %30
%48 = load i8*, i8** %8
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
br label %57
52: ; preds = %47
%53 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%54 = load i32, i32* %7
%55 = shl i32 1, %54
%56 = call i32 @XkbVirtualModsToReal(%struct.TYPE_7__* %53, i32 %55, i32* %6)
br label %60
57: ; preds = %51, %46
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %26
60: ; preds = %52, %26
%61 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%62 = load i32, i32* @True
%63 = call i32 @XkbFreeKeyboard(%struct.TYPE_7__* %61, i32 0, i32 %62)
%64 = load i32*, i32** %3
%65 = load i32, i32* @XkbUseCoreKbd
%66 = load i32, i32* %6
%67 = load i32, i32* %4
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %60
%70 = load i32, i32* %6
br label %72
71: ; preds = %60
br label %72
72: ; preds = %71, %69
%73 = phi i32 [ %70, %69 ], [ 0, %71 ]
%74 = call i32 @XkbLockModifiers(i32* %64, i32 %65, i32 %66, i32 %73)
br label %75
75: ; preds = %72, %21, %15
ret void
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { %struct.TYPE_6__*, i32 }
%struct.TYPE_6__ = type { i32* }
@XkbAllComponentsMask = global i32 0
@XkbUseCoreKbd = global i32 0
@True = global i32 0
@XkbNumVirtualMods = global i32 0
@.str = [8 x i8] c"NumLock\00"
define void @numlock(i32* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @XkbAllComponentsMask
%6 = load i32, i32* @XkbUseCoreKbd
%7 = tail call %struct.TYPE_7__* @XkbGetKeyboard(i32* %0, i32 %5, i32 %6)
%8 = icmp eq %struct.TYPE_7__* %7, null
br i1 %8, label %53, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i64 0, i32 0
%11 = load %struct.TYPE_6__*, %struct.TYPE_6__** %10
%12 = icmp eq %struct.TYPE_6__* %11, null
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = load i32, i32* @XkbNumVirtualMods
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %45
16: ; preds = %13
%17 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %7, i64 0, i32 1
br label %21
18: ; preds = %9
%19 = load i32, i32* @True
%20 = tail call i32 @XkbFreeKeyboard(%struct.TYPE_7__* %7, i32 0, i32 %19)
br label %53
21: ; preds = %43, %16
%22 = phi %struct.TYPE_6__* [ %11, %16 ], [ %44, %43 ]
%23 = phi i64 [ 0, %16 ], [ %39, %43 ]
%24 = load i32, i32* %17
%25 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %22, i64 0, i32 0
%26 = load i32*, i32** %25
%27 = getelementptr inbounds i32, i32* %26, i64 %23
%28 = load i32, i32* %27
%29 = tail call i8* @XGetAtomName(i32 %24, i32 %28)
%30 = icmp eq i8* %29, null
br i1 %30, label %38, label %31
31: ; preds = %21
%32 = tail call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = trunc i64 %23 to i32
%36 = shl nuw i32 1, %35
%37 = call i32 @XkbVirtualModsToReal(%struct.TYPE_7__* %7, i32 %36, i32* %3)
br label %45
38: ; preds = %21, %31
%39 = add nuw nsw i64 %23, 1
%40 = load i32, i32* @XkbNumVirtualMods
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = load %struct.TYPE_6__*, %struct.TYPE_6__** %10
br label %21
45: ; preds = %38, %13, %34
%46 = load i32, i32* @True
%47 = call i32 @XkbFreeKeyboard(%struct.TYPE_7__* %7, i32 0, i32 %46)
%48 = load i32, i32* @XkbUseCoreKbd
%49 = load i32, i32* %3
%50 = icmp eq i32 %1, 0
%51 = select i1 %50, i32 0, i32 %49
%52 = call i32 @XkbLockModifiers(i32* %0, i32 %48, i32 %49, i32 %51)
br label %53
53: ; preds = %2, %45, %18
ret void
}