#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 type;
};
typedef TYPE_1__ XEvent;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;
typedef int /*<<< orphan*/ Bool;

/* Variables and functions */
unsigned int ControlMask;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
int GrabModeAsync;
#define KeyPress 128
int /*<<< orphan*/ KeyPressMask;
unsigned int ShiftMask;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XGrabKey(int /*<<< orphan*/ *, int, unsigned int,
                            int /*<<< orphan*/, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ XK_K;
int XKeysymToKeycode(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/);
int /*<<< orphan*/ XSelectInput(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int /*<<< orphan*/ XUngrabKey(int /*<<< orphan*/ *, int, unsigned int,
                              int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main() {
  Display *dpy = XOpenDisplay(0);
  Window root = DefaultRootWindow(dpy);
  XEvent ev;
  unsigned int modifiers = ControlMask | ShiftMask;
  int keycode = XKeysymToKeycode(dpy, XK_K);
  Window grab_window = root;
  Bool owner_events = False;
  int pointer_mode = GrabModeAsync;
  int keyboard_mode = GrabModeAsync;
  XGrabKey(dpy, keycode, modifiers, grab_window, owner_events, pointer_mode,
           keyboard_mode);
  XSelectInput(dpy, root, KeyPressMask);
  int running = 1;
  while (running) {
    XNextEvent(dpy, &ev);
    switch (ev.type) {
    case KeyPress: {
      printf("Hot key pressed!\n");
      XUngrabKey(dpy, keycode, modifiers, grab_window);
      running = 0;
    } break;
    default:
      break;
    }
  }
  XCloseDisplay(dpy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <DefaultRootWindow@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    0x2e22(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
call   1060 <XKeysymToKeycode@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x30(%rbp),%eax
mov    %eax,(%rsp)
call   1070 <XGrabKey@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
call   1090 <XSelectInput@plt>
movl   $0x1,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12a4 <main+0x114>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <XNextEvent@plt>
mov    -0x18(%rbp),%eax
sub    $0x80,%eax
jne    129a <main+0x10a>
jmp    1270 <main+0xe0>
lea    0xd89(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   10a0 <XUngrabKey@plt>
movl   $0x0,-0x34(%rbp)
jmp    129f <main+0x10f>
jmp    129f <main+0x10f>
jmp    1246 <main+0xb6>
mov    -0x10(%rbp),%rdi
call   10b0 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <XOpenDisplay@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <DefaultRootWindow@plt>
mov    %eax,%r14d
mov    0x2e28(%rip),%rax
mov    0x2e29(%rip),%rcx
mov    (%rcx),%r12d
or     (%rax),%r12d
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <XKeysymToKeycode@plt>
mov    %eax,%r15d
mov    0x2df8(%rip),%rax
mov    (%rax),%r8d
mov    0x2dce(%rip),%rax
mov    (%rax),%r9d
mov    %r9d,(%rsp)
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
call   1070 <XGrabKey@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14d,%esi
call   1090 <XSelectInput@plt>
lea    0x8(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <XNextEvent@plt>
cmpl   $0x80,0x8(%rsp)
jne    1220 <main+0x90>
lea    0xdc4(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
mov    %r14d,%ecx
call   10a0 <XUngrabKey@plt>
mov    %rbx,%rdi
call   10b0 <XCloseDisplay@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@ControlMask = global i32 0
@ShiftMask = global i32 0
@XK_K = global i32 0
@False = global i32 0
@GrabModeAsync = global i32 0
@KeyPressMask = global i32 0
@.str = [18 x i8] c"Hot key pressed!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca %struct.TYPE_3__
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
%12 = call i32* @XOpenDisplay(i32 0)
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = call i32 @DefaultRootWindow(i32* %13)
store i32 %14, i32* %3
%15 = load i32, i32* @ControlMask
%16 = load i32, i32* @ShiftMask
%17 = or i32 %15, %16
store i32 %17, i32* %5
%18 = load i32*, i32** %2
%19 = load i32, i32* @XK_K
%20 = call i32 @XKeysymToKeycode(i32* %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %3
store i32 %21, i32* %7
%22 = load i32, i32* @False
store i32 %22, i32* %8
%23 = load i32, i32* @GrabModeAsync
store i32 %23, i32* %9
%24 = load i32, i32* @GrabModeAsync
store i32 %24, i32* %10
%25 = load i32*, i32** %2
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i32 @XGrabKey(i32* %25, i32 %26, i32 %27, i32 %28, i32 %29, i32 %30, i32 %31)
%33 = load i32*, i32** %2
%34 = load i32, i32* %3
%35 = load i32, i32* @KeyPressMask
%36 = call i32 @XSelectInput(i32* %33, i32 %34, i32 %35)
store i32 1, i32* %11
br label %37
37: ; preds = %53, %0
%38 = load i32, i32* %11
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %54
40: ; preds = %37
%41 = load i32*, i32** %2
%42 = call i32 @XNextEvent(i32* %41, %struct.TYPE_3__* %4)
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
%44 = load i32, i32* %43
switch i32 %44, label %52 [
i32 128, label %45
]
45: ; preds = %40
%46 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%47 = load i32*, i32** %2
%48 = load i32, i32* %6
%49 = load i32, i32* %5
%50 = load i32, i32* %7
%51 = call i32 @XUngrabKey(i32* %47, i32 %48, i32 %49, i32 %50)
store i32 0, i32* %11
br label %53
52: ; preds = %40
br label %53
53: ; preds = %52, %45
br label %37
54: ; preds = %37
%55 = load i32*, i32** %2
%56 = call i32 @XCloseDisplay(i32* %55)
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@ControlMask = global i32 0
@ShiftMask = global i32 0
@XK_K = global i32 0
@False = global i32 0
@GrabModeAsync = global i32 0
@KeyPressMask = global i32 0
@str = [17 x i8] c"Hot key pressed!\00"
define i32 @main() {
%1 = alloca %struct.TYPE_3__
%2 = tail call i32* @XOpenDisplay(i32 0)
%3 = tail call i32 @DefaultRootWindow(i32* %2)
%4 = bitcast %struct.TYPE_3__* %1 to i8*
%5 = load i32, i32* @ControlMask
%6 = load i32, i32* @ShiftMask
%7 = or i32 %6, %5
%8 = load i32, i32* @XK_K
%9 = tail call i32 @XKeysymToKeycode(i32* %2, i32 %8)
%10 = load i32, i32* @False
%11 = load i32, i32* @GrabModeAsync
%12 = tail call i32 @XGrabKey(i32* %2, i32 %9, i32 %7, i32 %3, i32 %10, i32 %11, i32 %11)
%13 = load i32, i32* @KeyPressMask
%14 = tail call i32 @XSelectInput(i32* %2, i32 %3, i32 %13)
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
br label %16
16: ; preds = %16, %0
%17 = call i32 @XNextEvent(i32* %2, %struct.TYPE_3__* %1)
%18 = load i32, i32* %15
%19 = icmp eq i32 %18, 128
br i1 %19, label %20, label %16
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%22 = call i32 @XUngrabKey(i32* %2, i32 %9, i32 %7, i32 %3)
%23 = call i32 @XCloseDisplay(i32* %2)
ret i32 0
}