// File: /workspace/github_c_makefile_star2_O2/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, 0x2d6c(%rip)      # 0x4170
je 0x140e
movl 0x2d60(%rip), %eax      # 0x416c
jmp 0x1429
leaq 0x1006(%rip), %rdi      # 0x241b
xorl %esi, %esi
callq 0x1f1e
movl %eax, 0x2d4a(%rip)      # 0x416c
movb $0x1, 0x2d47(%rip)      # 0x4170
testl %eax, %eax
je 0x1447
leaq 0xbe8(%rip), %r12       # 0x201c
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1505
leaq 0xbf9(%rip), %r12       # 0x2047
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x14cd
leaq 0xc13(%rip), %r12       # 0x2077
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x153d
leaq 0xc2f(%rip), %r12       # 0x20ad
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1575
leaq 0xc28(%rip), %r12       # 0x20c0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x15aa
leaq 0xc5f(%rip), %r12       # 0x2111
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x15d7
xorl %r13d, %r13d
jmp 0x1633
leaq 0x2bf4(%rip), %rdi      # 0x40c8
callq 0x1120
movq 0x2c18(%rip), %rax      # 0x40f8
movq 0x2ac9(%rip), %r13      # 0x3fb0
testq %r15, %r15
je 0x1627
testq %rax, %rax
jne 0x1627
leaq 0x2bf8(%rip), %rbp      # 0x40f8
jmp 0x1602
leaq 0x2bbc(%rip), %rdi      # 0x40c8
callq 0x1120
movq 0x2bd8(%rip), %rax      # 0x40f0
movq 0x2aa9(%rip), %r13      # 0x3fc8
testq %r15, %r15
je 0x1627
testq %rax, %rax
jne 0x1627
leaq 0x2bb8(%rip), %rbp      # 0x40f0
jmp 0x1602
leaq 0x2b84(%rip), %rdi      # 0x40c8
callq 0x1120
movq 0x2bb0(%rip), %rax      # 0x4100
movq 0x2a89(%rip), %r13      # 0x3fe0
testq %r15, %r15
je 0x1627
testq %rax, %rax
jne 0x1627
leaq 0x2b90(%rip), %rbp      # 0x4100
jmp 0x1602
leaq 0x2b4c(%rip), %rdi      # 0x40c8
callq 0x1120
movq 0x2b80(%rip), %rax      # 0x4108
movq 0x2a29(%rip), %r13      # 0x3fb8
testq %r15, %r15
je 0x1627
testq %rax, %rax
jne 0x1627
leaq 0x2b60(%rip), %rbp      # 0x4108
jmp 0x1602
leaq 0x2b17(%rip), %rdi      # 0x40c8
callq 0x1120
movq 0x2b53(%rip), %rax      # 0x4110
movq 0x29e4(%rip), %r13      # 0x3fa8
testq %r15, %r15
je 0x1627
testq %rax, %rax
jne 0x1627
leaq 0x2b3b(%rip), %rbp      # 0x4110
jmp 0x1602
leaq 0x2aea(%rip), %rdi      # 0x40c8
callq 0x1120
movq 0x2b2e(%rip), %rax      # 0x4118
movq 0x29df(%rip), %r13      # 0x3fd0
testq %r15, %r15
je 0x1627
testq %rax, %rax
jne 0x1627
leaq 0x2b16(%rip), %rbp      # 0x4118
movq %r12, %rdi
callq *%r15
movq %rax, (%rbp)
movq (%rbp), %r8
leaq 0xe1e(%rip), %rsi       # 0x2435
pushq $0x4
popq %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1677
leaq 0x2a9a(%rip), %rdi      # 0x40c8
callq 0x10c0
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq