#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 */
int /*<<< orphan*/ ConnectionNumber(int /*<<< orphan*/ *);
int /*<<< orphan*/ XNextEvent(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ XPending(int /*<<< orphan*/ *);
scalar_t__ wait_fd_seconds(int /*<<< orphan*/, double);
int XNextEventTimeout(Display *display, XEvent *event, double seconds) {
  if (XPending(display) ||
      wait_fd_seconds(ConnectionNumber(display), seconds)) {
    XNextEvent(display, event);
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<XNextEventTimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <XPending@plt>
cmp    $0x0,%rax
jne    1187 <XNextEventTimeout+0x47>
mov    -0x10(%rbp),%rdi
call   1050 <ConnectionNumber@plt>
mov    %eax,%edi
movsd  -0x20(%rbp),%xmm0
call   1030 <wait_fd_seconds@plt>
cmp    $0x0,%rax
je     11a0 <XNextEventTimeout+0x60>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <XNextEvent@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <XNextEventTimeout+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XNextEventTimeout>:
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <XPending@plt>
test   %rax,%rax
jne    1172 <XNextEventTimeout+0x32>
mov    %rbx,%rdi
call   1050 <ConnectionNumber@plt>
mov    %eax,%edi
movsd  (%rsp),%xmm0
call   1030 <wait_fd_seconds@plt>
test   %rax,%rax
je     118a <XNextEventTimeout+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <XNextEvent@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    1182 <XNextEventTimeout+0x42>

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

LLVM IR (-O2):
define i32 @XNextEventTimeout(i32* %0, i32* %1, double %2) {
%4 = tail call i64 @XPending(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @ConnectionNumber(i32* %0)
%8 = tail call i64 @wait_fd_seconds(i32 %7, double %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6, %3
%11 = tail call i32 @XNextEvent(i32* %0, i32* %1)
br label %12
12: ; preds = %6, %10
%13 = phi i32 [ 1, %10 ], [ 0, %6 ]
ret i32 %13
}