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

/* Variables and functions */
int /*<<< orphan*/ AnyPropertyType;
int /*<<< orphan*/ *DisplayOfScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
scalar_t__ None;
scalar_t__ Success;
int /*<<< orphan*/ True;
scalar_t__ XGetWindowProperty(int /*<<< orphan*/ *, scalar_t__,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/, scalar_t__ *, int *,
                              unsigned long *, unsigned long *,
                              unsigned char **);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
int /*<<< orphan*/ XQueryTree(int /*<<< orphan*/ *, scalar_t__, scalar_t__ *,
                              scalar_t__ *, scalar_t__ **, unsigned int *);
Bool top_level_window_p(Screen *screen, Window window) {
  Display *dpy = DisplayOfScreen(screen);
  Window root, parent, *kids;
  unsigned int nkids;
  if (!XQueryTree(dpy, window, &root, &parent, &kids, &nkids))
    return False;
  if (window == root)
    return True;
  if (parent == root)
    return True;
  else {
    Atom type = None;
    int format;
    unsigned long nitems, bytesafter;
    unsigned char *data;
    if (XGetWindowProperty(dpy, window, XInternAtom(dpy, "WM_STATE", True), 0,
                           0, False, AnyPropertyType, &type, &format, &nitems,
                           &bytesafter, (unsigned char **)&data) == Success &&
        type != None)
      return True;
  }
  return False;
}


