// File: /workspace/github_c_makefile_star2_O1/derhass[P]glx_hook/glx_hook.c
// Function: make_current
static void
make_current(GLXContext ctx, Display *dpy, GLXDrawable draw, GLXDrawable read)
{
	gl_context_t *glc;

	glc=(gl_context_t*)pthread_getspecific(ctx_current);
	if (glc) {
		/* old context */
		glc->flags &= ~GH_GL_CURRENT;
		GH_verbose(GH_MSG_DEBUG, "unbound context %p\n",glc->ctx);
	}
	
	if (ctx) {
		glc=find_ctx(ctx);

		if (glc == NULL) {
			GH_verbose(GH_MSG_WARNING, "app tried to make current non-existing context %p\n",ctx);
		} else {
			glc->draw=draw;
			glc->read=read;
			glc->flags |= GH_GL_CURRENT;
			GH_verbose(GH_MSG_DEBUG, "made current context %p\n",ctx);
			if (glc->flags & GH_GL_NEVER_CURRENT) {
				unsigned int ft_delay=get_envui("GH_FRAMETIME_DELAY", 10);
				unsigned int ft_frames=get_envui("GH_FRAMETIME_FRAMES", 1000);
				GH_frametime_mode ft_mode=(GH_frametime_mode)get_envi("GH_FRAMETIME", (int)GH_FRAMETIME_NONE);
				int latency=get_envi("GH_LATENCY", GH_LATENCY_NOP);
				int latency_manual_wait=get_envi("GH_LATENCY_MANUAL_WAIT", -1);
				unsigned int latency_gl_wait_timeout=get_envui("GH_LATENCY_GL_WAIT_TIMEOUT_USECS", 1000000);
				unsigned int latency_gl_wait_interval=get_envui("GH_LATENCY_GL_WAIT_USECS", 0);
				unsigned int latency_self_wait_interval=get_envui("GH_LATENCY_WAIT_USECS", 0);
				/* made current for the first time */
				glc->flags &= ~ GH_GL_NEVER_CURRENT;

				glc->swap_sleep_usecs=(useconds_t)get_envui("GH_SWAP_SLEEP_USECS",0);
				frametimes_init(&glc->frametimes, ft_mode, ft_delay, GH_FRAMETIME_COUNT, ft_frames, glc->num);
				frametimes_init_base(&glc->frametimes);
				latency_init(&glc->latency, latency, latency_manual_wait, latency_gl_wait_timeout, latency_gl_wait_interval, latency_self_wait_interval);
				swapbuffer_omission_init_gl(&glc->swapbuffer_omission);
				if (glc->inject_swapinterval != GH_SWAP_DONT_SET) {
					GH_GET_PTR_GL(glXSwapIntervalEXT);
					if (GH_glXSwapIntervalEXT) {
						GH_verbose(GH_MSG_INFO, "injecting swap interval: %d\n",
								glc->inject_swapinterval);
						GH_glXSwapIntervalEXT(dpy, glc->draw, glc->inject_swapinterval);
					} else {
						GH_GET_PTR_GL(glXSwapIntervalSGI);
						if (GH_glXSwapIntervalEXT) {
							GH_verbose(GH_MSG_INFO, "injecting swap interval: %d\n",
									glc->inject_swapinterval);
							GH_glXSwapIntervalSGI(glc->inject_swapinterval);
						}
					}
				}
				if (glc->flags & GH_GL_INJECT_DEBUG) {
					GH_GET_PTR_GL(glDebugMessageCallback);
					if (GH_glDebugMessageCallback) {
						GH_glDebugMessageCallback(GH_debug_callback, glc);
						GH_verbose(GH_MSG_INFO, "injecting debug callback [core]\n");
					} else {
						GH_GET_PTR_GL(glDebugMessageCallbackARB);
						if (GH_glDebugMessageCallbackARB) {
							GH_glDebugMessageCallbackARB(GH_debug_callback, glc);
							GH_verbose(GH_MSG_INFO, "injecting debug callback [ARB]\n");
						} else {
							GH_GET_PTR_GL(glDebugMessageCallbackKHR);
							if (GH_glDebugMessageCallbackKHR) {
								GH_glDebugMessageCallbackKHR(GH_debug_callback, glc);
								GH_verbose(GH_MSG_INFO, "injecting debug callback [KHR]\n");
							} else {
								GH_GET_PTR_GL(glDebugMessageCallbackAMD);
								if (GH_glDebugMessageCallbackAMD) {
									GH_glDebugMessageCallbackAMD(GH_debug_callback_AMD, glc);
									GH_verbose(GH_MSG_INFO, "injecting debug callback [AMD]\n");
								} else {
									GH_verbose(GH_MSG_WARNING, "failed ot iject debug message callback\n");
								}
							}
						}
					}
				}
			}
		}
	} else {
		glc=NULL;
	}

	pthread_setspecific(ctx_current, glc);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %r14
movl 0x6ca8(%rip), %edi      # 0xb208
callq 0x2070
testq %rax, %rax
je 0x4584
andb $-0x2, 0x18(%rax)
movq (%rax), %rdx
leaq 0x3bfa(%rip), %rsi      # 0x8172
movl $0x4, %edi
xorl %eax, %eax
callq 0x2c88
testq %r14, %r14
je 0x4a0f
leaq 0x6cfc(%rip), %rdi      # 0xb290
callq 0x21a0
movq 0x6d70(%rip), %rbx      # 0xb310
testq %rbx, %rbx
je 0x45b0
cmpq %r14, (%rbx)
je 0x45b0
movq 0x28(%rbx), %rbx
jmp 0x45a0
leaq 0x6cd9(%rip), %rdi      # 0xb290
callq 0x2120
testq %rbx, %rbx
je 0x4a16
movq %r12, 0x8(%rbx)
movq %r15, 0x10(%rbx)
orb $0x1, 0x18(%rbx)
leaq 0x3be1(%rip), %rsi      # 0x81b9
movl $0x4, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2c88
testb $0x2, 0x18(%rbx)
je 0x4cf6
leaq 0x3bda(%rip), %rdi      # 0x81d2
movl $0xa, %esi
callq 0x6613
movl %eax, %ebp
leaq 0x3bda(%rip), %rdi      # 0x81e5
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x6613
movl %eax, %r15d
leaq 0x3bda(%rip), %rdi      # 0x81f9
xorl %esi, %esi
callq 0x5b7d
movl %eax, %r12d
leaq 0x3bd6(%rip), %rdi      # 0x8206
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5b7d
movl %eax, 0x14(%rsp)
leaq 0x3bcc(%rip), %rdi      # 0x8211
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5b7d
movl %eax, 0x10(%rsp)
leaq 0x3bce(%rip), %rdi      # 0x8228
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x6613
movl %eax, 0xc(%rsp)
leaq 0x3bda(%rip), %rdi      # 0x8249
xorl %esi, %esi
callq 0x6613
movl %eax, 0x8(%rsp)
leaq 0x3be1(%rip), %rdi      # 0x8262
xorl %esi, %esi
callq 0x6613
movl %eax, %r14d
andb $-0x3, 0x18(%rbx)
leaq 0x3be2(%rip), %rdi      # 0x8278
xorl %esi, %esi
callq 0x6613
movl %eax, 0x810(%rbx)
leaq 0x30(%rbx), %rdi
movl 0x20(%rbx), %r9d
movl %r12d, %esi
movl %ebp, %edx
movl $0x2, %ecx
movl %r15d, %r8d
callq 0x5e91
movl 0x30(%rbx), %edx
testl %edx, %edx
je 0x477e
movq %r13, 0x18(%rsp)
movq 0x50(%rbx), %rbp
movl 0x38(%rbx), %eax
imull 0x3c(%rbx), %eax
leaq (%rax,%rax,2), %r13
leaq (,%r13,8), %r15
addq %rbp, %r15
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r12
movups %xmm0, 0xc(%r12)
movaps %xmm0, (%r12)
movq %r12, %rdi
movq %r15, %rsi
callq 0x67cd
movl 0x30(%rbx), %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x67cd
cmpl $0x2, 0x38(%rbx)
jb 0x4747
leaq 0x18(,%r13,8), %rax
addq %rbp, %rax
movl $0x1, %ecx
movq 0x10(%r15), %rdx
movq %rdx, 0x10(%rax)
movups (%r15), %xmm0
movups %xmm0, (%rax)
incq %rcx
movl 0x38(%rbx), %edx
addq $0x18, %rax
cmpq %rdx, %rcx
jb 0x4729
cmpl $0x0, 0x38(%rsp)
setne %cl
movq 0x6b82(%rip), %rax      # 0xb2d8
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x4779
leaq 0x38(%rsp), %r15
movl $0x1, %edi
movq %r15, %rsi
callq *%rax
movl $0x0, (%r15)
movq 0x18(%rsp), %r13
leaq 0x68(%rbx), %rdi
movl 0x14(%rsp), %esi
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
movl %r14d, %r9d
callq 0x6301
cmpq $0x0, 0xb8(%rbx)
je 0x4a9a
leaq 0x69c0(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x6b13(%rip)      # 0xb2d0
jne 0x4808
leaq 0x69aa(%rip), %r14      # 0xb170
movq %r14, %rdi
callq 0x2120
leaq 0x36a9(%rip), %r15      # 0x7e7e
movq %r15, %rdi
callq 0x5d53
movq %rax, %r12
leaq 0x2daf(%rip), %rsi      # 0x7596
movl $0x4, %edi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
movq %r14, %rdi
callq 0x21a0
movq %r12, 0x6ac8(%rip)      # 0xb2d0
leaq 0x6961(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x6ab4(%rip)      # 0xb2d0
je 0x4a33
leaq 0x6947(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x6aa2(%rip)      # 0xb2d8
jne 0x4881
leaq 0x6931(%rip), %r14      # 0xb170
movq %r14, %rdi
callq 0x2120
leaq 0x3650(%rip), %r15      # 0x7e9e
movq %r15, %rdi
callq 0x5d53
movq %rax, %r12
leaq 0x2d36(%rip), %rsi      # 0x7596
movl $0x4, %edi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
movq %r14, %rdi
callq 0x21a0
movq %r12, 0x6a57(%rip)      # 0xb2d8
leaq 0x68e8(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x6a43(%rip)      # 0xb2d8
je 0x4a3c
leaq 0x68ce(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x6a31(%rip)      # 0xb2e0
jne 0x48fa
leaq 0x68b8(%rip), %r14      # 0xb170
movq %r14, %rdi
callq 0x2120
leaq 0x35e7(%rip), %r15      # 0x7eae
movq %r15, %rdi
callq 0x5d53
movq %rax, %r12
leaq 0x2cbd(%rip), %rsi      # 0x7596
movl $0x4, %edi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
movq %r14, %rdi
callq 0x21a0
movq %r12, 0x69e6(%rip)      # 0xb2e0
leaq 0x686f(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x69d2(%rip)      # 0xb2e0
je 0x4a45
leaq 0x6855(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x69c0(%rip)      # 0xb2e8
jne 0x4973
leaq 0x683f(%rip), %r14      # 0xb170
movq %r14, %rdi
callq 0x2120
leaq 0x357e(%rip), %r15      # 0x7ebe
movq %r15, %rdi
callq 0x5d53
movq %rax, %r12
leaq 0x2c44(%rip), %rsi      # 0x7596
movl $0x4, %edi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
movq %r14, %rdi
callq 0x21a0
movq %r12, 0x6975(%rip)      # 0xb2e8
leaq 0x67f6(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x6961(%rip)      # 0xb2e8
je 0x4a4e
leaq 0x67dc(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x694f(%rip)      # 0xb2f0
jne 0x49ec
leaq 0x67c6(%rip), %r14      # 0xb170
movq %r14, %rdi
callq 0x2120
leaq 0x3514(%rip), %r15      # 0x7ecd
movq %r15, %rdi
callq 0x5d53
movq %rax, %r12
leaq 0x2bcb(%rip), %rsi      # 0x7596
movl $0x4, %edi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2c88
movq %r14, %rdi
callq 0x21a0
movq %r12, 0x6904(%rip)      # 0xb2f0
leaq 0x677d(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x68f0(%rip)      # 0xb2f0
jne 0x4a9a
leaq 0x34c0(%rip), %rdx      # 0x7ecd
jmp 0x4a55
xorl %ebx, %ebx
jmp 0x4cf6
leaq 0x3769(%rip), %rsi      # 0x8186
xorl %ebx, %ebx
movl $0x2, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2c88
jmp 0x4cf6
leaq 0x3444(%rip), %rdx      # 0x7e7e
jmp 0x4a55
leaq 0x345b(%rip), %rdx      # 0x7e9e
jmp 0x4a55
leaq 0x3462(%rip), %rdx      # 0x7eae
jmp 0x4a55
leaq 0x3469(%rip), %rdx      # 0x7ebe
leaq 0x342f(%rip), %rsi      # 0x7e8b
movl $0x2, %edi
xorl %eax, %eax
callq 0x2c88
leaq 0x38e3(%rip), %rsi      # 0x8352
movl $0x2, %edi
xorl %eax, %eax
callq 0x2c88
movq $0x0, 0xb8(%rbx)
leaq 0x35a3(%rip), %rdi      # 0x8030
xorl %esi, %esi
callq 0x5b7d
movl %eax, 0x98(%rbx)
xorl %eax, %eax
cmpl 0x1c(%rbx), %eax
jo 0x4b70
leaq 0x66c4(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x676f(%rip)      # 0xb228
jne 0x4ace
leaq 0x27e5(%rip), %rdi      # 0x72a7
callq 0x3b1e
movq %rax, 0x675a(%rip)      # 0xb228
leaq 0x669b(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x6746(%rip)      # 0xb228
je 0x4b0f
movl 0x1c(%rbx), %edx
leaq 0x379e(%rip), %rsi      # 0x828c
movl $0x3, %edi
xorl %eax, %eax
callq 0x2c88
movq 0x6727(%rip), %rax      # 0xb228
movq 0x8(%rbx), %rsi
movl 0x1c(%rbx), %edx
movq %r13, %rdi
callq *%rax
jmp 0x4b70
leaq 0x665a(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x670d(%rip)      # 0xb230
jne 0x4b38
leaq 0x278e(%rip), %rdi      # 0x72ba
callq 0x3b1e
movq %rax, 0x66f8(%rip)      # 0xb230
leaq 0x6631(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x66dc(%rip)      # 0xb228
je 0x4b70
movl 0x1c(%rbx), %edx
leaq 0x3734(%rip), %rsi      # 0x828c
movl $0x3, %edi
xorl %eax, %eax
callq 0x2c88
movq 0x66c5(%rip), %rax      # 0xb230
movl 0x1c(%rbx), %edi
callq *%rax
testb $0x8, 0x18(%rbx)
je 0x4cf6
leaq 0x65ef(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x6672(%rip)      # 0xb200
jne 0x4ba3
leaq 0x25fd(%rip), %rdi      # 0x7194
callq 0x3b1e
movq %rax, 0x665d(%rip)      # 0xb200
leaq 0x65c6(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x6649(%rip)      # 0xb200
je 0x4bd8
movq 0x6640(%rip), %rax      # 0xb200
leaq 0x28d(%rip), %rdi       # 0x4e54
movq %rbx, %rsi
callq *%rax
leaq 0x36d6(%rip), %rsi      # 0x82a9
jmp 0x4cea
leaq 0x6591(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x6624(%rip)      # 0xb210
jne 0x4c01
leaq 0x2607(%rip), %rdi      # 0x71fc
callq 0x3b1e
movq %rax, 0x660f(%rip)      # 0xb210
leaq 0x6568(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x65fb(%rip)      # 0xb210
je 0x4c36
movq 0x65f2(%rip), %rax      # 0xb210
leaq 0x22f(%rip), %rdi       # 0x4e54
movq %rbx, %rsi
callq *%rax
leaq 0x3699(%rip), %rsi      # 0x82ca
jmp 0x4cea
leaq 0x6533(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x65ce(%rip)      # 0xb218
jne 0x4c5f
leaq 0x25e2(%rip), %rdi      # 0x7235
callq 0x3b1e
movq %rax, 0x65b9(%rip)      # 0xb218
leaq 0x650a(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x65a5(%rip)      # 0xb218
je 0x4c91
movq 0x659c(%rip), %rax      # 0xb218
leaq 0x1d1(%rip), %rdi       # 0x4e54
movq %rbx, %rsi
callq *%rax
leaq 0x365b(%rip), %rsi      # 0x82ea
jmp 0x4cea
leaq 0x64d8(%rip), %rdi      # 0xb170
callq 0x21a0
cmpq $0x0, 0x657b(%rip)      # 0xb220
jne 0x4cba
leaq 0x25c0(%rip), %rdi      # 0x726e
callq 0x3b1e
movq %rax, 0x6566(%rip)      # 0xb220
leaq 0x64af(%rip), %rdi      # 0xb170
callq 0x2120
cmpq $0x0, 0x6552(%rip)      # 0xb220
je 0x4d13
movq 0x6549(%rip), %rax      # 0xb220
leaq 0x4e0(%rip), %rdi       # 0x51be
movq %rbx, %rsi
callq *%rax
leaq 0x3620(%rip), %rsi      # 0x830a
movl $0x3, %edi
xorl %eax, %eax
callq 0x2c88
movl 0x650c(%rip), %edi      # 0xb208
movq %rbx, %rsi
callq 0x21b0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3610(%rip), %rsi      # 0x832a
movl $0x2, %edi
jmp 0x4cef