#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 (abs(active_win - ev_win) <= 1) {
    ret_val = 1;
  } else {
    if (cache_xquery_result(dpy, active_win)) {
      ret_val = lookup_in_xquery_cache(ev_win);
    }
  }
  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    11d2 <event_on_active_or_adj_window+0x92>
mov    -0x20(%rbp),%rdi
sub    -0x28(%rbp),%rdi
call   1030 <abs@plt>
cmp    $0x1,%eax
jg     11a4 <event_on_active_or_adj_window+0x64>
movl   $0x1,-0x2c(%rbp)
jmp    11cc <event_on_active_or_adj_window+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <cache_xquery_result@plt>
cmp    $0x0,%rax
je     11c7 <event_on_active_or_adj_window+0x87>
mov    -0x28(%rbp),%rdi
call   1060 <lookup_in_xquery_cache@plt>
mov    %eax,-0x2c(%rbp)
jmp    11cc <event_on_active_or_adj_window+0x8c>
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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <extract_window_id@plt>
mov    $0x1,%ebp
cmp    %rbx,%rax
je     1196 <event_on_active_or_adj_window+0x56>
mov    %rax,%r14
mov    %rbx,%rdi
sub    %rax,%rdi
call   1030 <abs@plt>
cmp    $0x2,%eax
jl     1196 <event_on_active_or_adj_window+0x56>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <cache_xquery_result@plt>
test   %rax,%rax
je     1194 <event_on_active_or_adj_window+0x54>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <lookup_in_xquery_cache@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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 %34
16: ; preds = %3
%17 = load i64, i64* %7
%18 = load i64, i64* %8
%19 = sub nsw i64 %17, %18
%20 = call i32 @abs(i64 %19)
%21 = icmp sle i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 1, i32* %9
br label %32
23: ; preds = %16
%24 = load i32*, i32** %5
%25 = load i64, i64* %7
%26 = call i64 @cache_xquery_result(i32* %24, i64 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i64, i64* %8
%30 = call i32 @lookup_in_xquery_cache(i64 %29)
store i32 %30, i32* %9
br label %31
31: ; preds = %28, %23
br label %32
32: ; preds = %31, %22
%33 = load i32, i32* %9
store i32 %33, i32* %4
br label %34
34: ; preds = %32, %15
%35 = load i32, i32* %4
ret i32 %35
}

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 %15, label %6
6: ; preds = %3
%7 = sub nsw i64 %2, %4
%8 = tail call i32 @abs(i64 %7)
%9 = icmp slt i32 %8, 2
br i1 %9, label %15, label %10
10: ; preds = %6
%11 = tail call i64 @cache_xquery_result(i32* %0, i64 %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @lookup_in_xquery_cache(i64 %4)
br label %15
15: ; preds = %13, %10, %6, %3
%16 = phi i32 [ 1, %3 ], [ %14, %13 ], [ 0, %10 ], [ 1, %6 ]
ret i32 %16
}