// File: /workspace/github_c_makefile_star2_O1/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 0x2c7c(%rip), %rbx      # 0x4108
movq 0x2c7d(%rip), %rax      # 0x4110
movl (%rax), %esi
movq %rbx, %rdi
callq 0x10b0
movq %rbx, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x1100
testq %rax, %rax
je 0x1628
movq %rax, %rbx
movq %rax, %rdi
callq 0x1130
movl %eax, %ebp
movq %rbx, %rdi
callq 0x10e0
testl %ebp, %ebp
jle 0x1620
movq %rax, %r14
movl %ebp, %r13d
movq 0x2c2c(%rip), %r15      # 0x4108
movl (%r14), %esi
movq %r15, %rdi
callq 0x1140
movq %r15, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x10c0
testq %rax, %rax
je 0x15e7
movq %rax, %r15
cmpb $0x0, 0x1b(%rax)
je 0x151b
movq %r15, %rdi
callq 0x1030
addq $0x4, %r14
decq %r13
jne 0x14d5
jmp 0x1620
movl (%r14), %ebp
movq 0x2be3(%rip), %rdi      # 0x4108
movl 0x2bd9(%rip), %ecx      # 0x4104
movl $0x4, (%rsp)
xorl %esi, %esi
movl %ebp, %edx
movl %ecx, %r8d
xorl %r9d, %r9d
callq 0x1040
movq 0x2bc0(%rip), %rdi      # 0x4108
movl %eax, %esi
xorl %edx, %edx
callq 0x1170
testq %rax, %rax
je 0x1601
movq %rax, %r12
movq %rax, %rdi
callq 0x1150
testl %eax, %eax
je 0x15da
movq %r12, %rdi
callq 0x1060
movl (%rax), %ebp
movq %r12, %rdi
callq 0x1030
cmpl $0x3, %ebp
jne 0x1505
movq 0x2b81(%rip), %rdi      # 0x4108
movl (%r14), %esi
callq 0x1080
movq 0x2b72(%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, 0x2b40(%rip)      # 0x4100
jne 0x15f4
movl (%r14), %ecx
leaq 0xaa6(%rip), %rdi       # 0x2072
movl %ecx, %edx
xorl %eax, %eax
callq 0x10a0
jmp 0x1505
movq %r12, %rdi
callq 0x1030
jmp 0x1505
movq %r14, %rdi
callq 0x1236
jmp 0x150d
movq %rsi, %rdi
callq 0x1050
jmp 0x1505
movq 0x29f0(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xa90(%rip), %rsi       # 0x20a2
movl %ebp, %edx
xorl %eax, %eax
callq 0x1120
jmp 0x1505
movq %rbx, %rdi
callq 0x1030
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq