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

/* Variables and functions */
int /*<<< orphan*/ AnyPropertyType;
int /*<<< orphan*/ False;
scalar_t__ None;
int /*<<< orphan*/ XGetWindowProperty(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                      scalar_t__, int /*<<< orphan*/,
                                      int /*<<< orphan*/, int /*<<< orphan*/,
                                      int /*<<< orphan*/, scalar_t__ *, int *,
                                      unsigned long *, unsigned long *,
                                      unsigned char **);
int /*<<< orphan*/ XQueryTree(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              int /*<<< orphan*/ **, unsigned int *);
Window GetAtomWindow(Display *dpy, Window win, Atom atom) {
  Window root, parent;
  Window *children;
  unsigned int nchildren;
  int i;
  Atom type = None;
  int format;
  unsigned long nitems, after;
  unsigned char *data;
  Window inf = 0;
  XGetWindowProperty(dpy, win, atom, 0, 0, False, AnyPropertyType, &type,
                     &format, &nitems, &after, &data);
  if (type)
    return win;
  else {
    if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren) ||
        (nchildren == 0))
      return 0;
    for (i = nchildren - 1; i >= 0; i--) {
      if (inf = GetAtomWindow(dpy, children[i], atom))
        return inf;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<GetAtomWindow>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rdi,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %rdx,-0x38(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    0x2e6e(%rip),%rax
mov    (%rax),%r9d
mov    0x2e74(%rip),%rax
mov    (%rax),%r15d
xor    %r8d,%r8d
lea    -0x58(%rbp),%r14
lea    -0x5c(%rbp),%rbx
lea    -0x68(%rbp),%r11
lea    -0x70(%rbp),%r10
lea    -0x78(%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   1050 <XGetWindowProperty@plt>
cmpq   $0x0,-0x58(%rbp)
je     11d1 <GetAtomWindow+0xa1>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    126d <GetAtomWindow+0x13d>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x3c(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x48(%rbp),%r8
lea    -0x4c(%rbp),%r9
call   1030 <XQueryTree@plt>
cmp    $0x0,%eax
je     1200 <GetAtomWindow+0xd0>
cmpl   $0x0,-0x4c(%rbp)
jne    120c <GetAtomWindow+0xdc>
movl   $0x0,-0x1c(%rbp)
jmp    126d <GetAtomWindow+0x13d>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jl     1261 <GetAtomWindow+0x131>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x38(%rbp),%rdx
call   1040 <GetAtomWindow@plt>
mov    %eax,-0x7c(%rbp)
cmp    $0x0,%eax
je     124e <GetAtomWindow+0x11e>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    126d <GetAtomWindow+0x13d>
jmp    1253 <GetAtomWindow+0x123>
mov    -0x50(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x50(%rbp)
jmp    1215 <GetAtomWindow+0xe5>
jmp    1266 <GetAtomWindow+0x136>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetAtomWindow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    0x2e84(%rip),%rax
mov    (%rax),%r9d
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
lea    0x30(%rsp),%rbx
lea    0x38(%rsp),%r10
lea    0x40(%rsp),%r11
lea    0x24(%rsp),%r12
lea    0x10(%rsp),%r13
xor    %ecx,%ecx
xor    %r8d,%r8d
push   %rbx
push   %r10
push   %r11
push   %r12
push   %r13
push   %rax
call   1050 <XGetWindowProperty@plt>
add    $0x30,%rsp
cmpq   $0x0,0x10(%rsp)
jne    11f6 <GetAtomWindow+0xc6>
lea    0x2c(%rsp),%rdx
lea    0x28(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <XQueryTree@plt>
test   %eax,%eax
je     11f4 <GetAtomWindow+0xc4>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
je     11f4 <GetAtomWindow+0xc4>
add    $0xffffffff,%ebx
xchg   %ax,%ax
test   %ebx,%ebx
js     11f4 <GetAtomWindow+0xc4>
mov    0x18(%rsp),%rax
mov    %ebx,%ecx
mov    (%rax,%rcx,4),%esi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <GetAtomWindow@plt>
add    $0xffffffff,%ebx
test   %eax,%eax
je     11d0 <GetAtomWindow+0xa0>
mov    %eax,%ebp
jmp    11f6 <GetAtomWindow+0xc6>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@None = global i64 0
@False = global i32 0
@AnyPropertyType = global i32 0
define i32 @GetAtomWindow(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%19 = load i64, i64* @None
store i64 %19, i64* %13
store i32 0, i32* %18
%20 = load i32*, i32** %5
%21 = load i32, i32* %6
%22 = load i64, i64* %7
%23 = load i32, i32* @False
%24 = load i32, i32* @AnyPropertyType
%25 = call i32 @XGetWindowProperty(i32* %20, i32 %21, i64 %22, i32 0, i32 0, i32 %23, i32 %24, i64* %13, i32* %14, i64* %15, i64* %16, i8** %17)
%26 = load i64, i64* %13
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %3
%29 = load i32, i32* %6
store i32 %29, i32* %4
br label %63
30: ; preds = %3
%31 = load i32*, i32** %5
%32 = load i32, i32* %6
%33 = call i32 @XQueryTree(i32* %31, i32 %32, i32* %8, i32* %9, i32** %10, i32* %11)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* %11
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35, %30
store i32 0, i32* %4
br label %63
39: ; preds = %35
%40 = load i32, i32* %11
%41 = sub i32 %40, 1
store i32 %41, i32* %12
br label %42
42: ; preds = %58, %39
%43 = load i32, i32* %12
%44 = icmp sge i32 %43, 0
br i1 %44, label %45, label %61
45: ; preds = %42
%46 = load i32*, i32** %5
%47 = load i32*, i32** %10
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = load i32, i32* %50
%52 = load i64, i64* %7
%53 = call i32 @GetAtomWindow(i32* %46, i32 %51, i64 %52)
store i32 %53, i32* %18
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %45
%56 = load i32, i32* %18
store i32 %56, i32* %4
br label %63
57: ; preds = %45
br label %58
58: ; preds = %57
%59 = load i32, i32* %12
%60 = add nsw i32 %59, -1
store i32 %60, i32* %12
br label %42
61: ; preds = %42
br label %62
62: ; preds = %61
store i32 0, i32* %4
br label %63
63: ; preds = %62, %55, %38, %28
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@None = global i64 0
@False = global i32 0
@AnyPropertyType = global i32 0
define i32 @GetAtomWindow(i32* %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = bitcast i32* %4 to i8*
%14 = bitcast i32* %5 to i8*
%15 = bitcast i32** %6 to i8*
%16 = bitcast i32* %7 to i8*
%17 = bitcast i64* %8 to i8*
%18 = load i64, i64* @None
store i64 %18, i64* %8
%19 = bitcast i32* %9 to i8*
%20 = bitcast i64* %10 to i8*
%21 = bitcast i64* %11 to i8*
%22 = bitcast i8** %12 to i8*
%23 = load i32, i32* @False
%24 = load i32, i32* @AnyPropertyType
%25 = call i32 @XGetWindowProperty(i32* %0, i32 %1, i64 %2, i32 0, i32 0, i32 %23, i32 %24, i64* %8, i32* %9, i64* %10, i64* %11, i8** %12)
%26 = load i64, i64* %8
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %45
28: ; preds = %3
%29 = call i32 @XQueryTree(i32* %0, i32 %1, i32* %4, i32* %5, i32** %6, i32* %7)
%30 = icmp eq i32 %29, 0
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 0
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %45, label %34
34: ; preds = %28, %38
%35 = phi i32 [ %36, %38 ], [ %31, %28 ]
%36 = add i32 %35, -1
%37 = icmp sgt i32 %36, -1
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = load i32*, i32** %6
%40 = zext i32 %36 to i64
%41 = getelementptr inbounds i32, i32* %39, i64 %40
%42 = load i32, i32* %41
%43 = call i32 @GetAtomWindow(i32* %0, i32 %42, i64 %2)
%44 = icmp eq i32 %43, 0
br i1 %44, label %34, label %45
45: ; preds = %34, %38, %28, %3
%46 = phi i32 [ %1, %3 ], [ 0, %28 ], [ 0, %34 ], [ %43, %38 ]
ret i32 %46
}