#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ width;
  scalar_t__ height;
};
typedef TYPE_1__ XWindowAttributes;
typedef int /*<<< orphan*/ Window;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
scalar_t__ DisplayHeight(int /*<<< orphan*/ *, int);
scalar_t__ DisplayWidth(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ XFree(char *);
scalar_t__ XGetWindowAttributes(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                TYPE_1__ *);
scalar_t__ XQueryTree(int /*<<< orphan*/ *, int /*<<< orphan*/,
                      int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ **, unsigned int *);
Window __ToonGetNautilusDesktop(Display *display, int screen, Window window,
                                int depth) {
  Window rootReturn, parentReturn, *children;
  Window winreturn = window;
  unsigned int nChildren;
  if (depth > 5) {
    return ((Window)0);
  } else if (XQueryTree(display, window, &rootReturn, &parentReturn, &children,
                        &nChildren)) {
    int i;
    for (i = 0; i < nChildren; ++i) {
      XWindowAttributes attributes;
      if (XGetWindowAttributes(display, children[i], &attributes)) {
        if (attributes.width == DisplayWidth(display, screen) &&
            attributes.height == DisplayHeight(display, screen)) {
          winreturn =
              __ToonGetNautilusDesktop(display, screen, children[i], depth + 1);
        }
      }
    }
    XFree((char *)children);
  }
  return winreturn;
}


x86 assembly (clang, -O0):
<__ToonGetNautilusDesktop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jle    1191 <__ToonGetNautilusDesktop+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1280 <__ToonGetNautilusDesktop+0x120>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    -0x20(%rbp),%rdx
lea    -0x24(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x38(%rbp),%r9
call   1060 <XQueryTree@plt>
cmp    $0x0,%rax
je     1275 <__ToonGetNautilusDesktop+0x115>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jae    126c <__ToonGetNautilusDesktop+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    -0x50(%rbp),%rdx
call   1080 <XGetWindowAttributes@plt>
cmp    $0x0,%rax
je     1259 <__ToonGetNautilusDesktop+0xf9>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <DisplayWidth@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
cmp    %rcx,%rax
jne    1254 <__ToonGetNautilusDesktop+0xf4>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <DisplayHeight@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
cmp    %rcx,%rax
jne    1254 <__ToonGetNautilusDesktop+0xf4>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
call   1030 <__ToonGetNautilusDesktop@plt>
mov    %eax,-0x34(%rbp)
jmp    1259 <__ToonGetNautilusDesktop+0xf9>
jmp    125e <__ToonGetNautilusDesktop+0xfe>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11be <__ToonGetNautilusDesktop+0x5e>
mov    -0x30(%rbp),%rdi
call   1070 <XFree@plt>
jmp    127a <__ToonGetNautilusDesktop+0x11a>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ToonGetNautilusDesktop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
cmp    $0x5,%ecx
jg     124e <__ToonGetNautilusDesktop+0xee>
mov    %ecx,%ebp
mov    %edx,%ebx
mov    %esi,%r13d
mov    %rdi,%r15
lea    0x24(%rsp),%rdx
lea    0x20(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%esi
call   1060 <XQueryTree@plt>
test   %rax,%rax
je     124c <__ToonGetNautilusDesktop+0xec>
mov    %ebx,0x8(%rsp)
cmpl   $0x0,0xc(%rsp)
je     123c <__ToonGetNautilusDesktop+0xdc>
add    $0x1,%ebp
mov    %ebp,0x1c(%rsp)
xor    %ebx,%ebx
lea    0x28(%rsp),%r12
jmp    11dd <__ToonGetNautilusDesktop+0x7d>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    0xc(%rsp),%eax
cmp    %rax,%rbx
jae    123c <__ToonGetNautilusDesktop+0xdc>
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %r15,%rdi
mov    %r12,%rdx
call   1080 <XGetWindowAttributes@plt>
test   %rax,%rax
je     11d0 <__ToonGetNautilusDesktop+0x70>
mov    0x28(%rsp),%r14
mov    %r15,%rdi
mov    %r13d,%esi
call   1050 <DisplayWidth@plt>
cmp    %rax,%r14
jne    11d0 <__ToonGetNautilusDesktop+0x70>
mov    0x30(%rsp),%rbp
mov    %r15,%rdi
mov    %r13d,%esi
call   1040 <DisplayHeight@plt>
cmp    %rax,%rbp
jne    11d0 <__ToonGetNautilusDesktop+0x70>
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,4),%edx
mov    %r15,%rdi
mov    %r13d,%esi
mov    0x1c(%rsp),%ecx
call   1030 <__ToonGetNautilusDesktop@plt>
mov    %eax,0x8(%rsp)
jmp    11d0 <__ToonGetNautilusDesktop+0x70>
mov    0x10(%rsp),%rdi
call   1070 <XFree@plt>
mov    0x8(%rsp),%eax
jmp    124e <__ToonGetNautilusDesktop+0xee>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
define i32 @__ToonGetNautilusDesktop(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.TYPE_3__
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%17 = load i32, i32* %8
store i32 %17, i32* %13
%18 = load i32, i32* %9
%19 = icmp sgt i32 %18, 5
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 0, i32* %5
br label %77
21: ; preds = %4
%22 = load i32*, i32** %6
%23 = load i32, i32* %8
%24 = call i64 @XQueryTree(i32* %22, i32 %23, i32* %10, i32* %11, i32** %12, i32* %14)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %74
26: ; preds = %21
store i32 0, i32* %15
br label %27
27: ; preds = %67, %26
%28 = load i32, i32* %15
%29 = load i32, i32* %14
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %70
31: ; preds = %27
%32 = load i32*, i32** %6
%33 = load i32*, i32** %12
%34 = load i32, i32* %15
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i64 @XGetWindowAttributes(i32* %32, i32 %37, %struct.TYPE_3__* %16)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %66
40: ; preds = %31
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%42 = load i64, i64* %41
%43 = load i32*, i32** %6
%44 = load i32, i32* %7
%45 = call i64 @DisplayWidth(i32* %43, i32 %44)
%46 = icmp eq i64 %42, %45
br i1 %46, label %47, label %65
47: ; preds = %40
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
%49 = load i64, i64* %48
%50 = load i32*, i32** %6
%51 = load i32, i32* %7
%52 = call i64 @DisplayHeight(i32* %50, i32 %51)
%53 = icmp eq i64 %49, %52
br i1 %53, label %54, label %65
54: ; preds = %47
%55 = load i32*, i32** %6
%56 = load i32, i32* %7
%57 = load i32*, i32** %12
%58 = load i32, i32* %15
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %57, i64 %59
%61 = load i32, i32* %60
%62 = load i32, i32* %9
%63 = add nsw i32 %62, 1
%64 = call i32 @__ToonGetNautilusDesktop(i32* %55, i32 %56, i32 %61, i32 %63)
store i32 %64, i32* %13
br label %65
65: ; preds = %54, %47, %40
br label %66
66: ; preds = %65, %31
br label %67
67: ; preds = %66
%68 = load i32, i32* %15
%69 = add nsw i32 %68, 1
store i32 %69, i32* %15
br label %27
70: ; preds = %27
%71 = load i32*, i32** %12
%72 = bitcast i32* %71 to i8*
%73 = call i32 @XFree(i8* %72)
br label %74
74: ; preds = %70, %21
br label %75
75: ; preds = %74
%76 = load i32, i32* %13
store i32 %76, i32* %5
br label %77
77: ; preds = %75, %20
%78 = load i32, i32* %5
ret i32 %78
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
define i32 @__ToonGetNautilusDesktop(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.TYPE_3__
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32** %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = icmp sgt i32 %3, 5
br i1 %14, label %58, label %15
15: ; preds = %4
%16 = call i64 @XQueryTree(i32* %0, i32 %2, i32* %5, i32* %6, i32** %7, i32* %8)
%17 = icmp eq i64 %16, 0
br i1 %17, label %58, label %18
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %53, label %21
21: ; preds = %18
%22 = bitcast %struct.TYPE_3__* %9 to i8*
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i64 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i64 0, i32 1
%25 = add nsw i32 %3, 1
br label %26
26: ; preds = %21, %47
%27 = phi i64 [ 0, %21 ], [ %49, %47 ]
%28 = phi i32 [ %2, %21 ], [ %48, %47 ]
%29 = load i32*, i32** %7
%30 = getelementptr inbounds i32, i32* %29, i64 %27
%31 = load i32, i32* %30
%32 = call i64 @XGetWindowAttributes(i32* %0, i32 %31, %struct.TYPE_3__* %9)
%33 = icmp eq i64 %32, 0
br i1 %33, label %47, label %34
34: ; preds = %26
%35 = load i64, i64* %23
%36 = call i64 @DisplayWidth(i32* %0, i32 %1)
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %34
%39 = load i64, i64* %24
%40 = call i64 @DisplayHeight(i32* %0, i32 %1)
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %47
42: ; preds = %38
%43 = load i32*, i32** %7
%44 = getelementptr inbounds i32, i32* %43, i64 %27
%45 = load i32, i32* %44
%46 = call i32 @__ToonGetNautilusDesktop(i32* %0, i32 %1, i32 %45, i32 %25)
br label %47
47: ; preds = %34, %38, %42, %26
%48 = phi i32 [ %46, %42 ], [ %28, %38 ], [ %28, %34 ], [ %28, %26 ]
%49 = add nuw nsw i64 %27, 1
%50 = load i32, i32* %8
%51 = zext i32 %50 to i64
%52 = icmp ult i64 %49, %51
br i1 %52, label %26, label %53
53: ; preds = %47, %18
%54 = phi i32 [ %2, %18 ], [ %48, %47 ]
%55 = bitcast i32** %7 to i8**
%56 = load i8*, i8** %55
%57 = call i32 @XFree(i8* %56)
br label %58
58: ; preds = %53, %15, %4
%59 = phi i32 [ 0, %4 ], [ %54, %53 ], [ %2, %15 ]
ret i32 %59
}