// File: /workspace/github_c_makefile_star2_O0/nkanaev[P]tipsy/src/tigr.c
// Function: tigrWindow
Tigr* tigrWindow(int w, int h, const char* title, int flags) {
    Tigr* bmp = 0;
    Colormap cmap;
    XSetWindowAttributes swa;
    Window xwin;
    GLXContext glc;
    XIC ic;
    int scale;

    initX11Stuff();

    if (flags & TIGR_AUTO) {
        // Always use a 1:1 pixel size, unless downscaled by tigrEnforceScale below.
        scale = 1;
    } else {
        // See how big we can make it and still fit on-screen.
        Screen* screen = DefaultScreenOfDisplay(dpy);
        int maxW = WidthOfScreen(screen);
        int maxH = HeightOfScreen(screen);
        scale = tigrCalcScale(w, h, maxW, maxH);
    }

    scale = tigrEnforceScale(scale, flags);

    cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
    swa.colormap = cmap;
    swa.event_mask = StructureNotifyMask;

    // Create window of wanted size
    xwin = XCreateWindow(dpy, root, 0, 0, w * scale, h * scale, 0, vi->depth, InputOutput, vi->visual,
                         CWColormap | CWEventMask, &swa);
    XMapWindow(dpy, xwin);

    if (flags & TIGR_FULLSCREEN) {
        // https://www.tonyobryan.com//index.php?article=9
        WindowHints hints;
        Atom property;
        hints.flags = 2;
        hints.decorations = 0;
        property = XInternAtom(dpy, "_MOTIF_WM_HINTS", True);
        XChangeProperty(dpy, xwin, property, property, 32, PropModeReplace, (unsigned char*)&hints, 5);
        int screen = DefaultScreen(dpy);
        int dWidth = DisplayWidth(dpy, screen);
        int dHeight = DisplayHeight(dpy, screen);
        XMoveResizeWindow(dpy, xwin, 0, 0, dWidth, dHeight);
        XMapRaised(dpy, xwin);
        XGrabPointer(dpy, xwin, True, 0, GrabModeAsync, GrabModeAsync, xwin, 0L, CurrentTime);
        XGrabKeyboard(dpy, xwin, False, GrabModeAsync, GrabModeAsync, CurrentTime);
    } else {
        // Wait for window to get mapped
        for (;;) {
            XEvent e;
            XNextEvent(dpy, &e);
            if (e.type == MapNotify) {
                break;
            }
        }

        // Reset size if we did not get the window size we wanted above.
        XWindowAttributes wa;
        XGetWindowAttributes(dpy, xwin, &wa);
        scale = tigrCalcScale(w, h, wa.width, wa.height);
        scale = tigrEnforceScale(scale, flags);
        XResizeWindow(dpy, xwin, w * scale, h * scale);
    }

    XTextProperty prop;
    int result = Xutf8TextListToTextProperty(dpy, (char**)&title, 1, XUTF8StringStyle, &prop);
    if (result == Success) {
        Atom wmName = XInternAtom(dpy, "_NET_WM_NAME", 0);
        XSetTextProperty(dpy, xwin, &prop, wmName);
        XFree(prop.value);
    }

    ic = XCreateIC(inputMethod, XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNClientWindow, xwin, NULL);
    if (ic == NULL) {
        printf("Failed to create input context\n");
        exit(0);
    }
    XSetICFocus(ic);

    XSetWMProtocols(dpy, xwin, &wmDeleteMessage, 1);

    glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);
    int contextAttributes[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 3, None };
    glc = glXCreateContextAttribsARB(dpy, fbConfig, NULL, GL_TRUE, contextAttributes);
    glXMakeCurrent(dpy, xwin, glc);

    setupVSync(dpy, xwin);

    bmp = tigrBitmap2(w, h, sizeof(TigrInternal));
    bmp->handle = (void*)xwin;

    TigrInternal* win = tigrInternal(bmp);
    win->win = xwin;
    win->dpy = dpy;
    win->glc = glc;
    win->ic = ic;

    win->shown = 0;
    win->closed = 0;
    win->scale = scale;

    win->lastChar = 0;
    win->flags = flags;
    win->p1 = win->p2 = win->p3 = 0;
    win->p4 = 1;
    win->widgetsWanted = 0;
    win->widgetAlpha = 0;
    win->widgetsScale = 0;
    win->widgets = 0;
    win->gl.gl_legacy = 0;

    memset(win->keys, 0, 256);
    memset(win->prev, 0, 256);

    if (flags & TIGR_NOCURSOR) {
        tigrHideCursor(win);
    }

    tigrPosition(bmp, win->scale, bmp->w, bmp->h, win->pos);
    tigrGAPICreate(bmp);
    tigrGAPIBegin(bmp);

    return bmp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq $0x0, -0x20(%rbp)
callq 0xa560
movl -0x14(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x6eec
movl $0x1, -0xb4(%rbp)
jmp 0x6f53
movq 0xd8fd(%rip), %rax      # 0x147f0
movq 0xe8(%rax), %rax
movq 0xd8ef(%rip), %rcx      # 0x147f0
movslq 0xe0(%rcx), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0xc4(%rbp)
movq -0xc0(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xc8(%rbp)
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0xc4(%rbp), %edx
movl -0xc8(%rbp), %ecx
callq 0x3ad0
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x3b40
movl %eax, -0xb4(%rbp)
movq 0xd882(%rip), %rdi      # 0x147f0
movq 0xd883(%rip), %rsi      # 0x147f8
movq 0xd884(%rip), %rax      # 0x14800
movq (%rax), %rdx
xorl %ecx, %ecx
callq 0x3240
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x20000, -0x50(%rbp)   # imm = 0x20000
movq 0xd84f(%rip), %rdi      # 0x147f0
movq 0xd850(%rip), %rsi      # 0x147f8
movl -0x4(%rbp), %r8d
imull -0xb4(%rbp), %r8d
movl -0x8(%rbp), %r9d
imull -0xb4(%rbp), %r9d
movq 0xd839(%rip), %rax      # 0x14800
movl 0x14(%rax), %r11d
movq 0xd82e(%rip), %rax      # 0x14800
movq (%rax), %r10
xorl %ecx, %ecx
leaq -0x98(%rbp), %rax
movl %ecx, %edx
movl $0x0, (%rsp)
movl %r11d, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq $0x2800, 0x20(%rsp)     # imm = 0x2800
movq %rax, 0x28(%rsp)
callq 0x3630
movq %rax, -0xa0(%rbp)
movq 0xd7d6(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
callq 0x33b0
movl -0x14(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x71a4
movq $0x2, -0xf0(%rbp)
movq $0x0, -0xe0(%rbp)
movq 0xd79e(%rip), %rdi      # 0x147f0
leaq 0x9451(%rip), %rsi      # 0x104aa
movl $0x1, %edx
callq 0x32a0
movq %rax, -0xf8(%rbp)
movq 0xd77f(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
movq -0xf8(%rbp), %rdx
movq -0xf8(%rbp), %rcx
movl $0x20, %r8d
xorl %r9d, %r9d
leaq -0xf0(%rbp), %rax
movq %rax, (%rsp)
movl $0x5, 0x8(%rsp)
callq 0x32f0
movq 0xd742(%rip), %rax      # 0x147f0
movl 0xe0(%rax), %eax
movl %eax, -0xfc(%rbp)
movq 0xd72f(%rip), %rax      # 0x147f0
movq 0xe8(%rax), %rax
movslq -0xfc(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
movl %eax, -0x100(%rbp)
movq 0xd70a(%rip), %rax      # 0x147f0
movq 0xe8(%rax), %rax
movslq -0xfc(%rbp), %rcx
shlq $0x7, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
movl %eax, -0x104(%rbp)
movq 0xd6e5(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
movl -0x100(%rbp), %r8d
movl -0x104(%rbp), %r9d
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x3300
movq 0xd6c0(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
callq 0x37b0
movq 0xd6ad(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
movq -0xa0(%rbp), %rax
movl $0x1, %r9d
xorl %ecx, %ecx
xorl %edx, %edx
movl %r9d, %edx
movl %r9d, %r8d
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x30f0
movq 0xd66d(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
xorl %edx, %edx
movl $0x1, %r8d
xorl %eax, %eax
movl %eax, %r9d
movl %r8d, %ecx
callq 0x3450
jmp 0x7238
jmp 0x71a6
movq 0xd643(%rip), %rdi      # 0x147f0
leaq -0x1c8(%rbp), %rsi
callq 0x35b0
cmpl $0x13, -0x1c8(%rbp)
jne 0x71c4
jmp 0x71c6
jmp 0x71a6
movq 0xd623(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
leaq -0x250(%rbp), %rdx
callq 0x3710
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0x248(%rbp), %edx
movl -0x244(%rbp), %ecx
callq 0x3ad0
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x3b40
movl %eax, -0xb4(%rbp)
movq 0xd5d8(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
movl -0x4(%rbp), %edx
imull -0xb4(%rbp), %edx
movl -0x8(%rbp), %ecx
imull -0xb4(%rbp), %ecx
callq 0x35e0
movq 0xd5b1(%rip), %rdi      # 0x147f0
leaq -0x10(%rbp), %rsi
movl $0x1, %edx
movl $0x4, %ecx
leaq -0x270(%rbp), %r8
callq 0x34b0
movl %eax, -0x274(%rbp)
cmpl $0x0, -0x274(%rbp)
jne 0x72b1
movq 0xd581(%rip), %rdi      # 0x147f0
leaq 0x9244(%rip), %rsi      # 0x104ba
xorl %edx, %edx
callq 0x32a0
movq %rax, -0x280(%rbp)
movq 0xd565(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
movq -0x280(%rbp), %rcx
leaq -0x270(%rbp), %rdx
callq 0x33d0
movq -0x270(%rbp), %rdi
callq 0x34a0
movq 0xd550(%rip), %rdi      # 0x14808
movq -0xa0(%rbp), %r8
leaq 0x9201(%rip), %rsi      # 0x104c7
movl $0x408, %edx            # imm = 0x408
leaq 0x9200(%rip), %rcx      # 0x104d2
xorl %eax, %eax
movl %eax, %r9d
movb $0x0, %al
callq 0x3310
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x7304
leaq 0x91e9(%rip), %rdi      # 0x104df
movb $0x0, %al
callq 0x3060
xorl %edi, %edi
callq 0x3420
movq -0xb0(%rbp), %rdi
callq 0x36a0
movq 0xd4d9(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
leaq 0xd4eb(%rip), %rdx      # 0x14810
movl $0x1, %ecx
callq 0x31e0
movq 0xd4ba(%rip), %rdi      # 0x147f0
movq 0xd4c3(%rip), %rsi      # 0x14800
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x3440
movq %rax, -0xa8(%rbp)
movq 0x9417(%rip), %rax      # 0x10770
movq %rax, -0x2a0(%rbp)
movq 0x9411(%rip), %rax      # 0x10778
movq %rax, -0x298(%rbp)
movl 0x940c(%rip), %eax      # 0x10780
movl %eax, -0x290(%rbp)
movq 0xd467(%rip), %rax      # 0x147e8
movq 0xd468(%rip), %rdi      # 0x147f0
movq 0xd489(%rip), %rsi      # 0x14818
leaq -0x2a0(%rbp), %r8
xorl %ecx, %ecx
movl %ecx, %edx
movl $0x1, %ecx
callq *%rax
movq %rax, -0xa8(%rbp)
movq 0xd441(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
callq 0x32c0
movq 0xd427(%rip), %rdi      # 0x147f0
movq -0xa0(%rbp), %rsi
callq 0x75c0
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl $0x2a0, %edx            # imm = 0x2A0
callq 0x38f0
movq %rax, -0x20(%rbp)
movq -0xa0(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rdi
callq 0x6e60
movq %rax, -0x2a8(%rbp)
movq -0xa0(%rbp), %rcx
movq -0x2a8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq 0xd3cf(%rip), %rcx      # 0x147f0
movq -0x2a8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0xa8(%rbp), %rcx
movq -0x2a8(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0xb0(%rbp), %rcx
movq -0x2a8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x2a8(%rbp), %rax
movl $0x0, (%rax)
movq -0x2a8(%rbp), %rax
movl $0x0, 0x4(%rax)
movl -0xb4(%rbp), %ecx
movq -0x2a8(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x2a8(%rbp), %rax
movl $0x0, 0x8c(%rax)
movl -0x14(%rbp), %ecx
movq -0x2a8(%rbp), %rax
movl %ecx, 0x74(%rax)
movq -0x2a8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x6c(%rax)
movq -0x2a8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x68(%rax)
movq -0x2a8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x64(%rax)
movq -0x2a8(%rbp), %rax
movss 0x7b2f(%rip), %xmm0     # 0xf004
movss %xmm0, 0x70(%rax)
movq -0x2a8(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x2a8(%rbp), %rax
movb $0x0, 0x5c(%rax)
movq -0x2a8(%rbp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x60(%rax)
movq -0x2a8(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x2a8(%rbp), %rax
movl $0x0, 0x24(%rax)
movq -0x2a8(%rbp), %rdi
addq $0x90, %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x31d0
movq -0x2a8(%rbp), %rdi
addq $0x190, %rdi            # imm = 0x190
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x31d0
movl -0x14(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x756a
movq -0x2a8(%rbp), %rdi
callq 0x7690
movq -0x20(%rbp), %rdi
movq -0x2a8(%rbp), %rax
movl 0x78(%rax), %esi
movq -0x20(%rbp), %rax
movl (%rax), %edx
movq -0x20(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x2a8(%rbp), %r8
addq $0x7c, %r8
callq 0x3ba0
movq -0x20(%rbp), %rdi
callq 0x7750
movq -0x20(%rbp), %rdi
callq 0x7940
movq -0x20(%rbp), %rax
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
nopw %cs:(%rax,%rax)