// File: /workspace/github_c_makefile_star2_O0/nkanaev[P]tipsy/src/tigr.c
// Function: tigrProcessInput
static void tigrProcessInput(TigrInternal* win, int winWidth, int winHeight) {
    {
        Window focused;
        int revertTo;
        XGetInputFocus(win->dpy, &focused, &revertTo);

        if (win->win != focused) {
            return;
        }
    }

    Window root;
    Window child;
    int rootX;
    int rootY;
    int winX;
    int winY;
    unsigned int mask;

    if (XQueryPointer(win->dpy, win->win, &root, &child, &rootX, &rootY, &winX, &winY, &mask)) {
        static unsigned int prevButtons;
        unsigned int buttons = mask & (Button1Mask | Button2Mask | Button3Mask);

        win->mouseX = (winX - win->pos[0]) / win->scale;
        win->mouseY = (winY - win->pos[1]) / win->scale;

        if (buttons != prevButtons && (winX > 0 && winX < winWidth) && (winY > 0 && winY < winHeight)) {
            win->mouseButtons = (buttons & Button1Mask)       ? 1
                                : 0 | (buttons & Button3Mask) ? 2
                                : 0 | (buttons & Button2Mask) ? 4
                                                              : 0;
        }
        prevButtons = buttons;
    }

    static char prevKeys[32];
    char keys[32];
    XQueryKeymap(win->dpy, keys);
    for (int i = 0; i < 32; i++) {
        char thisBlock = keys[i];
        char prevBlock = prevKeys[i];
        if (thisBlock != prevBlock) {
            for (int j = 0; j < 8; j++) {
                int thisBit = thisBlock & 1;
                int prevBit = prevBlock & 1;
                thisBlock >>= 1;
                prevBlock >>= 1;
                if (thisBit != prevBit) {
                    int keyCode = 8 * i + j;
                    KeySym keySym = XkbKeycodeToKeysym(win->dpy, keyCode, 0, 0);
                    if (keySym != NoSymbol) {
                        int key = tigrKeyFromX11(keySym);
                        win->keys[key] = thisBit;
                        tigrUpdateModifiers(win);

                        if (thisBit) {
                            tigrInterpretChar(win, root, keyCode, mask);
                        }
                    }
                }
            }
        }
    }
    memcpy(prevKeys, keys, 32);

    XEvent event;
    while (XCheckTypedWindowEvent(win->dpy, win->win, ClientMessage, &event)) {
        if (event.xclient.data.l[0] == wmDeleteMessage) {
            glXMakeCurrent(win->dpy, None, NULL);
            glXDestroyContext(win->dpy, win->glc);
            XDestroyWindow(win->dpy, win->win);
            win->win = 0;
        }
    }
    XFlush(win->dpy);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x18(%rbp), %rsi
leaq -0x1c(%rbp), %rdx
callq 0x36e0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x18(%rbp), %rax
je 0x870d
jmp 0x8a53
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
leaq -0x34(%rbp), %r8
leaq -0x38(%rbp), %r9
leaq -0x3c(%rbp), %r11
leaq -0x40(%rbp), %r10
leaq -0x44(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x33c0
cmpl $0x0, %eax
je 0x884d
movl -0x44(%rbp), %eax
andl $0x700, %eax            # imm = 0x700
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movq -0x8(%rbp), %rcx
subl 0x7c(%rcx), %eax
movq -0x8(%rbp), %rcx
cltd
idivl 0x78(%rcx)
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x294(%rax)
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
subl 0x80(%rcx), %eax
movq -0x8(%rbp), %rcx
cltd
idivl 0x78(%rcx)
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x298(%rax)
movl -0x48(%rbp), %eax
cmpl 0xc08c(%rip), %eax      # 0x14834
je 0x8844
cmpl $0x0, -0x3c(%rbp)
jle 0x8844
movl -0x3c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x8844
cmpl $0x0, -0x40(%rbp)
jle 0x8844
movl -0x40(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x8844
movl -0x48(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x87ec
movl $0x1, %eax
movl %eax, -0x15c(%rbp)
jmp 0x8834
movl -0x48(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
orl $0x0, %eax
cmpl $0x0, %eax
je 0x8809
movl $0x2, %eax
movl %eax, -0x160(%rbp)
jmp 0x8828
movl -0x48(%rbp), %edx
andl $0x200, %edx            # imm = 0x200
orl $0x0, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x160(%rbp)
movl -0x160(%rbp), %eax
movl %eax, -0x15c(%rbp)
movl -0x15c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x290(%rax)
movl -0x48(%rbp), %eax
movl %eax, 0xbfe7(%rip)      # 0x14834
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3430
movl $0x0, -0x74(%rbp)
cmpl $0x20, -0x74(%rbp)
jge 0x8995
movslq -0x74(%rbp), %rax
movb -0x70(%rbp,%rax), %al
movb %al, -0x75(%rbp)
movslq -0x74(%rbp), %rcx
leaq 0xbfbb(%rip), %rax      # 0x14840
movb (%rax,%rcx), %al
movb %al, -0x76(%rbp)
movsbl -0x75(%rbp), %eax
movsbl -0x76(%rbp), %ecx
cmpl %ecx, %eax
je 0x8985
movl $0x0, -0x7c(%rbp)
cmpl $0x8, -0x7c(%rbp)
jge 0x8983
movsbl -0x75(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x80(%rbp)
movsbl -0x76(%rbp), %eax
andl $0x1, %eax
movl %eax, -0x84(%rbp)
movsbl -0x75(%rbp), %eax
sarl %eax
movb %al, -0x75(%rbp)
movsbl -0x76(%rbp), %eax
sarl %eax
movb %al, -0x76(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x84(%rbp), %eax
je 0x8973
movl -0x74(%rbp), %eax
shll $0x3, %eax
addl -0x7c(%rbp), %eax
movl %eax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x88(%rbp), %eax
xorl %ecx, %ecx
movzbl %al, %esi
movl %ecx, %edx
callq 0x3130
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x90(%rbp)
je 0x8971
movq -0x90(%rbp), %rdi
callq 0x7b20
movzbl %al, %eax
movl %eax, -0x94(%rbp)
movl -0x80(%rbp), %eax
movb %al, %dl
movq -0x8(%rbp), %rax
movslq -0x94(%rbp), %rcx
movb %dl, 0x90(%rax,%rcx)
movq -0x8(%rbp), %rdi
callq 0xa7c0
cmpl $0x0, -0x80(%rbp)
je 0x896f
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x88(%rbp), %edx
movl -0x44(%rbp), %ecx
callq 0xa890
jmp 0x8971
jmp 0x8973
jmp 0x8975
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x88a2
jmp 0x8985
jmp 0x8987
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x8865
movq -0x70(%rbp), %rax
movq %rax, 0xbea0(%rip)      # 0x14840
movq -0x68(%rbp), %rax
movq %rax, 0xbe9d(%rip)      # 0x14848
movq -0x60(%rbp), %rax
movq %rax, 0xbe9a(%rip)      # 0x14850
movq -0x58(%rbp), %rax
movq %rax, 0xbe97(%rip)      # 0x14858
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
movl $0x21, %edx
leaq -0x158(%rbp), %rcx
callq 0x3510
cmpl $0x0, %eax
je 0x8a46
movq -0x120(%rbp), %rax
cmpq 0xbe1b(%rip), %rax      # 0x14810
jne 0x8a41
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x32c0
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
callq 0x3250
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rsi
callq 0x3660
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
jmp 0x89c1
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x3620
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
nopl (%rax)