// File: /workspace/github_c_makefile_star2_O1/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 0x44b0
movzwl 0x10(%rax), %ecx
movl %ecx, -0x8(%rsp)
movzwl 0x12(%rax), %ecx
movl %ecx, -0x4(%rsp)
jmp 0x44c7
movq 0x6491(%rip), %rax      # 0xa948
movl $0x0, -0x8(%rsp)
movl $0x0, -0x4(%rsp)
movzwl 0x14(%rax), %ecx
movzwl 0x16(%rax), %eax
movl 0x63ea(%rip), %r9d      # 0xa8c0
leaq 0x6403(%rip), %r10      # 0xa8e0
movq (%r10,%r9,8), %r9
testq %r9, %r9
je 0x4717
movl 0x6463(%rip), %r10d     # 0xa954
movl 0x6458(%rip), %r11d     # 0xa950
addl %r11d, %r11d
movq (%r9), %rbx
cmpq %rdi, %rbx
je 0x470a
cmpl $0x3, %esi
je 0x4675
cmpl $0x2, %esi
jne 0x470a
movswl 0x6(%rbx), %r14d
movzwl 0xa(%rbx), %ebp
addl %ebp, %r14d
movswl 0x6(%rdi), %r15d
movl %r14d, %r12d
subl %r15d, %r12d
movl %r12d, %r15d
negl %r15d
cmovsl %r12d, %r15d
cmpl %r10d, %r15d
jge 0x456b
movswl 0x8(%rdi), %r15d
movzwl 0xc(%rdi), %r13d
addl %r15d, %r13d
movswl 0x8(%rbx), %r12d
cmpl %r12d, %r13d
jle 0x456b
movzwl 0xc(%rbx), %r13d
addl %r12d, %r13d
cmpl %r15d, %r13d
jle 0x456b
addl %r11d, %r14d
movw %r14w, 0x6(%rdi)
movswl 0x8(%rbx), %r15d
movzwl 0xc(%rbx), %r14d
addl %r14d, %r15d
movswl 0x8(%rdi), %r12d
movl %r15d, %r13d
subl %r12d, %r13d
movl %r13d, %r12d
negl %r12d
cmovsl %r13d, %r12d
cmpl %r10d, %r12d
jge 0x45c2
movswl 0x6(%rdi), %r12d
movzwl 0xa(%rdi), %r13d
addl %r12d, %r13d
movswl 0x6(%rbx), %edx
cmpl %edx, %r13d
setg %r13b
addl %ebp, %edx
cmpl %r12d, %edx
setg %dl
andb %r13b, %dl
cmpb $0x1, %dl
jne 0x45c2
addl %r11d, %r15d
movw %r15w, 0x8(%rdi)
movswl 0x6(%rdi), %edx
movzwl 0xa(%rdi), %r15d
addl %r15d, %edx
movswl 0x6(%rbx), %r12d
subl %r12d, %edx
movl %edx, %r13d
negl %r13d
cmovsl %edx, %r13d
cmpl %r10d, %r13d
jge 0x4619
movswl 0x8(%rdi), %edx
movzwl 0xc(%rdi), %r13d
addl %edx, %r13d
movswl 0x8(%rbx), %r8d
cmpl %r8d, %r13d
setg %r13b
addl %r8d, %r14d
cmpl %edx, %r14d
setg %dl
andb %r13b, %dl
cmpb $0x1, %dl
jne 0x4619
subl %r15d, %r12d
subl %r11d, %r12d
movw %r12w, 0x6(%rdi)
movswl 0x8(%rdi), %edx
movzwl 0xc(%rdi), %r14d
addl %r14d, %edx
movswl 0x8(%rbx), %r12d
subl %r12d, %edx
movl %edx, %r8d
negl %r8d
cmovsl %edx, %r8d
cmpl %r10d, %r8d
jge 0x470a
movswl 0x6(%rdi), %edx
addl %edx, %r15d
movswl 0x6(%rbx), %r8d
cmpl %r8d, %r15d
setg %bl
addl %r8d, %ebp
cmpl %edx, %ebp
setg %dl
andb %bl, %dl
cmpb $0x1, %dl
jne 0x470a
addl %r11d, %r14d
subl %r14d, %r12d
movw %r12w, 0x8(%rdi)
jmp 0x470a
movswl 0x6(%rdi), %r14d
movzwl 0xa(%rdi), %edx
addl %r14d, %edx
movswl 0x6(%rbx), %ebp
subl %ebp, %edx
movl %edx, %r8d
negl %r8d
cmovsl %edx, %r8d
cmpl %r10d, %r8d
jge 0x46c6
movswl 0x8(%rdi), %r15d
movzwl 0xc(%rdi), %edx
addl %r15d, %edx
movswl 0x8(%rbx), %r12d
cmpl %r12d, %edx
jle 0x46c6
movzwl 0xc(%rbx), %edx
addl %r12d, %edx
cmpl %r15d, %edx
jle 0x46c6
movl %ebp, %r8d
subl %r14d, %r8d
subl %r11d, %r8d
movw %r8w, 0xa(%rdi)
movswl 0x8(%rdi), %r15d
movzwl 0xc(%rdi), %edx
addl %r15d, %edx
movswl 0x8(%rbx), %r12d
subl %r12d, %edx
movl %edx, %r8d
negl %r8d
cmovsl %edx, %r8d
cmpl %r10d, %r8d
jge 0x470a
movzwl 0xa(%rdi), %edx
addl %r14d, %edx
cmpl %ebp, %edx
jle 0x470a
movzwl 0xa(%rbx), %edx
addl %ebp, %edx
cmpl %r14d, %edx
jle 0x470a
addl %r11d, %r15d
subl %r15d, %r12d
movw %r12w, 0xc(%rdi)
movq 0x10(%r9), %r9
testq %r9, %r9
jne 0x44fb
movzwl %ax, %r9d
movzwl %cx, %r10d
cmpl $0x3, %esi
je 0x47c8
cmpl $0x2, %esi
jne 0x4806
movswl 0x6(%rdi), %edx
movl -0x8(%rsp), %r8d
movswl %r8w, %esi
subl %esi, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movzwl %si, %edx
movl 0x6204(%rip), %esi      # 0xa954
cmpl %esi, %edx
jge 0x4759
movw %r8w, 0x6(%rdi)
movswl 0x8(%rdi), %edx
movl -0x4(%rsp), %r11d
movswl %r11w, %r8d
subl %r8d, %edx
movl %edx, %r8d
negl %r8d
cmovsl %edx, %r8d
movzwl %r8w, %edx
cmpl %esi, %edx
jge 0x4780
movw %r11w, 0x8(%rdi)
movswl 0x6(%rdi), %r8d
movzwl 0xa(%rdi), %edx
subl %r10d, %r8d
addl %edx, %r8d
movl %r8d, %r10d
negl %r10d
cmovsl %r8d, %r10d
cmpl %esi, %r10d
jge 0x47a4
subl %edx, %ecx
movw %cx, 0x6(%rdi)
movswl 0x8(%rdi), %edx
movzwl 0xc(%rdi), %ecx
subl %r9d, %edx
addl %ecx, %edx
movl %edx, %r8d
negl %r8d
cmovsl %edx, %r8d
cmpl %esi, %r8d
jge 0x4806
subl %ecx, %eax
movw %ax, 0x8(%rdi)
jmp 0x4806
movzwl 0xa(%rdi), %edx
movswl 0x6(%rdi), %esi
subl %r10d, %edx
addl %esi, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movl 0x6172(%rip), %edx      # 0xa954
cmpl %edx, %esi
jge 0x47ea
movw %cx, 0xa(%rdi)
movzwl 0xc(%rdi), %ecx
movswl 0x8(%rdi), %esi
subl %r9d, %ecx
addl %esi, %ecx
movl %ecx, %esi
negl %esi
cmovsl %ecx, %esi
cmpl %edx, %esi
jge 0x4806
movw %ax, 0xc(%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq