#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_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  int keycode;
};
struct TYPE_6__ {
  TYPE_1__ xkey;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ AsyncKeyboard;
int /*<<< orphan*/ AsyncPointer;
int /*<<< orphan*/ CurrentTime;
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
int /*<<< orphan*/ GrabModeAsync;
int /*<<< orphan*/ GrabModeSync;
int KeyPressMask;
int KeyReleaseMask;
int /*<<< orphan*/ ReplayKeyboard;
int /*<<< orphan*/ SyncKeyboard;
int /*<<< orphan*/ XAllowEvents(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                int /*<<< orphan*/);
int XGrabKeyboard(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XWindowEvent(int /*<<< orphan*/ *, int /*<<< orphan*/, int,
                                TYPE_2__ *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *type(TYPE_2__ *);
int main(int argc, char **argv) {
  Display *d;
  XEvent ev;
  int ret;
  d = XOpenDisplay(NULL);
  for (;;) {
    ret = XGrabKeyboard(d, DefaultRootWindow(d), False, GrabModeAsync,
                        GrabModeSync, CurrentTime);
    assert(!ret);
    XAllowEvents(d, SyncKeyboard, CurrentTime);
    XAllowEvents(d, AsyncPointer, CurrentTime);
    assert(!XWindowEvent(d, DefaultRootWindow(d), KeyPressMask | KeyReleaseMask,
                         &ev));
    fprintf(stderr, "%s=%d\n", type(&ev), ev.xkey.keycode);
    fflush(stderr);
    if (ev.xkey.keycode != 25) {
      (!XAllowEvents(d, ReplayKeyboard, CurrentTime));
    } else {
      fprintf(stderr, "w\n");
      (!XAllowEvents(d, AsyncKeyboard, CurrentTime));
    }
  }
  sleep(10);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <DefaultRootWindow@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    0x2dde(%rip),%rax
mov    (%rax),%ecx
mov    0x2ded(%rip),%rax
mov    (%rax),%r8d
mov    0x2dfb(%rip),%rax
mov    (%rax),%r9d
call   10b0 <XGrabKeyboard@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
call   1030 <XAllowEvents@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
call   1030 <XAllowEvents@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <DefaultRootWindow@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    0x2d28(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rcx
call   10a0 <XWindowEvent@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <type@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
mov    -0x20(%rbp),%ecx
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
cmpl   $0x19,-0x20(%rbp)
je     12e9 <main+0x159>
mov    -0x18(%rbp),%rdi
mov    0x2cd4(%rip),%rax
mov    (%rax),%esi
mov    0x2d0b(%rip),%rax
mov    (%rax),%edx
call   1030 <XAllowEvents@plt>
jmp    131b <main+0x18b>
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
lea    0xd0e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
mov    0x2cd4(%rip),%rax
mov    (%rax),%edx
call   1030 <XAllowEvents@plt>
jmp    11b3 <main+0x23>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1060 <XOpenDisplay@plt>
mov    %rax,%rbx
mov    0x2e3c(%rip),%r12
mov    %rsp,%r14
mov    0x2dfa(%rip),%r13
mov    0x2deb(%rip),%r15
jmp    11ce <main+0x3e>
nop
mov    (%rax),%esi
mov    (%r12),%edx
mov    %rbx,%rdi
call   1030 <XAllowEvents@plt>
mov    %rbx,%rdi
call   1050 <DefaultRootWindow@plt>
mov    0x2e03(%rip),%rcx
mov    (%rcx),%edx
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2de1(%rip),%rsi
mov    (%rsi),%r8d
mov    (%r12),%r9d
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <XGrabKeyboard@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    (%r12),%edx
mov    %rbx,%rdi
call   1030 <XAllowEvents@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
mov    (%r12),%edx
mov    %rbx,%rdi
call   1030 <XAllowEvents@plt>
mov    %rbx,%rdi
call   1050 <DefaultRootWindow@plt>
mov    0x2d4a(%rip),%rcx
mov    (%rcx),%edx
mov    0x2d79(%rip),%rcx
or     (%rcx),%edx
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rcx
call   10a0 <XWindowEvent@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1070 <assert@plt>
mov    0x0(%r13),%ebp
mov    %r14,%rdi
call   1040 <type@plt>
mov    (%rsp),%ecx
mov    %ebp,%edi
lea    0xd7d(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%r13),%edi
call   1090 <fflush@plt>
cmpl   $0x19,(%rsp)
mov    %r15,%rax
jne    11c0 <main+0x30>
mov    0x0(%r13),%edi
lea    0xd59(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d1c(%rip),%rax
jmp    11c0 <main+0x30>

LLVM IR (-O0):
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@False = global i32 0
@GrabModeAsync = global i32 0
@GrabModeSync = global i32 0
@CurrentTime = global i32 0
@SyncKeyboard = global i32 0
@AsyncPointer = global i32 0
@KeyPressMask = global i32 0
@KeyReleaseMask = global i32 0
@stderr = global i32 0
@.str = [7 x i8] c"%s=%d\0A\00"
@ReplayKeyboard = global i32 0
@.str.1 = [3 x i8] c"w\0A\00"
@AsyncKeyboard = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.TYPE_6__
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** %6
br label %10
10: ; preds = %73, %2
%11 = load i32*, i32** %6
%12 = load i32*, i32** %6
%13 = call i32 @DefaultRootWindow(i32* %12)
%14 = load i32, i32* @False
%15 = load i32, i32* @GrabModeAsync
%16 = load i32, i32* @GrabModeSync
%17 = load i32, i32* @CurrentTime
%18 = call i32 @XGrabKeyboard(i32* %11, i32 %13, i32 %14, i32 %15, i32 %16, i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
%21 = xor i1 %20, true
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32*, i32** %6
%25 = load i32, i32* @SyncKeyboard
%26 = load i32, i32* @CurrentTime
%27 = call i32 @XAllowEvents(i32* %24, i32 %25, i32 %26)
%28 = load i32*, i32** %6
%29 = load i32, i32* @AsyncPointer
%30 = load i32, i32* @CurrentTime
%31 = call i32 @XAllowEvents(i32* %28, i32 %29, i32 %30)
%32 = load i32*, i32** %6
%33 = load i32*, i32** %6
%34 = call i32 @DefaultRootWindow(i32* %33)
%35 = load i32, i32* @KeyPressMask
%36 = load i32, i32* @KeyReleaseMask
%37 = or i32 %35, %36
%38 = call i32 @XWindowEvent(i32* %32, i32 %34, i32 %37, %struct.TYPE_6__* %7)
%39 = icmp ne i32 %38, 0
%40 = xor i1 %39, true
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i32, i32* @stderr
%44 = call i8* @type(%struct.TYPE_6__* %7)
%45 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %44, i32 %47)
%49 = load i32, i32* @stderr
%50 = call i32 @fflush(i32 %49)
%51 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
%52 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %51, i32 0, i32 0
%53 = load i32, i32* %52
%54 = icmp ne i32 %53, 25
br i1 %54, label %55, label %63
55: ; preds = %10
%56 = load i32*, i32** %6
%57 = load i32, i32* @ReplayKeyboard
%58 = load i32, i32* @CurrentTime
%59 = call i32 @XAllowEvents(i32* %56, i32 %57, i32 %58)
%60 = icmp ne i32 %59, 0
%61 = xor i1 %60, true
%62 = zext i1 %61 to i32
br label %73
63: ; preds = %10
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%66 = load i32*, i32** %6
%67 = load i32, i32* @AsyncKeyboard
%68 = load i32, i32* @CurrentTime
%69 = call i32 @XAllowEvents(i32* %66, i32 %67, i32 %68)
%70 = icmp ne i32 %69, 0
%71 = xor i1 %70, true
%72 = zext i1 %71 to i32
br label %73
73: ; preds = %63, %55
br label %10
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { %struct.TYPE_5__ }
%struct.TYPE_5__ = type { i32 }
@False = global i32 0
@GrabModeAsync = global i32 0
@GrabModeSync = global i32 0
@CurrentTime = global i32 0
@SyncKeyboard = global i32 0
@AsyncPointer = global i32 0
@KeyPressMask = global i32 0
@KeyReleaseMask = global i32 0
@stderr = global i32 0
@.str = [7 x i8] c"%s=%d\0A\00"
@ReplayKeyboard = global i32 0
@.str.1 = [3 x i8] c"w\0A\00"
@AsyncKeyboard = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.TYPE_6__
%4 = bitcast %struct.TYPE_6__* %3 to i8*
%5 = tail call i32* @XOpenDisplay(i32* null)
%6 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 0, i32 0
br label %7
7: ; preds = %42, %2
%8 = call i32 @DefaultRootWindow(i32* %5)
%9 = load i32, i32* @False
%10 = load i32, i32* @GrabModeAsync
%11 = load i32, i32* @GrabModeSync
%12 = load i32, i32* @CurrentTime
%13 = call i32 @XGrabKeyboard(i32* %5, i32 %8, i32 %9, i32 %10, i32 %11, i32 %12)
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i32, i32* @SyncKeyboard
%18 = load i32, i32* @CurrentTime
%19 = call i32 @XAllowEvents(i32* %5, i32 %17, i32 %18)
%20 = load i32, i32* @AsyncPointer
%21 = load i32, i32* @CurrentTime
%22 = call i32 @XAllowEvents(i32* %5, i32 %20, i32 %21)
%23 = call i32 @DefaultRootWindow(i32* %5)
%24 = load i32, i32* @KeyPressMask
%25 = load i32, i32* @KeyReleaseMask
%26 = or i32 %25, %24
%27 = call i32 @XWindowEvent(i32* %5, i32 %23, i32 %26, %struct.TYPE_6__* %3)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* @stderr
%32 = call i8* @type(%struct.TYPE_6__* %3)
%33 = load i32, i32* %6
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %33)
%35 = load i32, i32* @stderr
%36 = call i32 @fflush(i32 %35)
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, 25
br i1 %38, label %39, label %42
39: ; preds = %7
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %7, %39
%43 = phi i32* [ @AsyncKeyboard, %39 ], [ @ReplayKeyboard, %7 ]
%44 = load i32, i32* %43
%45 = load i32, i32* @CurrentTime
%46 = call i32 @XAllowEvents(i32* %5, i32 %44, i32 %45)
br label %7
}