// File: /workspace/github_c_makefile_star2_O2/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 0x4329
movzwl 0x10(%rax), %ecx
movl %ecx, -0x18(%rsp)
movzwl 0x12(%rax), %ecx
movl %ecx, -0x14(%rsp)
jmp 0x4340
movq 0x6618(%rip), %rax      # 0xa948
movl $0x0, -0x18(%rsp)
movl $0x0, -0x14(%rsp)
movzwl 0x14(%rax), %ecx
movzwl 0x16(%rax), %eax
movl %eax, -0x1c(%rsp)
movzwl %ax, %eax
movl %eax, -0xc(%rsp)
movl %ecx, -0x20(%rsp)
movzwl %cx, %eax
movl %eax, -0x10(%rsp)
movl 0x655c(%rip), %eax      # 0xa8c0
leaq 0x6575(%rip), %rcx      # 0xa8e0
leaq (%rcx,%rax,8), %r11
movl 0x65df(%rip), %ebx      # 0xa954
movl 0x65d5(%rip), %eax      # 0xa950
addl %eax, %eax
movq %rax, -0x28(%rsp)
movq (%r11), %r11
testq %r11, %r11
je 0x459a
movq (%r11), %r15
cmpq %rdi, %r15
je 0x4591
cmpl $0x3, %esi
je 0x4416
cmpl $0x2, %esi
jne 0x4591
movswl 0x6(%r15), %r10d
movzwl 0xa(%r15), %edx
movl %r10d, %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 %ebx, %edx
jge 0x447d
movzwl 0x8(%rdi), %ecx
movswl %cx, %r9d
movzwl 0xc(%rdi), %edx
addl %r9d, %edx
movzwl 0x8(%r15), %r13d
movswl %r13w, %r8d
cmpl %r8d, %edx
jle 0x448e
movzwl 0xc(%r15), %edx
addl %r8d, %edx
cmpl %r9d, %edx
jle 0x448e
addl -0x28(%rsp), %eax
movw %ax, 0x6(%rdi)
movzwl 0x6(%r15), %r10d
movl %eax, %ebp
jmp 0x448e
movswl 0x6(%rdi), %ecx
movzwl 0xa(%rdi), %ebp
movl %ebp, %eax
addl %ecx, %eax
movswl 0x6(%r15), %r9d
subl %r9d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
movswl 0x8(%rdi), %r8d
movzwl 0xc(%rdi), %eax
cmpl %ebx, %edx
jge 0x4554
addl %r8d, %eax
movzwl 0x8(%r15), %r10d
movswl %r10w, %r12d
cmpl %r12d, %eax
jle 0x4560
movzwl 0xc(%r15), %edx
addl %r12d, %edx
cmpl %r8d, %edx
jle 0x4560
movq -0x28(%rsp), %rdx
addl %ecx, %edx
movl %r9d, %ebp
subl %edx, %ebp
movw %bp, 0xa(%rdi)
jmp 0x4560
movzwl 0x8(%r15), %r13d
movzwl 0x8(%rdi), %ecx
movswl %r13w, %r8d
movswl %cx, %r9d
movzwl 0xc(%r15), %eax
addl %eax, %r8d
movl %r8d, %edx
subl %r9d, %edx
movl %edx, %r12d
negl %r12d
cmovsl %edx, %r12d
movzwl 0xa(%rdi), %r9d
movswl %bp, %r14d
leal (%r9,%r14), %edx
movswl %r10w, %r10d
cmpl %ebx, %r12d
jge 0x44e0
cmpl %r10d, %edx
jle 0x44e0
movq -0x8(%rsp), %r12
addl %r10d, %r12d
cmpl %r14d, %r12d
jle 0x44e0
addl -0x28(%rsp), %r8d
movw %r8w, 0x8(%rdi)
movzwl 0x8(%r15), %r13d
movl %r8d, %ecx
subl %r10d, %edx
movl %edx, %r12d
negl %r12d
cmovsl %edx, %r12d
movzwl 0xc(%rdi), %r8d
movswl %cx, %r14d
leal (%r8,%r14), %edx
movswl %r13w, %ecx
cmpl %ebx, %r12d
jge 0x4521
cmpl %ecx, %edx
jle 0x4521
addl %ecx, %eax
cmpl %r14d, %eax
jle 0x4521
movq -0x28(%rsp), %rax
addl %r9d, %eax
subl %eax, %r10d
movw %r10w, 0x6(%rdi)
movl %r10d, %ebp
subl %ecx, %edx
movl %edx, %eax
negl %eax
cmovsl %edx, %eax
cmpl %ebx, %eax
jge 0x4591
movswl %bp, %eax
addl %eax, %r9d
movswl 0x6(%r15), %edx
cmpl %edx, %r9d
jle 0x4591
addl -0x8(%rsp), %edx
cmpl %eax, %edx
jle 0x4591
addl -0x28(%rsp), %r8d
subl %r8d, %ecx
movw %cx, 0x8(%rdi)
jmp 0x4591
movzwl 0x8(%r15), %r10d
addl %r8d, %eax
movswl %r10w, %r12d
subl %r12d, %eax
movl %eax, %edx
negl %edx
cmovsl %eax, %edx
cmpl %ebx, %edx
jge 0x4591
movzwl %bp, %eax
addl %ecx, %eax
cmpl %r9d, %eax
jle 0x4591
movzwl 0xa(%r15), %eax
addl %r9d, %eax
cmpl %ecx, %eax
jle 0x4591
addl -0x28(%rsp), %r8d
subl %r8d, %r10d
movw %r10w, 0xc(%rdi)
addq $0x10, %r11
jmp 0x4382
cmpl $0x3, %esi
je 0x464a
cmpl $0x2, %esi
jne 0x4692
movswl 0x6(%rdi), %edx
movl -0x18(%rsp), %esi
movswl %si, %eax
movl %edx, %ecx
subl %eax, %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movzwl %ax, %ecx
movl 0x6389(%rip), %eax      # 0xa954
cmpl %eax, %ecx
jge 0x45d5
movw %si, 0x6(%rdi)
movl %esi, %edx
movswl 0x8(%rdi), %ecx
movl -0x14(%rsp), %r9d
movswl %r9w, %esi
movl %ecx, %r8d
subl %esi, %r8d
movl %r8d, %esi
negl %esi
cmovsl %r8d, %esi
movzwl %si, %esi
cmpl %eax, %esi
jge 0x4600
movw %r9w, 0x8(%rdi)
movl %r9d, %ecx
movswl %dx, %esi
movzwl 0xa(%rdi), %edx
subl -0x10(%rsp), %esi
addl %edx, %esi
movl %esi, %r8d
negl %r8d
cmovsl %esi, %r8d
cmpl %eax, %r8d
jge 0x4626
movl -0x20(%rsp), %esi
subl %edx, %esi
movw %si, 0x6(%rdi)
movswl %cx, %edx
movzwl 0xc(%rdi), %ecx
subl -0xc(%rsp), %edx
addl %ecx, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
cmpl %eax, %esi
jge 0x4692
movl -0x1c(%rsp), %eax
subl %ecx, %eax
movw %ax, 0x8(%rdi)
jmp 0x4692
movzwl 0xa(%rdi), %eax
movswl 0x6(%rdi), %ecx
subl -0x10(%rsp), %eax
addl %ecx, %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl 0x62ef(%rip), %eax      # 0xa954
cmpl %eax, %ecx
jge 0x4671
movl -0x20(%rsp), %ecx
movw %cx, 0xa(%rdi)
movzwl 0xc(%rdi), %ecx
movswl 0x8(%rdi), %edx
subl -0xc(%rsp), %ecx
addl %edx, %ecx
movl %ecx, %edx
negl %edx
cmovsl %ecx, %edx
cmpl %eax, %edx
jge 0x4692
movl -0x1c(%rsp), %eax
movw %ax, 0xc(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq