// File: /workspace/github_c_makefile_star2_O1/comfies[P]custard/src/ipc/ipc.c
// Function: ipc_command_window
void ipc_command_window(vector_t *input, unsigned short *screen_update) {
    // Missing input
    if (input->size < 2) return;
    char *variable = vector_iterator(input);

    /*
     * Usage:
     * custard - window close
     *  custard - window geometry [label]
     */

    window_t *window = NULL;
    if (focused_window == XCB_WINDOW_NONE)
        return;
    if (window_is_managed(focused_window))
        window = get_window_by_id(focused_window);

    if (!strcmp(variable, "close")) {
        close_window(focused_window);
    } else if (!strcmp(variable, "raise")) {

        if (window)
            raise_window(window->parent);
        else
            raise_window(focused_window);

    } else if (!strcmp(variable, "expand")) {

        if (!window || window->floating)
            return;

        char *cardinal = vector_iterator(input);
        grid_geometry_t *geometry = (grid_geometry_t*)window->geometry;

        if (!strcmp(cardinal, "north")) {
            if (geometry->y == 0)
                return;
            geometry->y--;
            geometry->height++;
        } else if (!strcmp(cardinal, "south"))
            geometry->height++;
        else if (!strcmp(cardinal, "east"))
            geometry->width++;
        else if (!strcmp(cardinal, "west")) {
            if (geometry->x == 0)
                return;
            geometry->x--;
            geometry->width++;
        } else return;

        set_window_geometry(window, geometry);
        decorate(window);

    } else if (!strcmp(variable, "contract")) {

        if (!window || window->floating)
            return;

        char *cardinal = vector_iterator(input);
        grid_geometry_t *geometry = (grid_geometry_t*)window->geometry;

        if (!strcmp(cardinal, "north")) {
            if (geometry->height == 1)
                return;
            geometry->y++;
            geometry->height--;
        } else if (!strcmp(cardinal, "south")) {
            if (geometry->height == 1)
                return;
            geometry->height--;
        } else if (!strcmp(cardinal, "east")) {
            if (geometry->width == 1)
                return;
            geometry->width--;
        } else if (!strcmp(cardinal, "west")) {
            if (geometry->width == 1)
                return;
            geometry->x++;
            geometry->width--;
        } else return;

        set_window_geometry(window, geometry);
        decorate(window);

    } else if (!strcmp(variable, "move")) {

        if (!window || window->floating)
            return;

        char *cardinal = vector_iterator(input);
        grid_geometry_t *geometry = (grid_geometry_t*)window->geometry;

        if (!strcmp(cardinal, "north")) {
            if (geometry->y == 0)
                return;
            geometry->y--;
        } else if (!strcmp(cardinal, "south"))
            geometry->y++;
        else if (!strcmp(cardinal, "east"))
            geometry->x++;
        else if (!strcmp(cardinal, "west")) {
            if (geometry->x == 0)
                return;
            geometry->x--;
        } else return;

        set_window_geometry(window, geometry);
        decorate(window);


    } else if (!strcmp(variable, "lower")) {

        if (window)
            lower_window(window->parent);
        else
            lower_window(focused_window);

    } else if (!strcmp(variable, "workspace")) {

        unsigned int workspace = string_to_integer(vector_iterator(input));

        if (window) {
            if (window->workspace == workspace)
                return;

            window->workspace = workspace;

            monitor_t *monitor = monitor_with_cursor_residence();
            if (monitor->workspace != window->workspace)
                unmap_window(window->parent);
        }

    } else if (!strcmp(variable, "geometry")) {
        char *label = vector_iterator(input);

        grid_geometry_t *geometry = (grid_geometry_t *)calloc(1,
            sizeof(grid_geometry_t));
        monitor_t *monitor = monitor_with_cursor_residence();

        log_debug("Looking for geometry(%s) in monitor(%s)",
            label, monitor->name);

        memcpy(geometry,
            get_geometry_from_monitor(monitor, label),
            sizeof(grid_geometry_t));

        if (!geometry)
            return;

        window_t *window = get_window_by_id(focused_window);
        if (window) {
            window->floating = 0;

            free(window->geometry);
            set_window_geometry(window, geometry);
            decorate(window);
        }

    } else if (!strcmp(variable, "float")) {
        char *token;
        char *size;
        char *position;
        unsigned int height;
        unsigned int width;
        unsigned int x;
        unsigned int y;

        size = vector_iterator(input);
        position = vector_iterator(input);

        token = strsep(&size, "x");

        width = string_to_integer(token);
        height = string_to_integer(size);

        token = strsep(&position, ",");

        x = string_to_integer(token);
        y = string_to_integer(position);

        window_t *window = get_window_by_id(focused_window);
        if (window) {
            window->floating = 1;
            screen_geometry_t *geometry = create_screen_geometry(x, y, height,
                width);

            free(window->geometry);
            set_window_geometry(window, geometry);
            decorate(window);
        }
    }

    *screen_update = 1;
}

// Assembly:
cmpl $0x2, 0xc(%rdi)
jb 0x412e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
callq 0x3851
leaq 0x8abb(%rip), %rbp      # 0xc8f0
movl (%rbp), %edi
testl %edi, %edi
je 0x4120
movq %rax, %r12
callq 0x6d51
testw %ax, %ax
je 0x3e5a
movl (%rbp), %edi
callq 0x6d63
movq %rax, %r14
jmp 0x3e5d
xorl %r14d, %r14d
leaq 0x4259(%rip), %rsi      # 0x80bd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3fcb
leaq 0x4248(%rip), %rsi      # 0x80c3
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3fd8
leaq 0x4237(%rip), %rsi      # 0x80c9
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3fea
leaq 0x423d(%rip), %rsi      # 0x80e6
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4082
leaq 0x422f(%rip), %rsi      # 0x80ef
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x412f
leaq 0x421d(%rip), %rsi      # 0x80f4
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x41bc
leaq 0x415f(%rip), %rsi      # 0x804d
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x41ce
leaq 0x4a96(%rip), %rsi      # 0x899b
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4215
leaq 0x4227(%rip), %rsi      # 0x8143
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x411b
movq %r15, %rdi
callq 0x3851
leaq 0x20(%rsp), %r14
movq %rax, (%r14)
movq %r15, %rdi
callq 0x3851
leaq 0x18(%rsp), %r15
movq %rax, (%r15)
leaq 0x4164(%rip), %rsi      # 0x80b7
movq %r14, %rdi
callq 0x3440
movq %rax, %rdi
callq 0x479c
movl %eax, 0x14(%rsp)
movq (%r14), %rdi
callq 0x479c
movl %eax, %r14d
leaq 0x4140(%rip), %rsi      # 0x80b9
movq %r15, %rdi
callq 0x3440
movq %rax, %rdi
callq 0x479c
movl %eax, %r12d
movq (%r15), %rdi
callq 0x479c
movl %eax, %r13d
movl (%rbp), %edi
callq 0x6d63
testq %rax, %rax
je 0x411b
movq %rax, %r15
movw $0x1, 0x22(%rax)
movl %r12d, %edi
movl %r13d, %esi
movl %r14d, %edx
movl 0x14(%rsp), %ecx
callq 0x5f8c
movq %rax, %r14
jmp 0x429f
movl (%rbp), %edi
callq 0x78ea
jmp 0x411b
testq %r14, %r14
je 0x4113
movl 0x4(%r14), %edi
jmp 0x4116
testq %r14, %r14
je 0x4120
cmpw $0x0, 0x22(%r14)
jne 0x4120
movq %r15, %rdi
callq 0x3851
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x40bb(%rip), %rsi      # 0x80d0
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x42c8
leaq 0x40aa(%rip), %rsi      # 0x80d6
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x42e3
leaq 0x4099(%rip), %rsi      # 0x80dc
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4303
leaq 0x4087(%rip), %rsi      # 0x80e1
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x4120
movl (%r15), %ecx
movl $0xc, %eax
movq %r15, %rdx
testl %ecx, %ecx
jne 0x42dd
jmp 0x4120
testq %r14, %r14
je 0x4120
cmpw $0x0, 0x22(%r14)
jne 0x4120
movq %r15, %rdi
callq 0x3851
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x4023(%rip), %rsi      # 0x80d0
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x42ea
leaq 0x4012(%rip), %rsi      # 0x80d6
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x430e
leaq 0x4001(%rip), %rsi      # 0x80dc
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4335
leaq 0x3fef(%rip), %rsi      # 0x80e1
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x4120
movl 0xc(%r15), %eax
cmpl $0x1, %eax
je 0x4120
leaq 0xc(%r15), %rcx
movq %r15, %rdx
jmp 0x42ff
movl (%rbp), %edi
callq 0x77ea
movw $0x1, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x4120
cmpw $0x0, 0x22(%r14)
jne 0x4120
movq %r15, %rdi
callq 0x3851
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x3f7e(%rip), %rsi      # 0x80d0
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x4321
leaq 0x3f6d(%rip), %rsi      # 0x80d6
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x434c
leaq 0x3f5c(%rip), %rsi      # 0x80dc
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4352
leaq 0x3f4a(%rip), %rsi      # 0x80e1
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x4120
movl (%r15), %eax
testl %eax, %eax
je 0x4120
decl %eax
movl %eax, (%r15)
jmp 0x4355
testq %r14, %r14
je 0x42bb
movl 0x4(%r14), %edi
jmp 0x42be
movq %r15, %rdi
callq 0x3851
movq %rax, %rdi
callq 0x479c
testq %r14, %r14
je 0x411b
cmpl %eax, 0x24(%r14)
je 0x4120
movl %eax, 0x24(%r14)
callq 0x69f2
movl 0x20(%rax), %eax
cmpl 0x24(%r14), %eax
je 0x411b
movl 0x4(%r14), %edi
callq 0x7712
jmp 0x411b
movq %r15, %rdi
callq 0x3851
movq %rax, %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x3340
movq %rax, %r14
callq 0x69f2
movq %rax, %r12
movq (%rax), %rax
movq %rax, (%rsp)
leaq 0x3eb2(%rip), %rsi      # 0x80fa
leaq 0x3eb9(%rip), %rdx      # 0x8108
leaq 0x3ec5(%rip), %r8       # 0x811b
movl $0x3, %edi
movl $0x156, %ecx            # imm = 0x156
movq %r15, %r9
xorl %eax, %eax
callq 0x5206
movq %r12, %rdi
movq %r15, %rsi
callq 0x608a
movups (%rax), %xmm0
movups %xmm0, (%r14)
testq %r14, %r14
je 0x4120
movl (%rbp), %edi
callq 0x6d63
testq %rax, %rax
je 0x411b
movq %rax, %r15
movw $0x0, 0x22(%rax)
movq 0x8(%r15), %rdi
callq 0x3060
movq %r15, %rdi
movq %r14, %rsi
callq 0x7087
movq %r15, %rdi
jmp 0x4363
movl (%rbp), %edi
callq 0x786a
jmp 0x411b
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x4120
leaq 0x4(%r15), %rdx
movl $0x8, %eax
decl %ecx
movl %ecx, (%rdx)
jmp 0x4308
movl $0x8, %eax
jmp 0x4308
movl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x4120
leaq 0x8(%r15), %rcx
leaq 0x4(%r15), %rdx
incl (%rdx)
jmp 0x4346
movl $0xc, %eax
incl (%r15,%rax)
jmp 0x4355
movl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x4120
leaq 0x8(%r15), %rcx
jmp 0x4346
movl 0x4(%r15), %eax
testl %eax, %eax
je 0x4120
decl %eax
movl %eax, 0x4(%r15)
jmp 0x4355
movl 0xc(%r15), %eax
cmpl $0x1, %eax
je 0x4120
leaq 0xc(%r15), %rcx
decl %eax
movl %eax, (%rcx)
jmp 0x4355
incl 0x4(%r15)
jmp 0x4355
incl (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x7087
movq %r14, %rdi
callq 0x58c3
jmp 0x411b