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

/* Variables and functions */
int abs(scalar_t__);
scalar_t__ cache_xquery_result(int /*<<< orphan*/ *, scalar_t__);
scalar_t__ extract_window_id(int /*<<< orphan*/ *);
int lookup_in_xquery_cache(scalar_t__);
int event_on_active_or_adj_window(Display *dpy, XEvent *ev, Window active_win) {
  Window ev_win;
  int ret_val = 0;
  ev_win = extract_window_id(ev);
  if (active_win == ev_win) {
    return 1;
  }
  if (cache_xquery_result(dpy, active_win)) {
    ret_val = lookup_in_xquery_cache(ev_win);
  } else {
    ret_val = (abs(active_win - ev_win) <= 1);
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<event_on_active_or_adj_window>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <extract_window_id@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1182 <event_on_active_or_adj_window+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11cb <event_on_active_or_adj_window+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <cache_xquery_result@plt>
cmp    $0x0,%rax
je     11aa <event_on_active_or_adj_window+0x6a>
mov    -0x28(%rbp),%rdi
call   1060 <lookup_in_xquery_cache@plt>
mov    %eax,-0x2c(%rbp)
jmp    11c5 <event_on_active_or_adj_window+0x85>
mov    -0x20(%rbp),%rdi
sub    -0x28(%rbp),%rdi
call   1030 <abs@plt>
cmp    $0x1,%eax
setle  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_on_active_or_adj_window>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <extract_window_id@plt>
mov    %rax,%r14
mov    $0x1,%eax
cmp    %rbx,%r14
je     1192 <event_on_active_or_adj_window+0x52>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <cache_xquery_result@plt>
test   %rax,%rax
je     117d <event_on_active_or_adj_window+0x3d>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <lookup_in_xquery_cache@plt>
sub    %r14,%rbx
mov    %rbx,%rdi
call   1030 <abs@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
setl   %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @event_on_active_or_adj_window(i32* %0, i32* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i64 %2, i64* %7
store i32 0, i32* %9
%10 = load i32*, i32** %6
%11 = call i64 @extract_window_id(i32* %10)
store i64 %11, i64* %8
%12 = load i64, i64* %7
%13 = load i64, i64* %8
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 1, i32* %4
br label %33
16: ; preds = %3
%17 = load i32*, i32** %5
%18 = load i64, i64* %7
%19 = call i64 @cache_xquery_result(i32* %17, i64 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i64, i64* %8
%23 = call i32 @lookup_in_xquery_cache(i64 %22)
store i32 %23, i32* %9
br label %31
24: ; preds = %16
%25 = load i64, i64* %7
%26 = load i64, i64* %8
%27 = sub nsw i64 %25, %26
%28 = call i32 @abs(i64 %27)
%29 = icmp sle i32 %28, 1
%30 = zext i1 %29 to i32
store i32 %30, i32* %9
br label %31
31: ; preds = %24, %21
%32 = load i32, i32* %9
store i32 %32, i32* %4
br label %33
33: ; preds = %31, %15
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @event_on_active_or_adj_window(i32* %0, i32* %1, i64 %2) {
%4 = tail call i64 @extract_window_id(i32* %1)
%5 = icmp eq i64 %4, %2
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = tail call i64 @cache_xquery_result(i32* %0, i64 %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @lookup_in_xquery_cache(i64 %4)
br label %16
11: ; preds = %6
%12 = sub nsw i64 %2, %4
%13 = tail call i32 @abs(i64 %12)
%14 = icmp slt i32 %13, 2
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %9, %11, %3
%17 = phi i32 [ 1, %3 ], [ %10, %9 ], [ %15, %11 ]
ret i32 %17
}