// File: /workspace/github_c_makefile_star2_O2/tkln[P]mcwm/mcwm.c
// Function: setupwin
struct client *setupwin(xcb_window_t win)
{
    uint32_t mask = 0;    
    uint32_t values[2];
    struct item *item;
    struct client *client;
    xcb_size_hints_t hints;
    uint32_t ws;
    
    /* Set default border color. */
    values[0] = conf.unfocuscol;
    xcb_change_window_attributes(conn, win, XCB_CW_BORDER_PIXEL, values);

    /* Subscribe to events we want to know about in this window. */
    mask = XCB_CW_EVENT_MASK;
    values[0] = XCB_EVENT_MASK_ENTER_WINDOW;
    xcb_change_window_attributes_checked(conn, win, mask, values);

    /*
     * Add this window to the X Save Set, that is, the windows that
     * will be automatically restored if we die.
     */
    xcb_change_save_set(conn, XCB_SET_MODE_INSERT, win);

    xcb_flush(conn);
    
    /* Remember window and store a few things about it. */
    
    item = additem(&winlist);
    
    if (NULL == item)
    {
        PDEBUG("newwin: Out of memory.\n");
        return NULL;
    }

    client = malloc(sizeof (struct client));
    if (NULL == client)
    {
        PDEBUG("newwin: Out of memory.\n");
        return NULL;
    }

    item->data = client;
    
    /* Initialize client. */
    client->id = win;
    client->usercoord = false;
    client->x = 0;
    client->y = 0;
    client->width = 0;
    client->height = 0;
    client->min_width = 0;
    client->min_height = 0;
    client->max_width = screen->width_in_pixels;
    client->max_height = screen->height_in_pixels;
    client->base_width = 0;
    client->base_height = 0;
    client->width_inc = 1;
    client->height_inc = 1;
    client->vertmaxed = false;
    client->maxed = false;
    client->fixed = false;
    client->monitor = NULL;

    client->winitem = item;

    for (ws = 0; ws < WORKSPACES; ws ++)
    {
        client->wsitem[ws] = NULL;
    }
    
    PDEBUG("Adding window %d\n", client->id);

    setborders(client, conf.borderwidth);

    /* Get window geometry. */
    if (!getgeom(client->id, &client->x, &client->y, &client->width,
                 &client->height))
    {
        fprintf(stderr, "Couldn't get geometry in initial setup of window.\n");
    }
    
    /*
     * Get the window's incremental size step, if any.
     */
    if (!xcb_icccm_get_wm_normal_hints_reply(
            conn, xcb_icccm_get_wm_normal_hints_unchecked(
                conn, win), &hints, NULL))
    {
        PDEBUG("Couldn't get size hints.\n");
    }

    /*
     * The user specified the position coordinates. Remember that so
     * we can use geometry later.
     */
    if (hints.flags & XCB_ICCCM_SIZE_HINT_US_POSITION)
    {
        client->usercoord = true;
    }

    if (hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
    {
        client->min_width = hints.min_width;
        client->min_height = hints.min_height;
    }
    
    if (hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
    {
        
        client->max_width = hints.max_width;
        client->max_height = hints.max_height;
    }
    
    if (hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
    {
        client->width_inc = hints.width_inc;
        client->height_inc = hints.height_inc;

        PDEBUG("widht_inc %d\nheight_inc %d\n", client->width_inc,
               client->height_inc);
    }

    if (hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE)
    {
        client->base_width = hints.base_width;
        client->base_height = hints.base_height;
    }

    return client;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
movl %edi, %ebp
movl 0x411d(%rip), %eax      # 0xa96c
leaq 0x8(%rsp), %rbx
movl %eax, (%rbx)
movq 0x411b(%rip), %rdi      # 0xa978
pushq $0x8
popq %rdx
movl %ebp, %esi
movq %rbx, %rcx
callq 0x30f0
movl $0x10, (%rbx)
movq 0x4101(%rip), %rdi      # 0xa978
movl %ebp, %esi
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rcx
callq 0x33c0
movq 0x40eb(%rip), %rdi      # 0xa978
xorl %ebx, %ebx
xorl %esi, %esi
movl %ebp, %edx
callq 0x3180
movq 0x40d9(%rip), %rdi      # 0xa978
callq 0x3150
leaq 0x401d(%rip), %rdi      # 0xa8c8
callq 0x6b39
testq %rax, %rax
je 0x69f7
movq %rax, %r14
movl $0x98, %edi
callq 0x3350
testq %rax, %rax
je 0x69f5
movq %rax, %rbx
movq %rax, (%r14)
movl %ebp, (%rax)
xorl %eax, %eax
movb %al, 0x4(%rbx)
andl $0x0, 0x16(%rbx)
andq $0x0, 0x6(%rbx)
movq 0x405c(%rip), %rcx      # 0xa948
movl 0x14(%rcx), %ecx
movl %ecx, 0x1a(%rbx)
movq 0x7d6(%rip), %xmm0      # 0x70d0
movdqu %xmm0, 0x20(%rbx)
andw $0x0, 0x30(%rbx)
movb %al, 0x32(%rbx)
andq $0x0, 0x38(%rbx)
movq %r14, 0x40(%rbx)
pushq $0x9
popq %rax
cmpq $0x13, %rax
je 0x6923
andq $0x0, (%rbx,%rax,8)
incq %rax
jmp 0x6913
movl 0x4027(%rip), %esi      # 0xa950
movq %rbx, %rdi
callq 0x6020
movl (%rbx), %esi
movq 0x403e(%rip), %r14      # 0xa978
movq %r14, %rdi
callq 0x32e0
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x31b0
testq %rax, %rax
je 0x6a05
movzwl 0xc(%rax), %ecx
movw %cx, 0x6(%rbx)
movzwl 0xe(%rax), %ecx
movw %cx, 0x8(%rbx)
movzwl 0x10(%rax), %ecx
movw %cx, 0xa(%rbx)
movzwl 0x12(%rax), %ecx
movw %cx, 0xc(%rbx)
movq %rax, %rdi
callq 0x3040
movq 0x3ff2(%rip), %r14      # 0xa978
movq %r14, %rdi
movl %ebp, %esi
callq 0x31e0
leaq 0x10(%rsp), %r15
movq %r14, %rdi
movl %eax, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x3400
movl (%r15), %eax
testb $0x1, %al
je 0x69af
movb $0x1, 0x4(%rbx)
testb $0x10, %al
je 0x69c3
movq 0x24(%rsp), %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0x16(%rbx)
testb $0x20, %al
je 0x69d7
movq 0x2c(%rsp), %xmm0
pshuflw $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3,4,5,6,7]
movd %xmm0, 0x1a(%rbx)
testb $0x40, %al
je 0x69e4
movq 0x34(%rsp), %rcx
movq %rcx, 0x20(%rbx)
btl $0x8, %eax
jae 0x69f7
movq 0x4c(%rsp), %rax
movq %rax, 0x28(%rbx)
jmp 0x69f7
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x35ec(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x8de(%rip), %rdi       # 0x72f4
pushq $0x32
popq %rsi
pushq $0x1
popq %rdx
callq 0x3510
jmp 0x697f