#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*/ False;
scalar_t__ None;
scalar_t__ Success;
scalar_t__ XA_WINDOW;
int /*<<< orphan*/ XFree(unsigned char *);
scalar_t__ XGetWindowProperty(int /*<<< orphan*/ *, int /*<<< orphan*/,
                              scalar_t__, int /*<<< orphan*/, int,
                              int /*<<< orphan*/, scalar_t__, scalar_t__ *,
                              int *, unsigned long *, unsigned long *,
                              unsigned char **);
scalar_t__ XInternAtom(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
unsigned long *Find_Roots(Display *dpy, Window root, unsigned int *num) {
  Atom type_ret;
  int format_ret;
  unsigned char *prop_ret;
  unsigned long bytes_after, num_ret;
  Atom atom;
  *num = 0;
  atom = XInternAtom(dpy, "_NET_VIRTUAL_ROOTS", False);
  if (!atom)
    return NULL;
  type_ret = None;
  prop_ret = NULL;
  if (XGetWindowProperty(dpy, root, atom, 0, 0x7fffffff, False, XA_WINDOW,
                         &type_ret, &format_ret, &num_ret, &bytes_after,
                         &prop_ret) != Success)
    return NULL;
  if (prop_ret && type_ret == XA_WINDOW && format_ret == 32) {
    *num = num_ret;
    return ((unsigned long *)prop_ret);
  }
  if (prop_ret)
    XFree(prop_ret);
  return NULL;
}


x86 assembly (clang, -O0):
<Find_Roots>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rdi,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    %rdx,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
lea    0xe97(%rip),%rsi
call   1040 <XInternAtom@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    118a <Find_Roots+0x5a>
movq   $0x0,-0x20(%rbp)
jmp    1278 <Find_Roots+0x148>
mov    0x2e47(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x68(%rbp),%rdx
mov    0x2e2e(%rip),%rax
mov    (%rax),%r9d
mov    0x2e0c(%rip),%rax
mov    (%rax),%r15
xor    %ecx,%ecx
mov    $0x7fffffff,%r8d
lea    -0x40(%rbp),%r14
lea    -0x44(%rbp),%rbx
lea    -0x60(%rbp),%r11
lea    -0x58(%rbp),%r10
lea    -0x50(%rbp),%rax
mov    %r15,(%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>
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%rax
je     121a <Find_Roots+0xea>
movq   $0x0,-0x20(%rbp)
jmp    1278 <Find_Roots+0x148>
cmpq   $0x0,-0x50(%rbp)
je     125c <Find_Roots+0x12c>
mov    -0x40(%rbp),%rax
mov    0x2d98(%rip),%rcx
cmp    (%rcx),%rax
jne    125c <Find_Roots+0x12c>
cmpl   $0x20,-0x44(%rbp)
jne    125c <Find_Roots+0x12c>
mov    -0x60(%rbp),%rax
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1278 <Find_Roots+0x148>
cmpq   $0x0,-0x50(%rbp)
je     1270 <Find_Roots+0x140>
mov    -0x50(%rbp),%rdi
call   1030 <XFree@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<Find_Roots>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbp
movl   $0x0,(%rdx)
mov    0x2e8c(%rip),%rbx
mov    (%rbx),%edx
lea    0xea3(%rip),%rsi
call   1040 <XInternAtom@plt>
test   %rax,%rax
je     120a <Find_Roots+0xda>
mov    0x2e66(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    (%rbx),%r9d
mov    0x2e3b(%rip),%rcx
lea    0x8(%rsp),%r10
lea    0x20(%rsp),%r11
lea    0x18(%rsp),%r13
lea    0x4(%rsp),%r12
xor    %ebx,%ebx
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %rcx,%rbp
mov    %rax,%rdx
xor    %ecx,%ecx
mov    $0x7fffffff,%r8d
push   %r10
push   %r11
push   %r13
push   %r12
lea    0x30(%rsp),%rax
push   %rax
push   0x0(%rbp)
call   1050 <XGetWindowProperty@plt>
add    $0x30,%rsp
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
jne    120c <Find_Roots+0xdc>
mov    0x8(%rsp),%rbx
test   %rbx,%rbx
je     120a <Find_Roots+0xda>
mov    0x10(%rsp),%rax
cmp    0x0(%rbp),%rax
jne    1202 <Find_Roots+0xd2>
cmpl   $0x20,0x4(%rsp)
jne    1202 <Find_Roots+0xd2>
mov    0x18(%rsp),%eax
mov    %eax,(%r14)
jmp    120c <Find_Roots+0xdc>
mov    %rbx,%rdi
call   1030 <XFree@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [19 x i8] c"_NET_VIRTUAL_ROOTS\00"
@False = global i32 0
@None = global i64 0
@XA_WINDOW = global i64 0
@Success = global i64 0
define i64* @Find_Roots(i32* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = bitcast i64* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i8** %6 to i8*
%12 = bitcast i64* %7 to i8*
%13 = bitcast i64* %8 to i8*
store i32 0, i32* %2
%14 = load i32, i32* @False
%15 = tail call i64 @XInternAtom(i32* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %40, label %17
17: ; preds = %3
%18 = load i64, i64* @None
store i64 %18, i64* %4
store i8* null, i8** %6
%19 = load i32, i32* @False
%20 = load i64, i64* @XA_WINDOW
%21 = call i64 @XGetWindowProperty(i32* %0, i32 %1, i64 %15, i32 0, i32 2147483647, i32 %19, i64 %20, i64* %4, i32* %5, i64* %8, i64* %7, i8** %6)
%22 = load i64, i64* @Success
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = icmp eq i8* %25, null
%27 = bitcast i8* %25 to i64*
br i1 %26, label %40, label %28
28: ; preds = %24
%29 = load i64, i64* %4
%30 = load i64, i64* @XA_WINDOW
%31 = icmp eq i64 %29, %30
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, 32
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %38
35: ; preds = %28
%36 = load i64, i64* %8
%37 = trunc i64 %36 to i32
store i32 %37, i32* %2
br label %40
38: ; preds = %28
%39 = call i32 @XFree(i8* %25)
br label %40
40: ; preds = %24, %38, %17, %3, %35
%41 = phi i64* [ %27, %35 ], [ null, %3 ], [ null, %17 ], [ null, %38 ], [ null, %24 ]
ret i64* %41
}