// File: /workspace/github_c_makefile_star2_O0/tkln[P]mcwm/hidden.c
// Function: findhidden
int findhidden(void)
{
    xcb_query_tree_reply_t *reply;
    int i;
    int len;
    xcb_window_t *children;
    xcb_get_window_attributes_reply_t *attr;
    uint32_t state;
    xcb_get_property_cookie_t cookie;
    xcb_icccm_get_text_property_reply_t prop;
    xcb_generic_error_t *error;
    
    /* Get all children. */
    reply = xcb_query_tree_reply(conn,
                                 xcb_query_tree(conn, screen->root), 0);
    if (NULL == reply)
    {
        return -1;
    }

    len = xcb_query_tree_children_length(reply);    
    children = xcb_query_tree_children(reply);
    
    /* List all hidden windows on this root. */
    for (i = 0; i < len; i ++)
    {
        attr = xcb_get_window_attributes_reply(
            conn, xcb_get_window_attributes(conn, children[i]), NULL);

        if (!attr)
        {
            fprintf(stderr, "Couldn't get attributes for window %d.",
                    children[i]);
            continue;
        }

        /*
         * Don't bother windows in override redirect mode.
         *
         * This mode means they wouldn't have been reported to us
         * with a MapRequest if we had been running, so in the
         * normal case we wouldn't have seen them.
         */
        if (!attr->override_redirect)
        {
            state = get_wm_state(children[i]);
            if (state == XCB_ICCCM_WM_STATE_ICONIC)
            {
                /*
                 * Example names:
                 * 
                 * _NET_WM_ICON_NAME(UTF8_STRING) = 0x75, 0x72, 0x78,
                 * 0x76, 0x74 WM_ICON_NAME(STRING) = "urxvt"
                 * _NET_WM_NAME(UTF8_STRING) = 0x75, 0x72, 0x78, 0x76,
                 * 0x74 WM_NAME(STRING) = "urxvt"
                 */
                cookie = xcb_icccm_get_wm_icon_name(conn, children[i]);
                xcb_icccm_get_wm_icon_name_reply(conn, cookie, &prop, &error);

                prop.name[prop.name_len] = '\0';
                if (printcommand)
                {
                    /* FIXME: Need to escape : in prop.name. */
                    printf("'%s':'xdotool windowmap 0x%x windowraise 0x%x'\n",
                           prop.name, children[i], children[i]);
                }
                else
                {
                    puts(prop.name);
                }
            }
        } /* if not override redirect */
        
        free(attr);
    } /* for */

    free(reply);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x2bf6(%rip), %rax      # 0x4108
movq %rax, -0x70(%rbp)
movq 0x2beb(%rip), %rdi      # 0x4108
movq 0x2bec(%rip), %rax      # 0x4110
movl (%rax), %esi
callq 0x10c0
movq -0x70(%rbp), %rdi
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x1110
movq %rax, -0x10(%rbp)
xorl %eax, %eax
cmpq -0x10(%rbp), %rax
jne 0x1556
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x16be
movq -0x10(%rbp), %rdi
callq 0x1140
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10f0
movq %rax, -0x20(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x16ae
movq 0x2b7f(%rip), %rax      # 0x4108
movq %rax, -0x78(%rbp)
movq 0x2b74(%rip), %rdi      # 0x4108
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x1150
movq -0x78(%rbp), %rdi
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x10d0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x15ea
movq 0x2a2f(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0xab6(%rip), %rsi       # 0x2094
movb $0x0, %al
callq 0x1130
jmp 0x16a0
movq -0x28(%rbp), %rax
cmpb $0x0, 0x1b(%rax)
jne 0x1697
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x16f0
movl %eax, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jne 0x1695
movq 0x2aec(%rip), %rdi      # 0x4108
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x1080
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x30(%rbp)
movq 0x2acc(%rip), %rdi      # 0x4108
movl -0x30(%rbp), %esi
leaq -0x50(%rbp), %rdx
leaq -0x58(%rbp), %rcx
callq 0x10a0
movq -0x40(%rbp), %rax
movl -0x44(%rbp), %ecx
movb $0x0, (%rax,%rcx)
testb $0x1, 0x2aa2(%rip)      # 0x4100
je 0x168a
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
leaq 0xa3a(%rip), %rdi       # 0x20bb
movb $0x0, %al
callq 0x10b0
jmp 0x1693
movq -0x40(%rbp), %rdi
callq 0x1050
jmp 0x1695
jmp 0x1697
movq -0x28(%rbp), %rdi
callq 0x1030
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1576
movq -0x10(%rbp), %rdi
callq 0x1030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)