// File: /workspace/github_c_makefile_star2_O0/comfies[P]custard/src/ipc/ipc.c
// Function: ipc_command_focus
void ipc_command_focus(vector_t *input, unsigned short *screen_update) {
    suppress_unused(input);

    unsigned short passed = 0;

    monitor_t *monitor = monitor_with_cursor_residence();

    window_t *window;
    while ((window = vector_iterator(windows))) {
        if (window->workspace != monitor->workspace)
            continue;

        if (window->id == focused_window) {
            if (passed)
                return; // only one window

            if (!windows->remaining)
                reset_vector_iterator(windows);

            passed = 1;
            continue;
        }

        if (passed) {
            reset_vector_iterator(windows);
            /* Focus on this window */
            xcb_window_t previous_window = focused_window;
            focused_window = window->id;

            xcb_ungrab_button(xcb_connection,
                XCB_BUTTON_INDEX_ANY, window->id, XCB_MOD_MASK_ANY);
            raise_window(window->parent);
            decorate(window);
            focus_window(window->id);

            if (previous_window != XCB_WINDOW_NONE) {
                window = get_window_by_id(previous_window);
                xcb_grab_button(xcb_connection, 0, previous_window,
                    XCB_EVENT_MASK_BUTTON_PRESS,
                    XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
                    XCB_NONE, XCB_NONE,
                    XCB_BUTTON_INDEX_ANY ^ \
                        XCB_BUTTON_INDEX_4 ^ XCB_BUTTON_INDEX_5,
                    XCB_MOD_MASK_ANY);
                decorate(window);
            }

            *screen_update = 1;
            return;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x12(%rbp)
callq 0x7b10
movq %rax, -0x20(%rbp)
leaq 0x8fd2(%rip), %rax      # 0xd8e8
movq (%rax), %rdi
callq 0x38c0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x4a65
movq -0x28(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x20(%rcx), %eax
je 0x493e
jmp 0x490f
movq -0x28(%rbp), %rax
movl (%rax), %eax
leaq 0x8fa5(%rip), %rcx      # 0xd8f0
cmpl (%rcx), %eax
jne 0x4982
cmpw $0x0, -0x12(%rbp)
je 0x495b
jmp 0x4a65
leaq 0x8f86(%rip), %rax      # 0xd8e8
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jne 0x497a
leaq 0x8f76(%rip), %rax      # 0xd8e8
movq (%rax), %rdi
callq 0x3970
movw $0x1, -0x12(%rbp)
jmp 0x490f
cmpw $0x0, -0x12(%rbp)
je 0x4a60
leaq 0x8f54(%rip), %rax      # 0xd8e8
movq (%rax), %rdi
callq 0x3970
leaq 0x8f4d(%rip), %rax      # 0xd8f0
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
leaq 0x8f3b(%rip), %rax      # 0xd8f0
movl %ecx, (%rax)
leaq 0x8f3a(%rip), %rax      # 0xd8f8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movl (%rax), %edx
xorl %esi, %esi
movl $0x8000, %ecx           # imm = 0x8000
callq 0x3510
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x9030
movq -0x28(%rbp), %rdi
callq 0x6430
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0x8f60
cmpl $0x0, -0x2c(%rbp)
je 0x4a55
movl -0x2c(%rbp), %edi
callq 0x8090
movq %rax, -0x28(%rbp)
leaq 0x8ee9(%rip), %rax      # 0xd8f8
movq (%rax), %rdi
movl -0x2c(%rbp), %edx
xorl %esi, %esi
movl $0x4, %ecx
movl $0x1, %r9d
movl %r9d, %r8d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movl $0x8000, 0x18(%rsp)     # imm = 0x8000
callq 0x3370
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rdi
callq 0x6430
movq -0x10(%rbp), %rax
movw $0x1, (%rax)
jmp 0x4a65
jmp 0x490f
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)