// File: /workspace/github_c_makefile_star2_O3/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 0x410d
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
callq 0x3849
leaq 0x8adc(%rip), %rbp      # 0xc8f0
movl (%rbp), %edi
testl %edi, %edi
je 0x40ff
movq %rax, %r12
callq 0x6d0e
testw %ax, %ax
je 0x3e39
movl (%rbp), %edi
callq 0x6d20
movq %rax, %r14
jmp 0x3e3c
xorl %r14d, %r14d
leaq 0x4276(%rip), %rsi      # 0x80b9
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3faa
leaq 0x4265(%rip), %rsi      # 0x80bf
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3fb7
leaq 0x4254(%rip), %rsi      # 0x80c5
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x3fc9
leaq 0x425a(%rip), %rsi      # 0x80e2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4061
leaq 0x424c(%rip), %rsi      # 0x80eb
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x410e
leaq 0x423a(%rip), %rsi      # 0x80f0
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x419b
leaq 0x417e(%rip), %rsi      # 0x804b
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x41ad
leaq 0x4b25(%rip), %rsi      # 0x8a09
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x41f4
leaq 0x4244(%rip), %rsi      # 0x813f
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x40fa
movq %r15, %rdi
callq 0x3849
leaq 0x20(%rsp), %r14
movq %rax, (%r14)
movq %r15, %rdi
callq 0x3849
leaq 0x18(%rsp), %r15
movq %rax, (%r15)
leaq 0x4183(%rip), %rsi      # 0x80b5
movq %r14, %rdi
callq 0x3440
movq %rax, %rdi
callq 0x4770
movl %eax, 0x14(%rsp)
movq (%r14), %rdi
callq 0x4770
movl %eax, %r14d
leaq 0x415f(%rip), %rsi      # 0x80b7
movq %r15, %rdi
callq 0x3440
movq %rax, %rdi
callq 0x4770
movl %eax, %r12d
movq (%r15), %rdi
callq 0x4770
movl %eax, %r13d
movl (%rbp), %edi
callq 0x6d20
testq %rax, %rax
je 0x40fa
movq %rax, %r15
movw $0x1, 0x22(%rax)
movl %r12d, %edi
movl %r13d, %esi
movl %r14d, %edx
movl 0x14(%rsp), %ecx
callq 0x5f5c
movq %rax, %r14
jmp 0x4275
movl (%rbp), %edi
callq 0x78aa
jmp 0x40fa
testq %r14, %r14
je 0x40f2
movl 0x4(%r14), %edi
jmp 0x40f5
testq %r14, %r14
je 0x40ff
cmpw $0x0, 0x22(%r14)
jne 0x40ff
movq %r15, %rdi
callq 0x3849
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x40d8(%rip), %rsi      # 0x80cc
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x429e
leaq 0x40c7(%rip), %rsi      # 0x80d2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x42b9
leaq 0x40b6(%rip), %rsi      # 0x80d8
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x42d9
leaq 0x40a4(%rip), %rsi      # 0x80dd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x40ff
movl (%r15), %ecx
movl $0xc, %eax
movq %r15, %rdx
testl %ecx, %ecx
jne 0x42b3
jmp 0x40ff
testq %r14, %r14
je 0x40ff
cmpw $0x0, 0x22(%r14)
jne 0x40ff
movq %r15, %rdi
callq 0x3849
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x4040(%rip), %rsi      # 0x80cc
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x42c0
leaq 0x402f(%rip), %rsi      # 0x80d2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x42e4
leaq 0x401e(%rip), %rsi      # 0x80d8
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x430b
leaq 0x400c(%rip), %rsi      # 0x80dd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x40ff
movl 0xc(%r15), %eax
cmpl $0x1, %eax
je 0x40ff
leaq 0xc(%r15), %rcx
movq %r15, %rdx
jmp 0x42d5
movl (%rbp), %edi
callq 0x77aa
movw $0x1, (%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0x40ff
cmpw $0x0, 0x22(%r14)
jne 0x40ff
movq %r15, %rdi
callq 0x3849
movq %rax, %r12
movq 0x8(%r14), %r15
leaq 0x3f9b(%rip), %rsi      # 0x80cc
movq %rax, %rdi
callq 0x3370
testl %eax, %eax
je 0x42f7
leaq 0x3f8a(%rip), %rsi      # 0x80d2
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4322
leaq 0x3f79(%rip), %rsi      # 0x80d8
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
je 0x4328
leaq 0x3f67(%rip), %rsi      # 0x80dd
movq %r12, %rdi
callq 0x3370
testl %eax, %eax
jne 0x40ff
movl (%r15), %eax
testl %eax, %eax
je 0x40ff
decl %eax
movl %eax, (%r15)
jmp 0x432b
testq %r14, %r14
je 0x4291
movl 0x4(%r14), %edi
jmp 0x4294
movq %r15, %rdi
callq 0x3849
movq %rax, %rdi
callq 0x4770
testq %r14, %r14
je 0x40fa
cmpl %eax, 0x24(%r14)
je 0x40ff
movl %eax, 0x24(%r14)
callq 0x69c8
movl 0x20(%rax), %eax
cmpl 0x24(%r14), %eax
je 0x40fa
movl 0x4(%r14), %edi
callq 0x76d2
jmp 0x40fa
movq %r15, %rdi
callq 0x3849
movq %rax, %r15
movl $0x1, %edi
movl $0x10, %esi
callq 0x3340
movq %rax, %r14
callq 0x69c8
movq %rax, %r12
movq (%rax), %rax
movq %rax, (%rsp)
leaq 0x3ecf(%rip), %rsi      # 0x80f6
leaq 0x3ed6(%rip), %rdx      # 0x8104
leaq 0x3ee2(%rip), %r8       # 0x8117
movl $0x3, %edi
movl $0x156, %ecx            # imm = 0x156
movq %r15, %r9
xorl %eax, %eax
callq 0x51d6
movq %r12, %rdi
movq %r15, %rsi
callq 0x6099
movups (%rax), %xmm0
movups %xmm0, (%r14)
movl (%rbp), %edi
callq 0x6d20
testq %rax, %rax
je 0x40fa
movq %rax, %r15
movw $0x0, 0x22(%rax)
movq 0x8(%r15), %rdi
callq 0x3060
movq %r15, %rdi
movq %r14, %rsi
callq 0x7052
movq %r15, %rdi
jmp 0x4339
movl (%rbp), %edi
callq 0x782a
jmp 0x40fa
movl 0x4(%r15), %ecx
testl %ecx, %ecx
je 0x40ff
leaq 0x4(%r15), %rdx
movl $0x8, %eax
decl %ecx
movl %ecx, (%rdx)
jmp 0x42de
movl $0x8, %eax
jmp 0x42de
movl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x40ff
leaq 0x8(%r15), %rcx
leaq 0x4(%r15), %rdx
incl (%rdx)
jmp 0x431c
movl $0xc, %eax
incl (%r15,%rax)
jmp 0x432b
movl 0x8(%r15), %eax
cmpl $0x1, %eax
je 0x40ff
leaq 0x8(%r15), %rcx
jmp 0x431c
movl 0x4(%r15), %eax
testl %eax, %eax
je 0x40ff
decl %eax
movl %eax, 0x4(%r15)
jmp 0x432b
movl 0xc(%r15), %eax
cmpl $0x1, %eax
je 0x40ff
leaq 0xc(%r15), %rcx
decl %eax
movl %eax, (%rcx)
jmp 0x432b
incl 0x4(%r15)
jmp 0x432b
incl (%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x7052
movq %r14, %rdi
callq 0x5882
jmp 0x40fa