// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x2cbd(%rip), %rbx      # 0x4108
movq 0x2cbe(%rip), %rax      # 0x4110
movl (%rax), %esi
movq %rbx, %rdi
callq 0x10b0
xorl %r15d, %r15d
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1100
testq %rax, %rax
je 0x1608
movq %rax, %rbx
movq %rax, %rdi
callq 0x1130
movl %eax, %r14d
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
callq 0x10e0
testl %r14d, %r14d
cmovlel %r15d, %r14d
movq %rax, %r15
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x15fe
movq 0x2c5d(%rip), %r12      # 0x4108
movl (%r15,%rbx,4), %esi
movq %r12, %rdi
callq 0x1140
movq %r12, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
testq %rax, %rax
je 0x15b1
movq %rax, %r12
cmpb $0x0, 0x1b(%rax)
je 0x14e2
movq %r12, %rdi
callq 0x1030
incq %rbx
jmp 0x149b
movl (%r15,%rbx,4), %ebp
movq 0x2c1b(%rip), %rdi      # 0x4108
movl 0x2c11(%rip), %ecx      # 0x4104
movl $0x4, (%rsp)
xorl %esi, %esi
movl %ebp, %edx
movl %ecx, %r8d
xorl %r9d, %r9d
callq 0x1040
movq 0x2bf8(%rip), %rdi      # 0x4108
movl %eax, %esi
xorl %edx, %edx
callq 0x1170
testq %rax, %rax
je 0x15df
movq %rax, %r13
movq %rax, %rdi
callq 0x1150
testl %eax, %eax
je 0x15a4
movq %r13, %rdi
callq 0x1060
movl (%rax), %ebp
movq %r13, %rdi
callq 0x1030
cmpl $0x3, %ebp
jne 0x14d5
movq 0x2bb9(%rip), %rdi      # 0x4108
movl (%r15,%rbx,4), %esi
callq 0x1080
movq 0x2ba9(%rip), %rdi      # 0x4108
movl %eax, %esi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x1090
movq 0x28(%rsp), %rax
movl 0x24(%rsp), %ecx
movb $0x0, (%rax,%rcx)
movq 0x28(%rsp), %rsi
cmpb $0x1, 0x2b77(%rip)      # 0x4100
jne 0x15d2
movl (%r15,%rbx,4), %ecx
leaq 0xadc(%rip), %rdi       # 0x2072
movl %ecx, %edx
xorl %eax, %eax
callq 0x10a0
jmp 0x14d5
movq %r13, %rdi
callq 0x1030
jmp 0x14d5
movq 0x2a40(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl (%r15,%rbx,4), %edx
leaq 0xa85(%rip), %rsi       # 0x204b
xorl %eax, %eax
callq 0x1120
jmp 0x14dd
movq %rsi, %rdi
callq 0x1050
jmp 0x14d5
movq 0x2a12(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xab2(%rip), %rsi       # 0x20a2
movl %ebp, %edx
xorl %eax, %eax
callq 0x1120
jmp 0x14d5
movq 0x8(%rsp), %rdi
callq 0x1030
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq