#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 /*<<< orphan*/ Window;
typedef scalar_t__ KeySym;
typedef int /*<<< orphan*/ KeyCode;
typedef int /*<<< orphan*/ Display;
typedef size_t Cardinal;

/* Variables and functions */
int /*<<< orphan*/ False;
int /*<<< orphan*/ GrabModeAsync;
scalar_t__ NoSymbol;
int /*<<< orphan*/ XGrabKey(int /*<<< orphan*/ *, int /*<<< orphan*/,
                            unsigned int, int /*<<< orphan*/,
                            int /*<<< orphan*/, int /*<<< orphan*/,
                            int /*<<< orphan*/);
scalar_t__ XStringToKeysym(char const *);
int /*<<< orphan*/ XtKeysymToKeycodeList(int /*<<< orphan*/ *, scalar_t__,
                                         int /*<<< orphan*/ **, size_t *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
void grabxkey(Display *d, Window w, unsigned int modifiers,
              const char *string) {
  KeySym keysym;
  KeyCode *keycodes;
  Cardinal nkeycodes;
  Cardinal i;
  keysym = XStringToKeysym(string);
  if (keysym == NoSymbol) {
    fprintf(stderr, "NoSymbol for %s, exiting\n", string);
    exit(1);
  }
  XtKeysymToKeycodeList(d, keysym, &keycodes, &nkeycodes);
  for (i = 0; i < nkeycodes; i++) {
    XGrabKey(d, keycodes[i], modifiers, w, False, GrabModeAsync, GrabModeAsync);
  }
}


x86 assembly (clang, -O0):
<grabxkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <XStringToKeysym@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <grabxkey+0x5a>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe65(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <XtKeysymToKeycodeList@plt>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1220 <grabxkey+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    0x2df7(%rip),%rax
mov    (%rax),%r8d
mov    0x2dd5(%rip),%rax
mov    (%rax),%r9d
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
call   1050 <XGrabKey@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11c7 <grabxkey+0x77>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grabxkey>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1070 <XStringToKeysym@plt>
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
je     11eb <grabxkey+0x9b>
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <XtKeysymToKeycodeList@plt>
cmpq   $0x0,0x8(%rsp)
je     11dc <grabxkey+0x8c>
xor    %ebp,%ebp
mov    0x2e44(%rip),%r15
mov    0x2e25(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax,%rbp,4),%esi
mov    (%r15),%r8d
mov    0x0(%r13),%r9d
mov    %r9d,(%rsp)
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %r12d,%ecx
call   1050 <XGrabKey@plt>
add    $0x1,%rbp
cmp    0x8(%rsp),%rbp
jb     11b0 <grabxkey+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    %r15,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@NoSymbol = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"NoSymbol for %s, exiting\0A\00"
@False = global i32 0
@GrabModeAsync = global i32 0
define void @grabxkey(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%13 = load i8*, i8** %8
%14 = call i64 @XStringToKeysym(i8* %13)
store i64 %14, i64* %9
%15 = load i64, i64* %9
%16 = load i64, i64* @NoSymbol
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %8
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %4
%24 = load i32*, i32** %5
%25 = load i64, i64* %9
%26 = call i32 @XtKeysymToKeycodeList(i32* %24, i64 %25, i32** %10, i64* %11)
store i64 0, i64* %12
br label %27
27: ; preds = %43, %23
%28 = load i64, i64* %12
%29 = load i64, i64* %11
%30 = icmp ult i64 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = load i32*, i32** %5
%33 = load i32*, i32** %10
%34 = load i64, i64* %12
%35 = getelementptr inbounds i32, i32* %33, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = load i32, i32* @False
%40 = load i32, i32* @GrabModeAsync
%41 = load i32, i32* @GrabModeAsync
%42 = call i32 @XGrabKey(i32* %32, i32 %36, i32 %37, i32 %38, i32 %39, i32 %40, i32 %41)
br label %43
43: ; preds = %31
%44 = load i64, i64* %12
%45 = add i64 %44, 1
store i64 %45, i64* %12
br label %27
46: ; preds = %27
ret void
}

LLVM IR (-O2):
@NoSymbol = global i64 0
@stderr = global i32 0
@.str = [26 x i8] c"NoSymbol for %s, exiting\0A\00"
@False = global i32 0
@GrabModeAsync = global i32 0
define void @grabxkey(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = bitcast i32** %5 to i8*
%8 = bitcast i64* %6 to i8*
%9 = tail call i64 @XStringToKeysym(i8* %3)
%10 = load i64, i64* @NoSymbol
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %3)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = call i32 @XtKeysymToKeycodeList(i32* %0, i64 %9, i32** %5, i64* %6)
%18 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %16, %20
%21 = phi i64 [ %28, %20 ], [ 0, %16 ]
%22 = load i32*, i32** %5
%23 = getelementptr inbounds i32, i32* %22, i64 %21
%24 = load i32, i32* %23
%25 = load i32, i32* @False
%26 = load i32, i32* @GrabModeAsync
%27 = call i32 @XGrabKey(i32* %0, i32 %24, i32 %2, i32 %1, i32 %25, i32 %26, i32 %26)
%28 = add nuw i64 %21, 1
%29 = load i64, i64* %6
%30 = icmp ult i64 %28, %29
br i1 %30, label %20, label %31
31: ; preds = %20, %16
ret void
}