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

/* Variables and functions */
int /*<<< orphan*/ *DisplayOfScreen(int /*<<< orphan*/ *);
int /*<<< orphan*/ False;
int /*<<< orphan*/ None;
int /*<<< orphan*/ RootWindowOfScreen(int /*<<< orphan*/ *);
scalar_t__ Success;
int /*<<< orphan*/ XA_WINDOW;
int /*<<< orphan*/ XFree(char *);
scalar_t__ XGetWindowProperty(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              int /*<<< orphan*/, int /*<<< orphan*/, int,
                              int /*<<< orphan*/, int /*<<< orphan*/,
                              int /*<<< orphan*/ *, int *, unsigned long *,
                              unsigned long *, unsigned char **);
int /*<<< orphan*/ XInternAtom(int /*<<< orphan*/ *, char *,
                               int /*<<< orphan*/);
scalar_t__ XQueryTree(int /*<<< orphan*/ *, int /*<<< orphan*/,
                      int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ **, unsigned int *);
Window VirtualRootWindowOfScreen(Screen *screen) {
  static Screen *save_screen = (Screen *)0;
  static Window root = (Window)0;
  if (screen != save_screen) {
    Display *dpy = DisplayOfScreen(screen);
    Atom __SWM_VROOT = None;
    int i;
    Window rootReturn, parentReturn, *children;
    unsigned int numChildren;
    root = RootWindowOfScreen(screen);
    __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
    if (XQueryTree(dpy, root, &rootReturn, &parentReturn, &children,
                   &numChildren)) {
      for (i = 0; i < numChildren; i++) {
        Atom actual_type;
        int actual_format;
        unsigned long nitems, bytesafter;
        Window *newRoot = (Window *)0;
        if (XGetWindowProperty(dpy, children[i], __SWM_VROOT, 0, 1, False,
                               XA_WINDOW, &actual_type, &actual_format, &nitems,
                               &bytesafter,
                               (unsigned char **)&newRoot) == Success &&
            newRoot) {
          root = *newRoot;
          break;
        }
      }
      if (children)
        XFree((char *)children);
    }
    save_screen = screen;
  }
  return root;
}


