// File: /workspace/github_c_makefile_star2_O1/derhass[P]glx_hook/glx_hook.c
// Function: GH_get_interceptor
static void* GH_get_interceptor(const char *name, GH_resolve_func query,
				const char *query_name )
{
#define GH_INTERCEPT(func) \
       	if (!strcmp(#func, name)) {\
		pthread_mutex_lock(&GH_fptr_mutex); \
		if ( (GH_ ##func == NULL) && query) { \
			GH_ ##func = query(#func); \
			GH_verbose(GH_MSG_DEBUG,"queried internal %s via %s: %p\n", \
				name,query_name, GH_ ##func); \
		} \
		pthread_mutex_unlock(&GH_fptr_mutex); \
		return func; \
	}

#ifdef GH_SWAPBUFFERS_INTERCEPT
	static int do_swapbuffers=0;
#endif
	static int do_dlsym = 0;
#if (GH_DLSYM_METHOD != 2)
	static int do_dlvsym = 0;
#endif
	static int inited = 0;

	if (!inited) {
#ifdef GH_SWAPBUFFERS_INTERCEPT
		do_swapbuffers =get_envi("GH_SWAPBUFFERS", 0) ||
				get_envi("GH_FRAMETIME", 0) ||
				get_envi("GH_SWAP_SLEEP_USECS", 0) ||
				(get_envi("GH_LATENCY", GH_LATENCY_NOP) != GH_LATENCY_NOP);
#endif
		do_dlsym = get_envi("GH_HOOK_DLSYM_DYNAMICALLY", 0);
#if (GH_DLSYM_METHOD != 2)
		do_dlvsym = get_envi("GH_HOOK_DLVSYM_DYNAMICALLY", 0);
#endif
		inited = 1;
	}

	if (do_dlsym) {
		GH_INTERCEPT(dlsym);
	}
#if (GH_DLSYM_METHOD != 2)
	if (do_dlvsym) {
		GH_INTERCEPT(dlvsym);
	}
#endif
	GH_INTERCEPT(glXGetProcAddress);
	GH_INTERCEPT(glXGetProcAddressARB);
	GH_INTERCEPT(glXSwapIntervalEXT);
	GH_INTERCEPT(glXSwapIntervalSGI);
	GH_INTERCEPT(glXSwapIntervalMESA);
#ifdef GH_CONTEXT_TRACKING
	GH_INTERCEPT(glXCreateContext);
	GH_INTERCEPT(glXCreateNewContext);
	GH_INTERCEPT(glXCreateContextAttribsARB);
	GH_INTERCEPT(glXImportContextEXT);
	GH_INTERCEPT(glXCreateContextWithConfigSGIX);
	GH_INTERCEPT(glXDestroyContext);
	GH_INTERCEPT(glXFreeContextEXT);
	GH_INTERCEPT(glXMakeCurrent);
	GH_INTERCEPT(glXMakeContextCurrent);
	GH_INTERCEPT(glXMakeCurrentReadSGI);
	GH_INTERCEPT(glDebugMessageCallback);
	GH_INTERCEPT(glDebugMessageCallbackARB);
	GH_INTERCEPT(glDebugMessageCallbackKHR);
	GH_INTERCEPT(glDebugMessageCallbackAMD);
#endif
#ifdef GH_SWAPBUFFERS_INTERCEPT
	if (do_swapbuffers) {
		if (do_swapbuffers < 0) {
			do_swapbuffers =get_envi("GH_SWAPBUFFERS", 0) ||
					get_envi("GH_FRAMETIME", 0) ||
					get_envi("GH_SWAP_SLEEP_USECS", 0) ||
					(get_envi("GH_LATENCY", GH_LATENCY_NOP) != GH_LATENCY_NOP);
		}
		if (do_swapbuffers)
			GH_INTERCEPT(glXSwapBuffers);
	}
#endif
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
cmpb $0x0, 0x3d36(%rip)      # 0x5170
jne 0x1457
leaq 0x1fd8(%rip), %rdi      # 0x341b
xorl %esi, %esi
callq 0x1fa0
movl %eax, 0x3d1c(%rip)      # 0x516c
movb $0x1, 0x3d19(%rip)      # 0x5170
cmpl $0x0, 0x3d0e(%rip)      # 0x516c
je 0x147a
leaq 0x1bb5(%rip), %r12      # 0x301c
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1538
leaq 0x1bc6(%rip), %r12      # 0x3047
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1500
leaq 0x1be0(%rip), %r12      # 0x3077
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1570
leaq 0x1bfc(%rip), %r12      # 0x30ad
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x15a8
leaq 0x1bf5(%rip), %r12      # 0x30c0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x15dd
leaq 0x1c2c(%rip), %r12      # 0x3111
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x160a
xorl %r13d, %r13d
jmp 0x1668
leaq 0x3bc1(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3be5(%rip), %rax      # 0x50f8
movq 0x3a96(%rip), %r13      # 0x4fb0
testq %r15, %r15
je 0x165c
testq %rax, %rax
jne 0x165c
leaq 0x3bc5(%rip), %rbp      # 0x50f8
jmp 0x1635
leaq 0x3b89(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3ba5(%rip), %rax      # 0x50f0
movq 0x3a76(%rip), %r13      # 0x4fc8
testq %r15, %r15
je 0x165c
testq %rax, %rax
jne 0x165c
leaq 0x3b85(%rip), %rbp      # 0x50f0
jmp 0x1635
leaq 0x3b51(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3b7d(%rip), %rax      # 0x5100
movq 0x3a56(%rip), %r13      # 0x4fe0
testq %r15, %r15
je 0x165c
testq %rax, %rax
jne 0x165c
leaq 0x3b5d(%rip), %rbp      # 0x5100
jmp 0x1635
leaq 0x3b19(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3b4d(%rip), %rax      # 0x5108
movq 0x39f6(%rip), %r13      # 0x4fb8
testq %r15, %r15
je 0x165c
testq %rax, %rax
jne 0x165c
leaq 0x3b2d(%rip), %rbp      # 0x5108
jmp 0x1635
leaq 0x3ae4(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3b20(%rip), %rax      # 0x5110
movq 0x39b1(%rip), %r13      # 0x4fa8
testq %r15, %r15
je 0x165c
testq %rax, %rax
jne 0x165c
leaq 0x3b08(%rip), %rbp      # 0x5110
jmp 0x1635
leaq 0x3ab7(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3afb(%rip), %rax      # 0x5118
movq 0x39ac(%rip), %r13      # 0x4fd0
testq %r15, %r15
je 0x165c
testq %rax, %rax
jne 0x165c
leaq 0x3ae3(%rip), %rbp      # 0x5118
movq %r12, %rdi
callq *%r15
movq %rax, (%rbp)
movq (%rbp), %r8
leaq 0x1deb(%rip), %rsi      # 0x3435
movl $0x4, %edi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x16b2
leaq 0x3a65(%rip), %rdi      # 0x50c8
callq 0x10c0
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq