// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl 0x9552(%rip), %edi      # 0xd2b0
callq 0x2070
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x3d95
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movl $0x4, %edi
leaq 0x63f4(%rip), %rsi      # 0xa182
movb $0x0, %al
callq 0x3020
cmpq $0x0, -0x8(%rbp)
je 0x4232
movq -0x8(%rbp), %rdi
callq 0x7b20
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3dd0
movq -0x8(%rbp), %rdx
movl $0x2, %edi
leaq 0x63d2(%rip), %rsi      # 0xa196
movb $0x0, %al
callq 0x3020
jmp 0x4230
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdx
movl $0x4, %edi
leaq 0x63c4(%rip), %rsi      # 0xa1c9
movb $0x0, %al
callq 0x3020
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x422e
leaq 0x63bc(%rip), %rdi      # 0xa1e2
movl $0xa, %esi
callq 0x74c0
movl %eax, -0x2c(%rbp)
leaq 0x63bb(%rip), %rdi      # 0xa1f5
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x74c0
movl %eax, -0x30(%rbp)
leaq 0x63bb(%rip), %rdi      # 0xa209
xorl %esi, %esi
callq 0x5480
movl %eax, -0x34(%rbp)
leaq 0x63b7(%rip), %rdi      # 0xa216
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5480
movl %eax, -0x38(%rbp)
leaq 0x63ae(%rip), %rdi      # 0xa221
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5480
movl %eax, -0x3c(%rbp)
leaq 0x63b1(%rip), %rdi      # 0xa238
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x74c0
movl %eax, -0x40(%rbp)
leaq 0x63be(%rip), %rdi      # 0xa259
xorl %esi, %esi
callq 0x74c0
movl %eax, -0x44(%rbp)
leaq 0x63c6(%rip), %rdi      # 0xa272
xorl %esi, %esi
callq 0x74c0
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x18(%rax)
leaq 0x63be(%rip), %rdi      # 0xa288
xorl %esi, %esi
callq 0x74c0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x810(%rax)
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
movl -0x34(%rbp), %esi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %r8d
movq -0x28(%rbp), %rax
movl 0x20(%rax), %r9d
movl $0x2, %ecx
callq 0x6820
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
callq 0x7b80
movq -0x28(%rbp), %rdi
addq $0x68, %rdi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
callq 0x6ab0
movq -0x28(%rbp), %rdi
addq $0x98, %rdi
callq 0x7c50
movq -0x28(%rbp), %rax
cmpl $0x80000000, 0x1c(%rax) # imm = 0x80000000
je 0x403d
leaq 0x92c4(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x9370(%rip), %rax      # 0xd2d0
cmpq $0x0, %rax
jne 0x3f79
leaq 0x534a(%rip), %rdi      # 0x92b7
callq 0x3640
movq %rax, 0x9357(%rip)      # 0xd2d0
leaq 0x9298(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x9344(%rip), %rax      # 0xd2d0
cmpq $0x0, %rax
je 0x3fca
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %edx
movl $0x3, %edi
leaq 0x62f7(%rip), %rsi      # 0xa29c
movb $0x0, %al
callq 0x3020
movq 0x931d(%rip), %rax      # 0xd2d0
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rsi
movq -0x28(%rbp), %rcx
movl 0x1c(%rcx), %edx
callq *%rax
jmp 0x403b
leaq 0x9247(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x92fb(%rip), %rax      # 0xd2d8
cmpq $0x0, %rax
jne 0x3ff6
leaq 0x52e0(%rip), %rdi      # 0x92ca
callq 0x3640
movq %rax, 0x92e2(%rip)      # 0xd2d8
leaq 0x921b(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x92c7(%rip), %rax      # 0xd2d0
cmpq $0x0, %rax
je 0x4039
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %edx
movl $0x3, %edi
leaq 0x627a(%rip), %rsi      # 0xa29c
movb $0x0, %al
callq 0x3020
movq 0x92a8(%rip), %rax      # 0xd2d8
movq -0x28(%rbp), %rcx
movl 0x1c(%rcx), %edi
callq *%rax
jmp 0x403b
jmp 0x403d
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x422c
leaq 0x91c1(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x9245(%rip), %rax      # 0xd2a8
cmpq $0x0, %rax
jne 0x407c
leaq 0x5134(%rip), %rdi      # 0x91a4
callq 0x3640
movq %rax, 0x922c(%rip)      # 0xd2a8
leaq 0x9195(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x9219(%rip), %rax      # 0xd2a8
cmpq $0x0, %rax
je 0x40c1
movq 0x920c(%rip), %rax      # 0xd2a8
movq -0x28(%rbp), %rsi
leaq 0x359(%rip), %rdi       # 0x4400
callq *%rax
movl $0x3, %edi
leaq 0x6204(%rip), %rsi      # 0xa2b9
movb $0x0, %al
callq 0x3020
jmp 0x422a
leaq 0x9150(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x91e4(%rip), %rax      # 0xd2b8
cmpq $0x0, %rax
jne 0x40ed
leaq 0x512b(%rip), %rdi      # 0x920c
callq 0x3640
movq %rax, 0x91cb(%rip)      # 0xd2b8
leaq 0x9124(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x91b8(%rip), %rax      # 0xd2b8
cmpq $0x0, %rax
je 0x4132
movq 0x91ab(%rip), %rax      # 0xd2b8
movq -0x28(%rbp), %rsi
leaq 0x2e8(%rip), %rdi       # 0x4400
callq *%rax
movl $0x3, %edi
leaq 0x61b4(%rip), %rsi      # 0xa2da
movb $0x0, %al
callq 0x3020
jmp 0x4228
leaq 0x90df(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x917b(%rip), %rax      # 0xd2c0
cmpq $0x0, %rax
jne 0x415e
leaq 0x50f3(%rip), %rdi      # 0x9245
callq 0x3640
movq %rax, 0x9162(%rip)      # 0xd2c0
leaq 0x90b3(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x914f(%rip), %rax      # 0xd2c0
cmpq $0x0, %rax
je 0x41a3
movq 0x9142(%rip), %rax      # 0xd2c0
movq -0x28(%rbp), %rsi
leaq 0x277(%rip), %rdi       # 0x4400
callq *%rax
movl $0x3, %edi
leaq 0x6163(%rip), %rsi      # 0xa2fa
movb $0x0, %al
callq 0x3020
jmp 0x4226
leaq 0x906e(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x9112(%rip), %rax      # 0xd2c8
cmpq $0x0, %rax
jne 0x41cf
leaq 0x50bb(%rip), %rdi      # 0x927e
callq 0x3640
movq %rax, 0x90f9(%rip)      # 0xd2c8
leaq 0x9042(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x90e6(%rip), %rax      # 0xd2c8
cmpq $0x0, %rax
je 0x4211
movq 0x90d9(%rip), %rax      # 0xd2c8
movq -0x28(%rbp), %rsi
leaq 0x5a6(%rip), %rdi       # 0x47a0
callq *%rax
movl $0x3, %edi
leaq 0x6112(%rip), %rsi      # 0xa31a
movb $0x0, %al
callq 0x3020
jmp 0x4224
movl $0x2, %edi
leaq 0x611d(%rip), %rsi      # 0xa33a
movb $0x0, %al
callq 0x3020
jmp 0x4226
jmp 0x4228
jmp 0x422a
jmp 0x422c
jmp 0x422e
jmp 0x4230
jmp 0x423a
movq $0x0, -0x28(%rbp)
movl 0x9070(%rip), %edi      # 0xd2b0
movq -0x28(%rbp), %rsi
callq 0x21b0
addq $0x50, %rsp
popq %rbp
retq
nop