x86 assembly (clang, -O0):
<VirtualRootWindowOfScreen>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    0x2ed9(%rip),%rax
je     12d4 <VirtualRootWindowOfScreen+0x174>
mov    -0x20(%rbp),%rdi
call   1050 <DisplayOfScreen@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <RootWindowOfScreen@plt>
mov    %eax,0x2eb3(%rip)
mov    -0x28(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
lea    0xe3f(%rip),%rsi
call   1060 <XInternAtom@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2e8d(%rip),%esi
lea    -0x34(%rbp),%rdx
lea    -0x38(%rbp),%rcx
lea    -0x40(%rbp),%r8
lea    -0x44(%rbp),%r9
call   1030 <XQueryTree@plt>
cmp    $0x0,%rax
je     12c9 <VirtualRootWindowOfScreen+0x169>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x44(%rbp),%eax
jae    12b0 <VirtualRootWindowOfScreen+0x150>
movq   $0x0,-0x68(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x2c(%rbp),%edx
mov    0x2dba(%rip),%rax
mov    (%rax),%r9d
mov    0x2d98(%rip),%rax
mov    (%rax),%r15d
lea    -0x68(%rbp),%rax
xor    %ecx,%ecx
mov    $0x1,%r8d
lea    -0x48(%rbp),%r14
lea    -0x4c(%rbp),%rbx
lea    -0x58(%rbp),%r11
lea    -0x60(%rbp),%r10
mov    %r15d,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1080 <XGetWindowProperty@plt>
mov    0x2d80(%rip),%rcx
cmp    (%rcx),%rax
jne    129d <VirtualRootWindowOfScreen+0x13d>
cmpq   $0x0,-0x68(%rbp)
je     129d <VirtualRootWindowOfScreen+0x13d>
mov    -0x68(%rbp),%rax
mov    (%rax),%eax
mov    %eax,0x2dc8(%rip)
jmp    12b0 <VirtualRootWindowOfScreen+0x150>
jmp    12a2 <VirtualRootWindowOfScreen+0x142>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11f9 <VirtualRootWindowOfScreen+0x99>
cmpq   $0x0,-0x40(%rbp)
je     12c4 <VirtualRootWindowOfScreen+0x164>
mov    -0x40(%rbp),%rdi
call   1040 <XFree@plt>
jmp    12c9 <VirtualRootWindowOfScreen+0x169>
mov    -0x20(%rbp),%rax
mov    %rax,0x2d84(%rip)
mov    0x2d86(%rip),%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<VirtualRootWindowOfScreen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    %rdi,0x2ee3(%rip)
je     1295 <VirtualRootWindowOfScreen+0x135>
mov    %rdi,%rbp
call   1050 <DisplayOfScreen@plt>
mov    %rax,%r15
mov    %rbp,%rdi
call   1070 <RootWindowOfScreen@plt>
mov    %eax,0x2ecc(%rip)
mov    0x2e45(%rip),%rax
mov    (%rax),%edx
lea    0xe5c(%rip),%rsi
mov    %r15,%rdi
call   1060 <XInternAtom@plt>
mov    %eax,%r12d
mov    0x2eab(%rip),%esi
lea    0x34(%rsp),%rdx
lea    0x30(%rsp),%rcx
lea    0x18(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %r15,%rdi
call   1030 <XQueryTree@plt>
test   %rax,%rax
je     128e <VirtualRootWindowOfScreen+0x12e>
mov    %rbp,0x20(%rsp)
cmpl   $0x0,0xc(%rsp)
je     127a <VirtualRootWindowOfScreen+0x11a>
xor    %ebp,%ebp
lea    0x2c(%rsp),%r13
mov    0x2e00(%rip),%r14
jmp    120d <VirtualRootWindowOfScreen+0xad>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    0xc(%rsp),%eax
cmp    %rax,%rbp
jae    127a <VirtualRootWindowOfScreen+0x11a>
movq   $0x0,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    (%rax,%rbp,4),%esi
mov    0x2dbb(%rip),%rax
mov    (%rax),%r9d
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
mov    %r15,%rdi
mov    %r12d,%edx
xor    %ecx,%ecx
mov    $0x1,%r8d
lea    0x10(%rsp),%rbx
push   %rbx
lea    0x40(%rsp),%rbx
push   %rbx
lea    0x50(%rsp),%rbx
push   %rbx
lea    0x40(%rsp),%rbx
push   %rbx
push   %r13
push   %rax
call   1080 <XGetWindowProperty@plt>
add    $0x30,%rsp
cmp    (%r14),%rax
jne    1200 <VirtualRootWindowOfScreen+0xa0>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     1200 <VirtualRootWindowOfScreen+0xa0>
mov    (%rax),%eax
mov    %eax,0x2de6(%rip)
mov    0x18(%rsp),%rdi
test   %rdi,%rdi
mov    0x20(%rsp),%rbp
je     128e <VirtualRootWindowOfScreen+0x12e>
call   1040 <XFree@plt>
mov    %rbp,0x2dc3(%rip)
mov    0x2dc5(%rip),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@VirtualRootWindowOfScreen.save_screen = internal global i32* null
@VirtualRootWindowOfScreen.root = internal global i32 0
@None = global i32 0
@.str = [12 x i8] c"__SWM_VROOT\00"
@False = global i32 0
@XA_WINDOW = global i32 0
@Success = global i64 0
define i32 @VirtualRootWindowOfScreen(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca i32*
store i32* %0, i32** %2
%15 = load i32*, i32** %2
%16 = load i32*, i32** @VirtualRootWindowOfScreen.save_screen
%17 = icmp ne i32* %15, %16
br i1 %17, label %18, label %70
18: ; preds = %1
%19 = load i32*, i32** %2
%20 = call i32* @DisplayOfScreen(i32* %19)
store i32* %20, i32** %3
%21 = load i32, i32* @None
store i32 %21, i32* %4
%22 = load i32*, i32** %2
%23 = call i32 @RootWindowOfScreen(i32* %22)
store i32 %23, i32* @VirtualRootWindowOfScreen.root
%24 = load i32*, i32** %3
%25 = load i32, i32* @False
%26 = call i32 @XInternAtom(i32* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 %26, i32* %4
%27 = load i32*, i32** %3
%28 = load i32, i32* @VirtualRootWindowOfScreen.root
%29 = call i64 @XQueryTree(i32* %27, i32 %28, i32* %6, i32* %7, i32** %8, i32* %9)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %68
31: ; preds = %18
store i32 0, i32* %5
br label %32
32: ; preds = %57, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %9
%35 = icmp ult i32 %33, %34
br i1 %35, label %36, label %60
36: ; preds = %32
store i32* null, i32** %14
%37 = load i32*, i32** %3
%38 = load i32*, i32** %8
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %4
%44 = load i32, i32* @False
%45 = load i32, i32* @XA_WINDOW
%46 = bitcast i32** %14 to i8**
%47 = call i64 @XGetWindowProperty(i32* %37, i32 %42, i32 %43, i32 0, i32 1, i32 %44, i32 %45, i32* %10, i32* %11, i64* %12, i64* %13, i8** %46)
%48 = load i64, i64* @Success
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %56
50: ; preds = %36
%51 = load i32*, i32** %14
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32*, i32** %14
%55 = load i32, i32* %54
store i32 %55, i32* @VirtualRootWindowOfScreen.root
br label %60
56: ; preds = %50, %36
br label %57
57: ; preds = %56
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %32
60: ; preds = %53, %32
%61 = load i32*, i32** %8
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = load i32*, i32** %8
%65 = bitcast i32* %64 to i8*
%66 = call i32 @XFree(i8* %65)
br label %67
67: ; preds = %63, %60
br label %68
68: ; preds = %67, %18
%69 = load i32*, i32** %2
store i32* %69, i32** @VirtualRootWindowOfScreen.save_screen
br label %70
70: ; preds = %68, %1
%71 = load i32, i32* @VirtualRootWindowOfScreen.root
ret i32 %71
}

LLVM IR (-O2):
@VirtualRootWindowOfScreen.save_screen = internal unnamed_addr global i32* null
@VirtualRootWindowOfScreen.root = internal unnamed_addr global i32 0
@None = global i32 0
@.str = [12 x i8] c"__SWM_VROOT\00"
@False = global i32 0
@XA_WINDOW = global i32 0
@Success = global i64 0
define i32 @VirtualRootWindowOfScreen(i32* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32*
%11 = load i32*, i32** @VirtualRootWindowOfScreen.save_screen
%12 = icmp eq i32* %11, %0
br i1 %12, label %62, label %13
13: ; preds = %1
%14 = tail call i32* @DisplayOfScreen(i32* %0)
%15 = bitcast i32* %2 to i8*
%16 = bitcast i32* %3 to i8*
%17 = bitcast i32** %4 to i8*
%18 = bitcast i32* %5 to i8*
%19 = tail call i32 @RootWindowOfScreen(i32* %0)
store i32 %19, i32* @VirtualRootWindowOfScreen.root
%20 = load i32, i32* @False
%21 = tail call i32 @XInternAtom(i32* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @VirtualRootWindowOfScreen.root
%23 = call i64 @XQueryTree(i32* %14, i32 %22, i32* %2, i32* %3, i32** %4, i32* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %61, label %25
25: ; preds = %13
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %55, label %28
28: ; preds = %25
%29 = bitcast i32* %6 to i8*
%30 = bitcast i32* %7 to i8*
%31 = bitcast i64* %8 to i8*
%32 = bitcast i64* %9 to i8*
%33 = bitcast i32** %10 to i8*
%34 = bitcast i32** %10 to i8**
br label %35
35: ; preds = %28, %50
%36 = phi i64 [ 0, %28 ], [ %51, %50 ]
store i32* null, i32** %10
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 %36
%39 = load i32, i32* %38
%40 = load i32, i32* @False
%41 = load i32, i32* @XA_WINDOW
%42 = call i64 @XGetWindowProperty(i32* %14, i32 %39, i32 %21, i32 0, i32 1, i32 %40, i32 %41, i32* %6, i32* %7, i64* %8, i64* %9, i8** %34)
%43 = load i64, i64* @Success
%44 = icmp eq i64 %42, %43
%45 = load i32*, i32** %10
%46 = icmp ne i32* %45, null
%47 = select i1 %44, i1 %46, i1 false
br i1 %47, label %48, label %50
48: ; preds = %35
%49 = load i32, i32* %45
store i32 %49, i32* @VirtualRootWindowOfScreen.root
br label %55
50: ; preds = %35
%51 = add nuw nsw i64 %36, 1
%52 = load i32, i32* %5
%53 = zext i32 %52 to i64
%54 = icmp ult i64 %51, %53
br i1 %54, label %35, label %55
55: ; preds = %50, %25, %48
%56 = load i32*, i32** %4
%57 = icmp eq i32* %56, null
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = bitcast i32* %56 to i8*
%60 = call i32 @XFree(i8* %59)
br label %61
61: ; preds = %55, %58, %13
store i32* %0, i32** @VirtualRootWindowOfScreen.save_screen
br label %62
62: ; preds = %61, %1
%63 = load i32, i32* @VirtualRootWindowOfScreen.root
ret i32 %63
}