// File: /workspace/github_c_makefile_star2_O1/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 0x3f70(%rip), %eax      # 0xa96c
leaq 0x50(%rsp), %rbx
movl %eax, (%rbx)
movq 0x3f6e(%rip), %rdi      # 0xa978
movl %ebp, %esi
movl $0x8, %edx
movq %rbx, %rcx
callq 0x30f0
movl $0x10, (%rbx)
movq 0x3f52(%rip), %rdi      # 0xa978
movl %ebp, %esi
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rcx
callq 0x33c0
movq 0x3f3c(%rip), %rdi      # 0xa978
xorl %ebx, %ebx
xorl %esi, %esi
movl %ebp, %edx
callq 0x3180
movq 0x3f2a(%rip), %rdi      # 0xa978
callq 0x3150
leaq 0x3e6e(%rip), %rdi      # 0xa8c8
callq 0x6d0c
testq %rax, %rax
je 0x6bea
movq %rax, %r14
movl $0x98, %edi
callq 0x3350
testq %rax, %rax
je 0x6be8
movq %rax, %rbx
movq %rax, (%r14)
movl %ebp, (%rax)
xorl %eax, %eax
movb %al, 0x4(%rbx)
movl $0x0, 0x16(%rbx)
movq %rax, 0x6(%rbx)
movq 0x3eab(%rip), %rcx      # 0xa948
movzwl 0x14(%rcx), %edx
movw %dx, 0x1a(%rbx)
movzwl 0x16(%rcx), %ecx
movw %cx, 0x1c(%rbx)
movq %rax, 0x28(%rbx)
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x20(%rbx)
movw $0x0, 0x30(%rbx)
movb %al, 0x32(%rbx)
movq %rax, 0x38(%rbx)
movq %r14, 0x40(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
movups %xmm0, 0x58(%rbx)
movups %xmm0, 0x68(%rbx)
movups %xmm0, 0x78(%rbx)
movups %xmm0, 0x88(%rbx)
movl 0x3e60(%rip), %eax      # 0xa950
leaq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movq 0x3e7a(%rip), %rdi      # 0xa978
movl %ebp, %esi
movl $0x10, %edx
callq 0x3200
movq 0x3e67(%rip), %rdi      # 0xa978
callq 0x3150
movl (%rbx), %esi
movq 0x3e59(%rip), %r14      # 0xa978
movq %r14, %rdi
callq 0x32e0
movq %r14, %rdi
movl %eax, %esi
xorl %edx, %edx
callq 0x31b0
testq %rax, %rax
je 0x6bf8
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 0x3e0d(%rip), %r14      # 0xa978
movq %r14, %rdi
movl %ebp, %esi
callq 0x31e0
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movl %eax, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x3400
movl (%r15), %eax
testb $0x1, %al
je 0x6b94
movb $0x1, 0x4(%rbx)
testb $0x10, %al
je 0x6baa
movzwl 0x1c(%rsp), %ecx
movw %cx, 0x16(%rbx)
movzwl 0x20(%rsp), %ecx
movw %cx, 0x18(%rbx)
testb $0x20, %al
je 0x6bc0
movzwl 0x24(%rsp), %ecx
movw %cx, 0x1a(%rbx)
movzwl 0x28(%rsp), %ecx
movw %cx, 0x1c(%rbx)
testb $0x40, %al
je 0x6bd2
movl 0x2c(%rsp), %ecx
movl %ecx, 0x20(%rbx)
movl 0x30(%rsp), %ecx
movl %ecx, 0x24(%rbx)
btl $0x8, %eax
jae 0x6bea
movl 0x44(%rsp), %eax
movl %eax, 0x28(%rbx)
movl 0x48(%rsp), %eax
movl %eax, 0x2c(%rbx)
jmp 0x6bea
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x36f2
jmp 0x6b64