// File: /workspace/github_c_makefile_star2_O3/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, 0x3d15(%rip)      # 0x5170
je 0x1465
movl 0x3d09(%rip), %eax      # 0x516c
jmp 0x1480
leaq 0x1faf(%rip), %rdi      # 0x341b
xorl %esi, %esi
callq 0x2003
movl %eax, 0x3cf3(%rip)      # 0x516c
movb $0x1, 0x3cf0(%rip)      # 0x5170
testl %eax, %eax
je 0x149e
leaq 0x1b91(%rip), %r12      # 0x301c
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x155c
leaq 0x1ba2(%rip), %r12      # 0x3047
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1524
leaq 0x1bbc(%rip), %r12      # 0x3077
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1594
leaq 0x1bd8(%rip), %r12      # 0x30ad
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x15cc
leaq 0x1bd1(%rip), %r12      # 0x30c0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x1601
leaq 0x1c08(%rip), %r12      # 0x3111
movq %r12, %rdi
movq %r14, %rsi
callq 0x1090
testl %eax, %eax
je 0x162e
xorl %r13d, %r13d
jmp 0x168c
leaq 0x3b9d(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3bc1(%rip), %rax      # 0x50f8
movq 0x3a72(%rip), %r13      # 0x4fb0
testq %r15, %r15
je 0x1680
testq %rax, %rax
jne 0x1680
leaq 0x3ba1(%rip), %rbp      # 0x50f8
jmp 0x1659
leaq 0x3b65(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3b81(%rip), %rax      # 0x50f0
movq 0x3a52(%rip), %r13      # 0x4fc8
testq %r15, %r15
je 0x1680
testq %rax, %rax
jne 0x1680
leaq 0x3b61(%rip), %rbp      # 0x50f0
jmp 0x1659
leaq 0x3b2d(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3b59(%rip), %rax      # 0x5100
movq 0x3a32(%rip), %r13      # 0x4fe0
testq %r15, %r15
je 0x1680
testq %rax, %rax
jne 0x1680
leaq 0x3b39(%rip), %rbp      # 0x5100
jmp 0x1659
leaq 0x3af5(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3b29(%rip), %rax      # 0x5108
movq 0x39d2(%rip), %r13      # 0x4fb8
testq %r15, %r15
je 0x1680
testq %rax, %rax
jne 0x1680
leaq 0x3b09(%rip), %rbp      # 0x5108
jmp 0x1659
leaq 0x3ac0(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3afc(%rip), %rax      # 0x5110
movq 0x398d(%rip), %r13      # 0x4fa8
testq %r15, %r15
je 0x1680
testq %rax, %rax
jne 0x1680
leaq 0x3ae4(%rip), %rbp      # 0x5110
jmp 0x1659
leaq 0x3a93(%rip), %rdi      # 0x50c8
callq 0x1120
movq 0x3ad7(%rip), %rax      # 0x5118
movq 0x3988(%rip), %r13      # 0x4fd0
testq %r15, %r15
je 0x1680
testq %rax, %rax
jne 0x1680
leaq 0x3abf(%rip), %rbp      # 0x5118
movq %r12, %rdi
callq *%r15
movq %rax, (%rbp)
movq (%rbp), %r8
leaq 0x1dc7(%rip), %rsi      # 0x3435
movl $0x4, %edi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x16d6
leaq 0x3a41(%rip), %rdi      # 0x50c8
callq 0x10c0
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq