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

/* Type definitions */
typedef int /*<<< orphan*/ xcb_window_t;
struct TYPE_5__ {
  int children_len;
};
typedef TYPE_1__ xcb_query_tree_reply_t;
typedef int /*<<< orphan*/ xcb_query_tree_cookie_t;
typedef int /*<<< orphan*/ xcb_connection_t;

/* Variables and functions */
int /*<<< orphan*/ errx(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(TYPE_1__ *);
int /*<<< orphan*/ xcb_query_tree(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *xcb_query_tree_children(TYPE_1__ *);
TYPE_1__ *xcb_query_tree_reply(int /*<<< orphan*/ *, int /*<<< orphan*/,
                               int /*<<< orphan*/ *);
int get_windows(xcb_connection_t *con, xcb_window_t w, xcb_window_t **l) {
  int childnum = 0;
  xcb_query_tree_cookie_t c;
  xcb_query_tree_reply_t *r;
  c = xcb_query_tree(con, w);
  r = xcb_query_tree_reply(con, c, NULL);
  if (r == NULL)
    errx(1, "0x%08x: no such window", w);
  *l = xcb_query_tree_children(r);
  childnum = r->children_len;
  free(r);
  return childnum;
}


x86 assembly (clang, -O0):
<get_windows>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <xcb_query_tree@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <xcb_query_tree_reply@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ac <get_windows+0x5c>
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
lea    0xe59(%rip),%rsi
call   1040 <errx@plt>
mov    -0x28(%rbp),%rdi
call   1060 <xcb_query_tree_children@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_windows>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <xcb_query_tree@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1070 <xcb_query_tree_reply@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1188 <get_windows+0x38>
lea    0xe84(%rip),%rsi
mov    $0x1,%edi
mov    %ebp,%edx
call   1040 <errx@plt>
mov    %rbx,%rdi
call   1060 <xcb_query_tree_children@plt>
mov    %rax,(%r14)
mov    (%rbx),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32 }
@.str = [23 x i8] c"0x%08x: no such window\00"
define i32 @get_windows(i32* %0, i32 %1, i32** %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.TYPE_5__*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32** %2, i32*** %6
store i32 0, i32* %7
%10 = load i32*, i32** %4
%11 = load i32, i32* %5
%12 = call i32 @xcb_query_tree(i32* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32*, i32** %4
%14 = load i32, i32* %8
%15 = call %struct.TYPE_5__* @xcb_query_tree_reply(i32* %13, i32 %14, i32* null)
store %struct.TYPE_5__* %15, %struct.TYPE_5__** %9
%16 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%17 = icmp eq %struct.TYPE_5__* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i32, i32* %5
%20 = call i32 @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %3
%22 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%23 = call i32* @xcb_query_tree_children(%struct.TYPE_5__* %22)
%24 = load i32**, i32*** %6
store i32* %23, i32** %24
%25 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %25, i32 0, i32 0
%27 = load i32, i32* %26
store i32 %27, i32* %7
%28 = load %struct.TYPE_5__*, %struct.TYPE_5__** %9
%29 = call i32 @free(%struct.TYPE_5__* %28)
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32 }
@.str = [23 x i8] c"0x%08x: no such window\00"
define i32 @get_windows(i32* %0, i32 %1, i32** nocapture writeonly %2) {
%4 = tail call i32 @xcb_query_tree(i32* %0, i32 %1)
%5 = tail call %struct.TYPE_5__* @xcb_query_tree_reply(i32* %0, i32 %4, i32* null)
%6 = icmp eq %struct.TYPE_5__* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %9
9: ; preds = %7, %3
%10 = tail call i32* @xcb_query_tree_children(%struct.TYPE_5__* %5)
store i32* %10, i32** %2
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @free(%struct.TYPE_5__* %5)
ret i32 %12
}