x86 assembly (clang, -O0):
<top_level_window_p>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <DisplayOfScreen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
lea    -0x50(%rbp),%r8
lea    -0x54(%rbp),%r9
call   1030 <XQueryTree@plt>
cmp    $0x0,%eax
jne    119c <top_level_window_p+0x5c>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12bd <top_level_window_p+0x17d>
mov    -0x30(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    11bb <top_level_window_p+0x7b>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12bd <top_level_window_p+0x17d>
mov    -0x48(%rbp),%rax
cmp    -0x40(%rbp),%rax
jne    11da <top_level_window_p+0x9a>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12bd <top_level_window_p+0x17d>
mov    0x2def(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
lea    0xdee(%rip),%rsi
call   1050 <XInternAtom@plt>
mov    -0x90(%rbp),%rdi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
mov    0x2daa(%rip),%rax
mov    (%rax),%r9d
mov    0x2db0(%rip),%rax
mov    (%rax),%r15d
xor    %r8d,%r8d
lea    -0x60(%rbp),%r14
lea    -0x64(%rbp),%rbx
lea    -0x70(%rbp),%r11
lea    -0x78(%rbp),%r10
lea    -0x80(%rbp),%rax
mov    %r8d,%ecx
mov    %r15d,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1060 <XGetWindowProperty@plt>
mov    0x2d7a(%rip),%rcx
cmp    (%rcx),%rax
jne    12ac <top_level_window_p+0x16c>
mov    -0x60(%rbp),%rax
mov    0x2d3e(%rip),%rcx
cmp    (%rcx),%rax
je     12ac <top_level_window_p+0x16c>
mov    0x2d26(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12bd <top_level_window_p+0x17d>
jmp    12b1 <top_level_window_p+0x171>
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<top_level_window_p>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
call   1040 <DisplayOfScreen@plt>
mov    %rax,%r14
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x40(%rsp),%r8
lea    0x24(%rsp),%r9
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <XQueryTree@plt>
test   %eax,%eax
je     1236 <top_level_window_p+0xf6>
mov    0x18(%rsp),%rax
cmp    %rbx,%rax
je     1191 <top_level_window_p+0x51>
cmp    %rax,0x10(%rsp)
jne    119d <top_level_window_p+0x5d>
mov    0x2e30(%rip),%rax
jmp    123d <top_level_window_p+0xfd>
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
lea    0xe44(%rip),%rsi
mov    %r14,%rdi
call   1050 <XInternAtom@plt>
mov    0x2e0d(%rip),%rcx
mov    (%rcx),%r9d
mov    0x2e13(%rip),%rcx
mov    (%rcx),%r10d
lea    0x28(%rsp),%r11
lea    0x30(%rsp),%rbp
lea    0x38(%rsp),%r12
lea    0x20(%rsp),%r15
lea    0x8(%rsp),%r13
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
push   %r11
push   %rbp
push   %r12
push   %r15
push   %r13
push   %r10
call   1060 <XGetWindowProperty@plt>
add    $0x30,%rsp
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
jne    1236 <top_level_window_p+0xf6>
mov    0x2da3(%rip),%rdx
mov    0x8(%rsp),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
jne    124e <top_level_window_p+0x10e>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rdx),%eax
jmp    123f <top_level_window_p+0xff>

LLVM IR (-O0):
@False = global i32 0
@True = global i32 0
@None = global i64 0
@.str = [9 x i8] c"WM_STATE\00"
@AnyPropertyType = global i32 0
@Success = global i64 0
define i32 @top_level_window_p(i32* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
%15 = alloca i8*
store i32* %0, i32** %4
store i64 %1, i64* %5
%16 = load i32*, i32** %4
%17 = call i32* @DisplayOfScreen(i32* %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = load i64, i64* %5
%20 = call i32 @XQueryTree(i32* %18, i64 %19, i64* %7, i64* %8, i64** %9, i32* %10)
%21 = icmp ne i32 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %2
%23 = load i32, i32* @False
store i32 %23, i32* %3
br label %57
24: ; preds = %2
%25 = load i64, i64* %5
%26 = load i64, i64* %7
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32, i32* @True
store i32 %29, i32* %3
br label %57
30: ; preds = %24
%31 = load i64, i64* %8
%32 = load i64, i64* %7
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = load i32, i32* @True
store i32 %35, i32* %3
br label %57
36: ; preds = %30
%37 = load i64, i64* @None
store i64 %37, i64* %11
%38 = load i32*, i32** %6
%39 = load i64, i64* %5
%40 = load i32*, i32** %6
%41 = load i32, i32* @True
%42 = call i32 @XInternAtom(i32* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = load i32, i32* @False
%44 = load i32, i32* @AnyPropertyType
%45 = call i64 @XGetWindowProperty(i32* %38, i64 %39, i32 %42, i32 0, i32 0, i32 %43, i32 %44, i64* %11, i32* %12, i64* %13, i64* %14, i8** %15)
%46 = load i64, i64* @Success
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %36
%49 = load i64, i64* %11
%50 = load i64, i64* @None
%51 = icmp ne i64 %49, %50
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = load i32, i32* @True
store i32 %53, i32* %3
br label %57
54: ; preds = %48, %36
br label %55
55: ; preds = %54
%56 = load i32, i32* @False
store i32 %56, i32* %3
br label %57
57: ; preds = %55, %52, %34, %28, %22
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@False = global i32 0
@True = global i32 0
@None = global i64 0
@.str = [9 x i8] c"WM_STATE\00"
@AnyPropertyType = global i32 0
@Success = global i64 0
define i32 @top_level_window_p(i32* %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = tail call i32* @DisplayOfScreen(i32* %0)
%13 = bitcast i64* %3 to i8*
%14 = bitcast i64* %4 to i8*
%15 = bitcast i64** %5 to i8*
%16 = bitcast i32* %6 to i8*
%17 = call i32 @XQueryTree(i32* %12, i64 %1, i64* %3, i64* %4, i64** %5, i32* %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load i32, i32* @False
br label %53
21: ; preds = %2
%22 = load i64, i64* %3
%23 = icmp eq i64 %22, %1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i32, i32* @True
br label %53
26: ; preds = %21
%27 = load i64, i64* %4
%28 = icmp eq i64 %27, %22
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i32, i32* @True
br label %53
31: ; preds = %26
%32 = bitcast i64* %7 to i8*
%33 = load i64, i64* @None
store i64 %33, i64* %7
%34 = bitcast i32* %8 to i8*
%35 = bitcast i64* %9 to i8*
%36 = bitcast i64* %10 to i8*
%37 = bitcast i8** %11 to i8*
%38 = load i32, i32* @True
%39 = call i32 @XInternAtom(i32* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @False
%41 = load i32, i32* @AnyPropertyType
%42 = call i64 @XGetWindowProperty(i32* %12, i64 %1, i32 %39, i32 0, i32 0, i32 %40, i32 %41, i64* %7, i32* %8, i64* %9, i64* %10, i8** %11)
%43 = load i64, i64* @Success
%44 = icmp eq i64 %42, %43
br i1 %44, label %46, label %45
45: ; preds = %31
br label %51
46: ; preds = %31
%47 = load i64, i64* %7
%48 = load i64, i64* @None
%49 = icmp eq i64 %47, %48
%50 = load i32, i32* @True
br i1 %49, label %51, label %53
51: ; preds = %45, %46
%52 = load i32, i32* @False
br label %53
53: ; preds = %51, %46, %29, %24, %19
%54 = phi i32 [ %25, %24 ], [ %30, %29 ], [ %20, %19 ], [ %52, %51 ], [ %50, %46 ]
ret i32 %54
}