#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 */
struct TYPE_6__ {
  scalar_t__ time;
  scalar_t__ keycode;
};
struct TYPE_7__ {
  scalar_t__ type;
  TYPE_1__ xkey;
};
typedef TYPE_2__ XEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ KeyPress;
int /*<<< orphan*/ QueuedAfterReading;
scalar_t__ XEventsQueued(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, TYPE_2__ *);
int /*<<< orphan*/ XPeekEvent(int /*<<< orphan*/ *, TYPE_2__ *);
bool consume_autorepeat_event(Display *display, XEvent *event) {
  if (XEventsQueued(display, QueuedAfterReading)) {
    XEvent next_event;
    XPeekEvent(display, &next_event);
    if (next_event.type == KeyPress &&
        next_event.xkey.time == event->xkey.time &&
        next_event.xkey.keycode == event->xkey.keycode) {
      XNextEvent(display, event);
      return true;
    }
  }
  return false;
}


x86 assembly (clang, -O0):
<consume_autorepeat_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
call   1030 <XEventsQueued@plt>
cmp    $0x0,%rax
je     11bf <consume_autorepeat_event+0x8f>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <XPeekEvent@plt>
mov    -0x30(%rbp),%rax
mov    0x2e6c(%rip),%rcx
cmp    (%rcx),%rax
jne    11ba <consume_autorepeat_event+0x8a>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    11ba <consume_autorepeat_event+0x8a>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    0x10(%rcx),%rax
jne    11ba <consume_autorepeat_event+0x8a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <XNextEvent@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c6 <consume_autorepeat_event+0x96>
jmp    11bf <consume_autorepeat_event+0x8f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<consume_autorepeat_event>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
call   1030 <XEventsQueued@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1197 <consume_autorepeat_event+0x67>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <XPeekEvent@plt>
mov    0x8(%rsp),%rax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <consume_autorepeat_event+0x67>
mov    0x10(%rsp),%rax
cmp    0x8(%r14),%rax
jne    1197 <consume_autorepeat_event+0x67>
mov    0x18(%rsp),%rax
cmp    0x10(%r14),%rax
jne    1197 <consume_autorepeat_event+0x67>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <XNextEvent@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_7__ = type { i64, %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i64, i64 }
@QueuedAfterReading = global i32 0
@KeyPress = global i64 0
define i32 @consume_autorepeat_event(i32* %0, %struct.TYPE_7__* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.TYPE_7__*
%6 = alloca %struct.TYPE_7__
store i32* %0, i32** %4
store %struct.TYPE_7__* %1, %struct.TYPE_7__** %5
%7 = load i32*, i32** %4
%8 = load i32, i32* @QueuedAfterReading
%9 = call i64 @XEventsQueued(i32* %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %41
11: ; preds = %2
%12 = load i32*, i32** %4
%13 = call i32 @XPeekEvent(i32* %12, %struct.TYPE_7__* %6)
%14 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @KeyPress
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %40
18: ; preds = %11
%19 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%23 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %22, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %23, i32 0, i32 0
%25 = load i64, i64* %24
%26 = icmp eq i64 %21, %25
br i1 %26, label %27, label %40
27: ; preds = %18
%28 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %6, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%32 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %31, i32 0, i32 1
%33 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %32, i32 0, i32 1
%34 = load i64, i64* %33
%35 = icmp eq i64 %30, %34
br i1 %35, label %36, label %40
36: ; preds = %27
%37 = load i32*, i32** %4
%38 = load %struct.TYPE_7__*, %struct.TYPE_7__** %5
%39 = call i32 @XNextEvent(i32* %37, %struct.TYPE_7__* %38)
store i32 1, i32* %3
br label %42
40: ; preds = %27, %18, %11
br label %41
41: ; preds = %40, %2
store i32 0, i32* %3
br label %42
42: ; preds = %41, %36
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.TYPE_7__ = type { i64, %struct.TYPE_6__ }
%struct.TYPE_6__ = type { i64, i64 }
@QueuedAfterReading = global i32 0
@KeyPress = global i64 0
define i32 @consume_autorepeat_event(i32* %0, %struct.TYPE_7__* %1) {
%3 = alloca %struct.TYPE_7__
%4 = load i32, i32* @QueuedAfterReading
%5 = tail call i64 @XEventsQueued(i32* %0, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %2
%8 = bitcast %struct.TYPE_7__* %3 to i8*
%9 = call i32 @XPeekEvent(i32* %0, %struct.TYPE_7__* %3)
%10 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @KeyPress
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %7
%15 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 1, i32 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %1, i64 0, i32 1, i32 0
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %3, i64 0, i32 1, i32 1
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %1, i64 0, i32 1, i32 1
%24 = load i64, i64* %23
%25 = icmp eq i64 %22, %24
br i1 %25, label %27, label %26
26: ; preds = %20, %14, %7
br label %29
27: ; preds = %20
%28 = call i32 @XNextEvent(i32* %0, %struct.TYPE_7__* %1)
br label %29
29: ; preds = %2, %26, %27
%30 = phi i32 [ 1, %27 ], [ 0, %26 ], [ 0, %2 ]
ret i32 %30
}