// File: /workspace/github_c_makefile_star2_O2/comfies[P]custard/src/ipc/ipc.c
// Function: ipc_command_geometry
void ipc_command_geometry(vector_t *input, unsigned short *screen_update) {
    suppress_unused(screen_update);

    /*
     * Usage:
     *  custard - geometry [monitor or '*'] [label] [width]x[height] [x],[y]
     */

    char *monitor_name;
    char *label;
    char *size;
    char *position;

    char *token;
    unsigned int height;
    unsigned int width;
    unsigned int x;
    unsigned int y;

    monitor_t *monitor;
    grid_geometry_t *geometry = NULL;
    labeled_grid_geometry_t *labeled_geometry = NULL;

    // Missing geometry data
    if ((input->size - 1) % 4) return;

    while (input->remaining) {
        labeled_geometry = NULL;
        geometry = NULL;

        monitor_name = vector_iterator(input);
        label = vector_iterator(input);
        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);

        /* bullshit here */

        while ((monitor = vector_iterator(monitors))) {
            if (!strcmp(monitor_name, "*") ||
                !strcmp(monitor_name, monitor->name)) {

                if (monitor->geometries) {
                    geometry = get_geometry_from_monitor(monitor, label);
                    if (geometry) {
                        geometry->x = x;
                        geometry->y = y;
                        geometry->height = height;
                        geometry->width = width;
                        free(labeled_geometry);

                        continue;
                    }
                } else
                    monitor->geometries = construct_vector();

                labeled_geometry = create_labeled_geometry(label,
                    x, y, height, width);
                push_to_vector(monitor->geometries, labeled_geometry);
            }
        }
    }

}

// Assembly:
movl 0xc(%rdi), %eax
decl %eax
testb $0x3, %al
je 0x3be9
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rbx
cmpl $0x0, 0x10(%rbx)
je 0x3d3f
movq %rbx, %rdi
callq 0x383d
movq %rax, %rbp
movq %rbx, %rdi
callq 0x383d
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
callq 0x383d
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0x383d
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x446c(%rip), %rsi      # 0x80b5
callq 0x3430
movq %rax, %rdi
callq 0x46ec
movl %eax, 0x4(%rsp)
movq 0x18(%rsp), %rdi
callq 0x46ec
movl %eax, %r12d
leaq 0x10(%rsp), %rdi
leaq 0x4444(%rip), %rsi      # 0x80b7
callq 0x3430
movq %rax, %rdi
callq 0x46ec
movl %eax, %r13d
movq 0x10(%rsp), %rdi
callq 0x46ec
movl %eax, %ebx
xorl %r14d, %r14d
leaq 0x8c2f(%rip), %rax      # 0xc8c8
movq (%rax), %rdi
callq 0x383d
testq %rax, %rax
je 0x3bfc
movq %rax, %r15
cmpb $0x2a, (%rbp)
jne 0x3cb9
cmpb $0x0, 0x1(%rbp)
je 0x3cc8
movq (%r15), %rsi
movq %rbp, %rdi
callq 0x3370
testl %eax, %eax
jne 0x3c92
cmpq $0x0, 0x10(%r15)
je 0x3cfc
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0x5d9b
testq %rax, %rax
je 0x3d11
movl %r13d, (%rax)
movl %ebx, 0x4(%rax)
movl %r12d, 0x8(%rax)
movl 0x4(%rsp), %ecx
movl %ecx, 0xc(%rax)
movq %r14, %rdi
callq 0x3060
jmp 0x3c92
movq %r15, %r14
addq $0x10, %r14
callq 0x3808
movq %rax, 0x10(%r15)
movq %r14, %r15
jmp 0x3d15
addq $0x10, %r15
movq 0x8(%rsp), %rdi
movl %r13d, %esi
movl %ebx, %edx
movl %r12d, %ecx
movl 0x4(%rsp), %r8d
callq 0x5c34
movq %rax, %r14
movq (%r15), %rdi
movq %rax, %rsi
callq 0x3878
jmp 0x3c92
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq