#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*/ XEvent;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ glinject_handle_x11_event(int /*<<< orphan*/ *);
int /*<<< orphan*/ glinject_real_XNextEvent(int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *);
int glinject_real_XPeekEvent(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int XPeekEvent(Display *dpy, XEvent *event) {
  int return_val = glinject_real_XPeekEvent(dpy, event);
  while (glinject_handle_x11_event(event)) {
    glinject_real_XNextEvent(dpy, event);
    return_val = glinject_real_XPeekEvent(dpy, event);
  }
  return return_val;
}


x86 assembly (clang, -O0):
<XPeekEvent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <glinject_real_XPeekEvent@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <glinject_handle_x11_event@plt>
cmp    $0x0,%rax
je     1185 <XPeekEvent+0x55>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <glinject_real_XNextEvent@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <glinject_real_XPeekEvent@plt>
mov    %eax,-0x14(%rbp)
jmp    1150 <XPeekEvent+0x20>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XPeekEvent>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
call   1030 <glinject_real_XPeekEvent@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <glinject_handle_x11_event@plt>
test   %rax,%rax
je     1167 <XPeekEvent+0x37>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <glinject_real_XNextEvent@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
jmp    1140 <XPeekEvent+0x10>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @XPeekEvent(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %3
%7 = load i32*, i32** %4
%8 = call i32 @glinject_real_XPeekEvent(i32* %6, i32* %7)
store i32 %8, i32* %5
br label %9
9: ; preds = %13, %2
%10 = load i32*, i32** %4
%11 = call i64 @glinject_handle_x11_event(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i32*, i32** %3
%15 = load i32*, i32** %4
%16 = call i32 @glinject_real_XNextEvent(i32* %14, i32* %15)
%17 = load i32*, i32** %3
%18 = load i32*, i32** %4
%19 = call i32 @glinject_real_XPeekEvent(i32* %17, i32* %18)
store i32 %19, i32* %5
br label %9
20: ; preds = %9
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
define i32 @XPeekEvent(i32* %0, i32* %1) {
%3 = tail call i32 @glinject_real_XPeekEvent(i32* %0, i32* %1)
%4 = tail call i64 @glinject_handle_x11_event(i32* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %2, %6
%7 = tail call i32 @glinject_real_XNextEvent(i32* %0, i32* %1)
%8 = tail call i32 @glinject_real_XPeekEvent(i32* %0, i32* %1)
%9 = tail call i64 @glinject_handle_x11_event(i32* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %6
11: ; preds = %6, %2
%12 = phi i32 [ %3, %2 ], [ %8, %6 ]
ret i32 %12
}