#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;

/* Variables and functions */
int /*<<< orphan*/ XFree(int /*<<< orphan*/ *);
scalar_t__ XQueryTree(int /*<<< orphan*/ *, int /*<<< orphan*/,
                      int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                      int /*<<< orphan*/ **, unsigned int *);
Window Parent(Display *display, Window window) {
  Window root;
  Window parent;
  Window *children;
  unsigned int num;
  if (XQueryTree(display, window, &root, &parent, &children, &num) == 0)
    return 0;
  if (num && children)
    XFree(children);
  return parent;
}


x86 assembly (clang, -O0):
<Parent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x28(%rbp),%r8
lea    -0x2c(%rbp),%r9
call   1030 <XQueryTree@plt>
cmp    $0x0,%rax
jne    1161 <Parent+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1185 <Parent+0x65>
cmpl   $0x0,-0x2c(%rbp)
je     117f <Parent+0x5f>
cmpq   $0x0,-0x28(%rbp)
je     117f <Parent+0x5f>
mov    -0x28(%rbp),%rdi
call   1040 <XFree@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Parent>:
sub    $0x18,%rsp
lea    0x14(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rsp,%r9
call   1030 <XQueryTree@plt>
test   %rax,%rax
je     115e <Parent+0x3e>
cmpl   $0x0,(%rsp)
je     1155 <Parent+0x35>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1155 <Parent+0x35>
call   1040 <XFree@plt>
mov    0x4(%rsp),%eax
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i32 @Parent(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%10 = load i32*, i32** %4
%11 = load i32, i32* %5
%12 = call i64 @XQueryTree(i32* %10, i32 %11, i32* %6, i32* %7, i32** %8, i32* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %26
15: ; preds = %2
%16 = load i32, i32* %9
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32*, i32** %8
%23 = call i32 @XFree(i32* %22)
br label %24
24: ; preds = %21, %18, %15
%25 = load i32, i32* %7
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %14
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @Parent(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32** %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i64 @XQueryTree(i32* %0, i32 %1, i32* %3, i32* %4, i32** %5, i32* %6)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @XFree(i32* %16)
br label %21
21: ; preds = %19, %13
%22 = load i32, i32* %4
br label %23
23: ; preds = %2, %21
%24 = phi i32 [ %22, %21 ], [ 0, %2 ]
ret i32 %24
}