// File: /workspace/github_c_makefile_star2_O3/tkln[P]mcwm/mcwm.c
// Function: snapwindow
void snapwindow(struct client *client, int snap_mode)
{
    struct item *item;
    struct client *win;
    int16_t mon_x;
    int16_t mon_y;
    uint16_t mon_width;
    uint16_t mon_height;

    if (NULL == client->monitor)
    {
        mon_x = 0;
        mon_y = 0;
        mon_width = screen->width_in_pixels;
        mon_height = screen->height_in_pixels;
    }
    else
    {
        mon_x = client->monitor->x;
        mon_y = client->monitor->y;
        mon_width = client->monitor->width;
        mon_height = client->monitor->height;
    }
    /*
     * Go through all windows on current workspace.
     */
    for (item = wslist[curws]; item != NULL; item = item->next)
    {
        win = item->data;

        if (client == win)
        {
            continue;
        }

        if (snap_mode == MCWM_MOVE)
        {
            if (abs((win->x +win->width) - client->x) < conf.snapmargin)
            {
                if (client->y + client->height > win->y
                    && client->y < win->y + win->height)
                {
                    client->x = (win->x + win->width) + (2 * conf.borderwidth);
                }
            }

            if (abs((win->y +win->height) - client->y) < conf.snapmargin)
            {
                if (client->x + client->width >win->x
                    && client->x < win->x + win->width)
                {
                    client->y = (win->y + win->height) + (2 * conf.borderwidth);
                }
            }

            if (abs((client->x + client->width) - win->x) < conf.snapmargin)
            {
                if (client->y + client->height > win->y
                    && client->y < win->y + win->height)
                {
                    client->x = (win->x - client->width)
                        - (2 * conf.borderwidth);
                }
            }

            if (abs((client->y + client->height) - win->y) < conf.snapmargin)
            {
                if (client->x + client->width >win->x
                    && client->x < win->x + win->width)
                {
                    client->y = (win->y - client->height)
                        - (2 * conf.borderwidth);
                }
            }

        } /* mcwm_move */
        else if (snap_mode == MCWM_RESIZE)
        {
            if (abs((client->x + client->width) - win->x) < conf.snapmargin)
            {
                if (client->y + client->height > win->y
                    && client->y < win->y + win->height)
                {
                    client->width = (win->x - client->x)
                        - (2 * conf.borderwidth);
                }
            }

            if (abs((client->y + client->height) - win->y) < conf.snapmargin)
            {
                if (client->x + client->width >win->x
                    && client->x < win->x + win->width)
                {
                    client->height = (win->y - client->y)
                        - (2 * conf.borderwidth);
                }
            }
        } /* mcwm_resize */
    } /* for */

    /* monitor border */
    if (snap_mode == MCWM_MOVE) {

        if (abs(client->x - mon_x) < conf.snapmargin)
        {
            client->x = mon_x;
        }

        if (abs(client->y - mon_y) < conf.snapmargin)
        {
            client->y = mon_y;
        }

        if (abs((client->x + client->width) - mon_width) < conf.snapmargin)
        {
            client->x = (mon_width - client->width);
        }

        if (abs((client->y + client->height) - mon_height) < conf.snapmargin)
        {
            client->y = (mon_height - client->height);
        }
    }
    else if (snap_mode == MCWM_RESIZE)
    {
        if (abs((client->width + client->x) - mon_width) < conf.snapmargin)
        {
            client->width = mon_width;
        }
        if (abs((client->height + client->y) - mon_height) < conf.snapmargin)
        {
            client->height = mon_height;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x38(%rdi), %rax
testq %rax, %rax
je 0x44dc
movzwl 0x10(%rax), %ecx
movl %ecx, -0x18(%rsp)
movzwl 0x12(%rax), %ecx
movl %ecx, -0x14(%rsp)
jmp 0x44f3
movq 0x6465(%rip), %rax      # 0xa948
movl $0x0, -0x18(%rsp)
movl $0x0, -0x14(%rsp)
movzwl 0x14(%rax), %ecx
movl %ecx, -0x10(%rsp)
movzwl 0x16(%rax), %eax
movl %eax, -0xc(%rsp)
movl 0x63b7(%rip), %eax      # 0xa8c0
leaq 0x63d0(%rip), %rcx      # 0xa8e0
movq (%rcx,%rax,8), %r9
testq %r9, %r9
je 0x473e
movl 0x6430(%rip), %r10d     # 0xa954
movl 0x6426(%rip), %eax      # 0xa950
addl %eax, %eax
movq %rax, -0x20(%rsp)
movq (%r9), %rbx
cmpq %rdi, %rbx
je 0x4731
cmpl $0x3, %esi
je 0x45b7
cmpl $0x2, %esi
jne 0x4731
movswl 0x6(%rbx), %r8d
movzwl 0xa(%rbx), %edx
movl %r8d, %eax
movq %rdx, -0x8(%rsp)
addl %edx, %eax
movswl 0x6(%rdi), %ebp
movl %eax, %ecx
subl %ebp, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
cmpl %r10d, %edx
jge 0x4621
movzwl 0x8(%rdi), %r12d
movswl %r12w, %r13d
movzwl 0xc(%rdi), %ecx
addl %r13d, %ecx
movzwl 0x8(%rbx), %r15d
movswl %r15w, %edx
cmpl %edx, %ecx
jle 0x4633
movzwl 0xc(%rbx), %ecx
addl %edx, %ecx
cmpl %r13d, %ecx
jle 0x4633
addl -0x20(%rsp), %eax
movw %ax, 0x6(%rdi)
movzwl 0x6(%rbx), %r8d
movl %eax, %ebp
jmp 0x4633
movswl 0x6(%rdi), %r14d
movzwl 0xa(%rdi), %r15d
movl %r15d, %eax
addl %r14d, %eax
movswl 0x6(%rbx), %r8d
subl %r8d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movswl 0x8(%rdi), %edx
movzwl 0xc(%rdi), %eax
cmpl %r10d, %ecx
jge 0x46f6
addl %edx, %eax
movzwl 0x8(%rbx), %ebp
movswl %bp, %r12d
cmpl %r12d, %eax
jle 0x4700
movzwl 0xc(%rbx), %ecx
addl %r12d, %ecx
cmpl %edx, %ecx
jle 0x4700
movq -0x20(%rsp), %rcx
addl %r14d, %ecx
movl %r8d, %r15d
subl %ecx, %r15d
movw %r15w, 0xa(%rdi)
jmp 0x4700
movzwl 0x8(%rbx), %r15d
movzwl 0x8(%rdi), %r12d
movswl %r15w, %edx
movswl %r12w, %r13d
movzwl 0xc(%rbx), %eax
addl %eax, %edx
movl %edx, %ecx
subl %r13d, %ecx
movl %ecx, %r14d
negl %r14d
cmovsl %ecx, %r14d
movzwl 0xa(%rdi), %r13d
movswl %bp, %r11d
leal (%r11,%r13), %ecx
movswl %r8w, %r8d
cmpl %r10d, %r14d
jge 0x4680
cmpl %r8d, %ecx
jle 0x4680
movq -0x8(%rsp), %r14
addl %r8d, %r14d
cmpl %r11d, %r14d
jle 0x4680
addl -0x20(%rsp), %edx
movw %dx, 0x8(%rdi)
movzwl 0x8(%rbx), %r15d
movl %edx, %r12d
subl %r8d, %ecx
movl %ecx, %r14d
negl %r14d
cmovsl %ecx, %r14d
movzwl 0xc(%rdi), %edx
movswl %r12w, %r11d
leal (%rdx,%r11), %ecx
movswl %r15w, %r15d
cmpl %r10d, %r14d
jge 0x46c2
cmpl %r15d, %ecx
jle 0x46c2
addl %r15d, %eax
cmpl %r11d, %eax
jle 0x46c2
movq -0x20(%rsp), %rax
addl %r13d, %eax
subl %eax, %r8d
movw %r8w, 0x6(%rdi)
movl %r8d, %ebp
subl %r15d, %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
cmpl %r10d, %eax
jge 0x4731
movswl %bp, %eax
addl %eax, %r13d
movswl 0x6(%rbx), %ecx
cmpl %ecx, %r13d
jle 0x4731
addl -0x8(%rsp), %ecx
cmpl %eax, %ecx
jle 0x4731
addl -0x20(%rsp), %edx
subl %edx, %r15d
movw %r15w, 0x8(%rdi)
jmp 0x4731
movzwl 0x8(%rbx), %ebp
addl %edx, %eax
movswl %bp, %r12d
subl %r12d, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl %r10d, %ecx
jge 0x4731
movzwl %r15w, %eax
addl %r14d, %eax
cmpl %r8d, %eax
jle 0x4731
movzwl 0xa(%rbx), %eax
addl %r8d, %eax
cmpl %r14d, %eax
jle 0x4731
addl -0x20(%rsp), %edx
subl %edx, %ebp
movw %bp, 0xc(%rdi)
movq 0x10(%r9), %r9
testq %r9, %r9
jne 0x4531
movl -0xc(%rsp), %r11d
movzwl %r11w, %r9d
movl -0x10(%rsp), %ebx
movzwl %bx, %edx
cmpl $0x3, %esi
je 0x47fa
cmpl $0x2, %esi
jne 0x4838
movswl 0x6(%rdi), %esi
movl -0x18(%rsp), %r8d
movswl %r8w, %eax
movl %esi, %ecx
subl %eax, %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movzwl %ax, %ecx
movl 0x61d3(%rip), %eax      # 0xa954
cmpl %eax, %ecx
jge 0x478d
movw %r8w, 0x6(%rdi)
movl %r8d, %esi
movswl 0x8(%rdi), %ecx
movl -0x14(%rsp), %ebp
movswl %bp, %r8d
movl %ecx, %r10d
subl %r8d, %r10d
movl %r10d, %r8d
negl %r8d
cmovsl %r10d, %r8d
movzwl %r8w, %r8d
cmpl %eax, %r8d
jge 0x47b8
movw %bp, 0x8(%rdi)
movl %ebp, %ecx
movswl %si, %r8d
movzwl 0xa(%rdi), %esi
subl %edx, %r8d
addl %esi, %r8d
movl %r8d, %edx
negl %edx
cmovsl %r8d, %edx
cmpl %eax, %edx
jge 0x47d9
subl %esi, %ebx
movw %bx, 0x6(%rdi)
movswl %cx, %edx
movzwl 0xc(%rdi), %ecx
subl %r9d, %edx
addl %ecx, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
cmpl %eax, %esi
jge 0x4838
subl %ecx, %r11d
movw %r11w, 0x8(%rdi)
jmp 0x4838
movzwl 0xa(%rdi), %eax
movswl 0x6(%rdi), %ecx
subl %edx, %eax
addl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl 0x6141(%rip), %eax      # 0xa954
cmpl %eax, %ecx
jge 0x481b
movw %bx, 0xa(%rdi)
movzwl 0xc(%rdi), %ecx
movswl 0x8(%rdi), %edx
subl %r9d, %ecx
addl %edx, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
cmpl %eax, %edx
jge 0x4838
movw %r11w, 0xc(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq