// File: gatecat[P]subprime/subprime.cpp
// Function: (anonymous namespace)::lookup_drawable(_XDisplay*, unsigned long, __GLXFBConfigRec*)
EGLSurface lookup_drawable(Display *dpy, GLXDrawable drawable, GLXFBConfig cfg = nullptr) {
	if (drawable2surface.count(drawable))
		return drawable2surface.at(drawable).egl_sfc;
	// Create a new backing PBuffer
	EGLDisplay dp = disp();
	EGLConfig egl_cfg;
	if (cfg == nullptr) {
		get_config(dp, &egl_cfg);
	} else {
		egl_cfg = *reinterpret_cast<EGLConfig*>(cfg);
	}
	unsigned width, height;
	std::tie(width, height) = get_drawable_dims(dpy, drawable);
	std::vector<int> attrs{EGL_WIDTH, int(width), EGL_HEIGHT, int(height), EGL_NONE};
	EGLSurface surface = fn_eglCreatePbufferSurface(dp, egl_cfg, attrs.data());
	drawable2surface[drawable].egl_sfc = surface;
	drawable2surface[drawable].width = width;
	drawable2surface[drawable].height = height;
	drawable2surface[drawable].cfg = cfg;
	return surface;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x108(%rsp)
movq %rsi, 0x100(%rsp)
movq %rdx, 0xf8(%rsp)
leaq 0x10b7a(%rip), %rdi     # 0x2b080
leaq 0x100(%rsp), %rsi
callq 0x1a810
cmpq $0x0, %rax
je 0x1a53d
leaq 0x10b60(%rip), %rdi     # 0x2b080
leaq 0x100(%rsp), %rsi
callq 0x1a840
movq (%rax), %rax
movq %rax, 0x110(%rsp)
jmp 0x1a7ea
callq 0x1a260
movq %rax, 0xf0(%rsp)
cmpq $0x0, 0xf8(%rsp)
jne 0x1a56c
movq 0xf0(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x1a390
jmp 0x1a57f
movq 0xf8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0xe8(%rsp)
movq 0x108(%rsp), %rdi
movq 0x100(%rsp), %rsi
callq 0x1a870
movq %rax, 0xd8(%rsp)
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x60(%rsp)
leaq 0xe4(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x165e0
movq 0x60(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x15e10
movl $0x3057, 0x8c(%rsp) # imm = 0x3057
movl 0xe4(%rsp), %eax
movl %eax, 0x90(%rsp)
movl $0x3056, 0x94(%rsp) # imm = 0x3056
movl 0xe0(%rsp), %eax
movl %eax, 0x98(%rsp)
movl $0x3038, 0x9c(%rsp) # imm = 0x3038
leaq 0x8c(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq $0x5, 0xa8(%rsp)
leaq 0x8b(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x15730
movq 0x68(%rsp), %rcx
movq 0xa0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
callq 0x16ca0
jmp 0x1a65f
leaq 0x8b(%rsp), %rdi
callq 0x151c0
movq 0x10b8d(%rip), %rax     # 0x2b200
movq %rax, 0x50(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x161b0
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rax, %rdx
movq 0x50(%rsp), %rax
callq *%rax
movq %rax, 0x58(%rsp)
jmp 0x1a6ba
movq 0x58(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x109ab(%rip), %rdi     # 0x2b080
leaq 0x100(%rsp), %rsi
callq 0x1a8f0
movq %rax, 0x38(%rsp)
jmp 0x1a6e9
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, (%rax)
movl 0xe4(%rsp), %eax
movl %eax, 0x24(%rsp)
leaq 0x10978(%rip), %rdi     # 0x2b080
leaq 0x100(%rsp), %rsi
callq 0x1a8f0
movq %rax, 0x28(%rsp)
jmp 0x1a71c
movq 0x28(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, 0x8(%rax)
movl 0xe0(%rsp), %eax
movl %eax, 0x14(%rsp)
leaq 0x10946(%rip), %rdi     # 0x2b080
leaq 0x100(%rsp), %rsi
callq 0x1a8f0
movq %rax, 0x18(%rsp)
jmp 0x1a74e
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
movl %ecx, 0xc(%rax)
movq 0xf8(%rsp), %rax
movq %rax, (%rsp)
leaq 0x10913(%rip), %rdi     # 0x2b080
leaq 0x100(%rsp), %rsi
callq 0x1a8f0
movq %rax, 0x8(%rsp)
jmp 0x1a781
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x70(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x15bb0
jmp 0x1a7ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0x8b(%rsp), %rdi
callq 0x151c0
jmp 0x1a7fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x80(%rsp)
movl %eax, 0x7c(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x15bb0
jmp 0x1a7fa
movq 0x110(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x80(%rsp), %rdi
callq 0x16bc0
nopw (%rax,%rax)