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

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


x86 assembly (clang, -O0):
<TryChildren>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
mov    %rdx,-0x38(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x88(%rbp)
mov    -0x28(%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    11a8 <TryChildren+0x68>
movq   $0x0,-0x20(%rbp)
jmp    1305 <TryChildren+0x1c5>
movl   $0x0,-0x58(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0x89(%rbp)
jne    11d4 <TryChildren+0x94>
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
setb   %al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    11e7 <TryChildren+0xa7>
jmp    127a <TryChildren+0x13a>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
mov    -0x38(%rbp),%rdx
mov    0x2ddf(%rip),%rax
mov    (%rax),%r9d
mov    0x2de5(%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>
cmpq   $0x0,-0x60(%rbp)
je     1267 <TryChildren+0x127>
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x88(%rbp)
jmp    126c <TryChildren+0x12c>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    11af <TryChildren+0x6f>
movl   $0x0,-0x58(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x88(%rbp)
mov    %al,-0x8a(%rbp)
jne    12a6 <TryChildren+0x166>
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
setb   %al
mov    %al,-0x8a(%rbp)
mov    -0x8a(%rbp),%al
test   $0x1,%al
jne    12b9 <TryChildren+0x179>
jmp    12e6 <TryChildren+0x1a6>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%ecx
mov    (%rax,%rcx,8),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <TryChildren@plt>
mov    %rax,-0x88(%rbp)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1281 <TryChildren+0x141>
cmpq   $0x0,-0x50(%rbp)
je     12fa <TryChildren+0x1ba>
mov    -0x50(%rbp),%rdi
call   1040 <XFree@plt>
mov    -0x88(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<TryChildren>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
mov    %rdi,%r15
mov    0x2e7d(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
lea    0x40(%rsp),%rdx
lea    0x38(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
call   1030 <XQueryTree@plt>
test   %eax,%eax
je     125f <TryChildren+0x11f>
cmpl   $0x0,0x4(%rsp)
je     1264 <TryChildren+0x124>
mov    $0x1,%ebx
lea    0x10(%rsp),%r12
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
mov    -0x8(%rax,%rbx,8),%rsi
mov    0x2e2f(%rip),%rax
mov    (%rax),%r9d
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %r15,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
lea    0x20(%rsp),%rbp
push   %rbp
lea    0x30(%rsp),%rbp
push   %rbp
lea    0x40(%rsp),%rbp
push   %rbp
lea    0x34(%rsp),%rbp
push   %rbp
push   %r12
push   %rax
call   1060 <XGetWindowProperty@plt>
add    $0x30,%rsp
cmpq   $0x0,0x10(%rsp)
je     1200 <TryChildren+0xc0>
mov    0x8(%rsp),%rax
mov    -0x8(%rax,%rbx,8),%r13
jmp    1203 <TryChildren+0xc3>
xor    %r13d,%r13d
mov    0x4(%rsp),%eax
test   %r13,%r13
jne    1218 <TryChildren+0xd8>
lea    0x1(%rbx),%rcx
cmp    %rax,%rbx
mov    %rcx,%rbx
jb     11a0 <TryChildren+0x60>
test   %r13,%r13
jne    1267 <TryChildren+0x127>
test   %eax,%eax
je     1267 <TryChildren+0x127>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    -0x8(%rax,%rbx,8),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1050 <TryChildren@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1267 <TryChildren+0x127>
lea    0x1(%rbx),%rax
mov    0x4(%rsp),%ecx
cmp    %rcx,%rbx
mov    %rax,%rbx
jb     1230 <TryChildren+0xf0>
jmp    1267 <TryChildren+0x127>
xor    %r13d,%r13d
jmp    1276 <TryChildren+0x136>
xor    %r13d,%r13d
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1276 <TryChildren+0x136>
call   1040 <XFree@plt>
mov    %r13,%rax
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 i64 @TryChildren(i32* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca i64
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%19 = load i64, i64* @None
store i64 %19, i64* %13
store i64 0, i64* %18
%20 = load i32*, i32** %5
%21 = load i64, i64* %6
%22 = call i32 @XQueryTree(i32* %20, i64 %21, i64* %8, i64* %9, i64** %10, i32* %11)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %3
store i64 0, i64* %4
br label %89
25: ; preds = %3
store i32 0, i32* %12
br label %26
26: ; preds = %55, %25
%27 = load i64, i64* %18
%28 = icmp ne i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %12
%31 = load i32, i32* %11
%32 = icmp ult i32 %30, %31
br label %33
33: ; preds = %29, %26
%34 = phi i1 [ false, %26 ], [ %32, %29 ]
br i1 %34, label %35, label %58
35: ; preds = %33
%36 = load i32*, i32** %5
%37 = load i64*, i64** %10
%38 = load i32, i32* %12
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i64, i64* %37, i64 %39
%41 = load i64, i64* %40
%42 = load i64, i64* %7
%43 = load i32, i32* @False
%44 = load i32, i32* @AnyPropertyType
%45 = call i32 @XGetWindowProperty(i32* %36, i64 %41, i64 %42, i32 0, i32 0, i32 %43, i32 %44, i64* %13, i32* %14, i64* %15, i64* %16, i8** %17)
%46 = load i64, i64* %13
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %54
48: ; preds = %35
%49 = load i64*, i64** %10
%50 = load i32, i32* %12
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i64, i64* %49, i64 %51
%53 = load i64, i64* %52
store i64 %53, i64* %18
br label %54
54: ; preds = %48, %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %12
%57 = add i32 %56, 1
store i32 %57, i32* %12
br label %26
58: ; preds = %33
store i32 0, i32* %12
br label %59
59: ; preds = %77, %58
%60 = load i64, i64* %18
%61 = icmp ne i64 %60, 0
br i1 %61, label %66, label %62
62: ; preds = %59
%63 = load i32, i32* %12
%64 = load i32, i32* %11
%65 = icmp ult i32 %63, %64
br label %66
66: ; preds = %62, %59
%67 = phi i1 [ false, %59 ], [ %65, %62 ]
br i1 %67, label %68, label %80
68: ; preds = %66
%69 = load i32*, i32** %5
%70 = load i64*, i64** %10
%71 = load i32, i32* %12
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds i64, i64* %70, i64 %72
%74 = load i64, i64* %73
%75 = load i64, i64* %7
%76 = call i64 @TryChildren(i32* %69, i64 %74, i64 %75)
store i64 %76, i64* %18
br label %77
77: ; preds = %68
%78 = load i32, i32* %12
%79 = add i32 %78, 1
store i32 %79, i32* %12
br label %59
80: ; preds = %66
%81 = load i64*, i64** %10
%82 = icmp ne i64* %81, null
br i1 %82, label %83, label %87
83: ; preds = %80
%84 = load i64*, i64** %10
%85 = bitcast i64* %84 to i8*
%86 = call i32 @XFree(i8* %85)
br label %87
87: ; preds = %83, %80
%88 = load i64, i64* %18
store i64 %88, i64* %4
br label %89
89: ; preds = %87, %24
%90 = load i64, i64* %4
ret i64 %90
}

LLVM IR (-O2):
@None = global i64 0
@False = global i32 0
@AnyPropertyType = global i32 0
define i64 @TryChildren(i32* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = bitcast i64* %4 to i8*
%14 = bitcast i64* %5 to i8*
%15 = bitcast i64** %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 = call i32 @XQueryTree(i32* %0, i64 %1, i64* %4, i64* %5, i64** %6, i32* %7)
%24 = icmp eq i32 %23, 0
br i1 %24, label %73, label %25
25: ; preds = %3
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 0
br i1 %27, label %66, label %32
28: ; preds = %46
%29 = icmp ne i32 %50, 0
%30 = icmp eq i64 %47, 0
%31 = select i1 %30, i1 %29, i1 false
br i1 %31, label %54, label %66
32: ; preds = %25, %46
%33 = phi i64 [ %48, %46 ], [ 0, %25 ]
%34 = load i64*, i64** %6
%35 = getelementptr inbounds i64, i64* %34, i64 %33
%36 = load i64, i64* %35
%37 = load i32, i32* @False
%38 = load i32, i32* @AnyPropertyType
%39 = call i32 @XGetWindowProperty(i32* %0, i64 %36, i64 %2, i32 0, i32 0, i32 %37, i32 %38, i64* %8, i32* %9, i64* %10, i64* %11, i8** %12)
%40 = load i64, i64* %8
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %32
%43 = load i64*, i64** %6
%44 = getelementptr inbounds i64, i64* %43, i64 %33
%45 = load i64, i64* %44
br label %46
46: ; preds = %32, %42
%47 = phi i64 [ %45, %42 ], [ 0, %32 ]
%48 = add nuw nsw i64 %33, 1
%49 = icmp eq i64 %47, 0
%50 = load i32, i32* %7
%51 = zext i32 %50 to i64
%52 = icmp ult i64 %48, %51
%53 = select i1 %49, i1 %52, i1 false
br i1 %53, label %32, label %28
54: ; preds = %28, %54
%55 = phi i64 [ %60, %54 ], [ 0, %28 ]
%56 = load i64*, i64** %6
%57 = getelementptr inbounds i64, i64* %56, i64 %55
%58 = load i64, i64* %57
%59 = call i64 @TryChildren(i32* %0, i64 %58, i64 %2)
%60 = add nuw nsw i64 %55, 1
%61 = icmp eq i64 %59, 0
%62 = load i32, i32* %7
%63 = zext i32 %62 to i64
%64 = icmp ult i64 %60, %63
%65 = select i1 %61, i1 %64, i1 false
br i1 %65, label %54, label %66
66: ; preds = %54, %25, %28
%67 = phi i64 [ %47, %28 ], [ 0, %25 ], [ %59, %54 ]
%68 = load i64*, i64** %6
%69 = icmp eq i64* %68, null
br i1 %69, label %73, label %70
70: ; preds = %66
%71 = bitcast i64* %68 to i8*
%72 = call i32 @XFree(i8* %71)
br label %73
73: ; preds = %66, %70, %3
%74 = phi i64 [ 0, %3 ], [ %67, %70 ], [ %67, %66 ]
ret i64 %74
}