// File: /workspace/github_c_makefile_star2_O0/tkln[P]mcwm/mcwm.c
// Function: fitonscreen
void fitonscreen(struct client *client)
{
    int16_t mon_x;
    int16_t mon_y;
    uint16_t mon_width;
    uint16_t mon_height;
    bool willmove = false;
    bool willresize = false;

    client->vertmaxed = false;

    if (client->maxed)
    {
        client->maxed = false;
        setborders(client, conf.borderwidth);
    }
        
    if (NULL == client->monitor)
    {
        /*
         * This window isn't attached to any physical monitor. This
         * probably means there is no RANDR, so we use the root window
         * size.
         */
        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;        
    }

    PDEBUG("Is window outside monitor?\n");
    PDEBUG("x: %d between %d and %d?\n", client->x, mon_x, mon_x + mon_width);
    PDEBUG("y: %d between %d and %d?\n", client->y, mon_y, mon_y + mon_height);
    
    /* Is it outside the physical monitor? */
    if (client->x > mon_x + mon_width)
    {
        client->x = mon_x + mon_width - client->width;
        willmove = true;
    }
    if (client->y > mon_y + mon_height)
    {
        client->y = mon_y + mon_height - client->height;
        willmove = true;        
    }
    
    if (client->x < mon_x)
    {
        client->x = mon_x;
        willmove = true;
    }
    if (client->y < mon_y)
    {
        client->y = mon_y;
        willmove = true;
    }
    
    /* Is it smaller than it wants to  be? */
    if (0 != client->min_height && client->height < client->min_height)
    {
        client->height = client->min_height;
        willresize = true;
    }

    if (0 != client->min_width && client->width < client->min_width)
    {
        client->width = client->min_width;
        willresize = true;        
    }

    /*
     * If the window is larger than our screen, just place it in the
     * corner and resize.
     */
    if (client->width + conf.borderwidth * 2 > mon_width)
    {
        client->x = mon_x;
        client->width = mon_width - conf.borderwidth * 2;;
        willmove = true;
        willresize = true;
    }
    else if (client->x + client->width + conf.borderwidth * 2
             > mon_x + mon_width)
    {
        client->x = mon_x + mon_width - (client->width + conf.borderwidth * 2);
        willmove = true;
    }

    if (client->height + conf.borderwidth * 2 > mon_height)
    {
        client->y = mon_y;
        client->height = mon_height - conf.borderwidth * 2;
        willmove = true;
        willresize = true;
    }
    else if (client->y + client->height + conf.borderwidth * 2
             > mon_y + mon_height)
    {
        client->y = mon_y + mon_height - (client->height + conf.borderwidth
                                          * 2);
        willmove = true;
    }

    if (willmove)
    {
        PDEBUG("Moving to %d,%d.\n", client->x, client->y);
        movewindow(client->id, client->x, client->y);
    }

    if (willresize)
    {
        PDEBUG("Resizing to %d x %d.\n", client->width, client->height);
        resize(client->id, client->width, client->height);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movb $0x0, -0x11(%rbp)
movb $0x0, -0x12(%rbp)
movq -0x8(%rbp), %rax
movb $0x0, 0x30(%rax)
movq -0x8(%rbp), %rax
testb $0x1, 0x31(%rax)
je 0x4afd
movq -0x8(%rbp), %rax
movb $0x0, 0x31(%rax)
movq -0x8(%rbp), %rdi
movl 0x8e58(%rip), %esi      # 0xd950
callq 0x7020
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq 0x38(%rcx), %rax
jne 0x4b35
movw $0x0, -0xa(%rbp)
movw $0x0, -0xc(%rbp)
movq 0x8e2c(%rip), %rax      # 0xd948
movw 0x14(%rax), %ax
movw %ax, -0xe(%rbp)
movq 0x8e1d(%rip), %rax      # 0xd948
movw 0x16(%rax), %ax
movw %ax, -0x10(%rbp)
jmp 0x4b75
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movw 0x10(%rax), %ax
movw %ax, -0xa(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movw 0x12(%rax), %ax
movw %ax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movw 0x14(%rax), %ax
movw %ax, -0xe(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movw 0x16(%rax), %ax
movw %ax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movswl -0xa(%rbp), %ecx
movzwl -0xe(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x4bae
movswl -0xa(%rbp), %eax
movzwl -0xe(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movb $0x1, -0x11(%rbp)
movq -0x8(%rbp), %rax
movswl 0x8(%rax), %eax
movswl -0xc(%rbp), %ecx
movzwl -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x4be7
movswl -0xc(%rbp), %eax
movzwl -0x10(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movb $0x1, -0x11(%rbp)
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movswl -0xa(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4c07
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movb $0x1, -0x11(%rbp)
movq -0x8(%rbp), %rax
movswl 0x8(%rax), %eax
movswl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x4c27
movw -0xc(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movb $0x1, -0x11(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x4c5d
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x18(%rcx), %ecx
cmpl %ecx, %eax
jge 0x4c5d
movq -0x8(%rbp), %rax
movw 0x18(%rax), %cx
movq -0x8(%rbp), %rax
movw %cx, 0xc(%rax)
movb $0x1, -0x12(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x16(%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x4c93
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x4c93
movq -0x8(%rbp), %rax
movw 0x16(%rax), %cx
movq -0x8(%rbp), %rax
movw %cx, 0xa(%rax)
movb $0x1, -0x12(%rbp)
movq -0x8(%rbp), %rax
movzwl 0xa(%rax), %eax
movl 0x8caf(%rip), %ecx      # 0xd950
shll %ecx
addl %ecx, %eax
movzwl -0xe(%rbp), %ecx
cmpl %ecx, %eax
jle 0x4cdc
movw -0xa(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movzwl -0xe(%rbp), %eax
movl 0x8c8d(%rip), %ecx      # 0xd950
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0xa(%rax)
movb $0x1, -0x11(%rbp)
movb $0x1, -0x12(%rbp)
jmp 0x4d35
movq -0x8(%rbp), %rax
movswl 0x6(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
addl %ecx, %eax
movl 0x8c5c(%rip), %ecx      # 0xd950
shll %ecx
addl %ecx, %eax
movswl -0xa(%rbp), %ecx
movzwl -0xe(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x4d33
movswl -0xa(%rbp), %eax
movzwl -0xe(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
movl 0x8c32(%rip), %edx      # 0xd950
shll %edx
addl %edx, %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x6(%rax)
movb $0x1, -0x11(%rbp)
jmp 0x4d35
movq -0x8(%rbp), %rax
movzwl 0xc(%rax), %eax
movl 0x8c0d(%rip), %ecx      # 0xd950
shll %ecx
addl %ecx, %eax
movzwl -0x10(%rbp), %ecx
cmpl %ecx, %eax
jle 0x4d7e
movw -0xc(%rbp), %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movzwl -0x10(%rbp), %eax
movl 0x8beb(%rip), %ecx      # 0xd950
shll %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0xc(%rax)
movb $0x1, -0x11(%rbp)
movb $0x1, -0x12(%rbp)
jmp 0x4dd7
movq -0x8(%rbp), %rax
movswl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
addl %ecx, %eax
movl 0x8bba(%rip), %ecx      # 0xd950
shll %ecx
addl %ecx, %eax
movswl -0xc(%rbp), %ecx
movzwl -0x10(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x4dd5
movswl -0xc(%rbp), %eax
movzwl -0x10(%rbp), %ecx
addl %ecx, %eax
movq -0x8(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movl 0x8b90(%rip), %edx      # 0xd950
shll %edx
addl %edx, %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movb $0x1, -0x11(%rbp)
jmp 0x4dd7
testb $0x1, -0x11(%rbp)
je 0x4dfb
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movw 0x6(%rax), %cx
movq -0x8(%rbp), %rax
movzwl %cx, %esi
movzwl 0x8(%rax), %edx
callq 0x7080
testb $0x1, -0x12(%rbp)
je 0x4e1f
movq -0x8(%rbp), %rax
movl (%rax), %edi
movq -0x8(%rbp), %rax
movw 0xa(%rax), %cx
movq -0x8(%rbp), %rax
movzwl %cx, %esi
movzwl 0xc(%rax), %edx
callq 0x70f0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)