// File: /workspace/github_c_makefile_star2_O0/derhass[P]glx_hook/glx_hook.c
// Function: get_fbconfig_for_visual
static const GLXFBConfig* get_fbconfig_for_visual(Display *dpy, XVisualInfo *vis, GLXFBConfig *cfg)
{
	GLXFBConfig *cfgs;
	const GLXFBConfig *new_cfg = NULL;
	/* TODO: what about the screen number? */
	int screen=0;
	int count;

	GH_GET_PTR_GL(glXGetFBConfigs);
	GH_GET_PTR_GL(glXGetFBConfigAttrib);
	GH_GET_PTR(XFree);

	if (!GH_glXGetFBConfigs || !GH_glXGetFBConfigAttrib || !GH_XFree) {
		GH_verbose(GH_MSG_ERROR, "glXGetFBConfigs or glXGetFBConfigAttrib or XFree not found!\n");
		return NULL;
	}

	cfgs=GH_glXGetFBConfigs(dpy, screen, &count);

	if (cfgs && count > 0) {
		int i;
		for (i=0; i<count; i++) {
			int value = -1;
			int res = GH_glXGetFBConfigAttrib(dpy, cfgs[i], GLX_VISUAL_ID, &value);
			if (res == Success) {
				GH_verbose(GH_MSG_DEBUG, "fbconfig %d for visual ID %d\n", i, value);
				if (value == (int)vis->visualid) {
					GH_verbose(GH_MSG_INFO, "found fbconfig %d for visual ID %d\n", i, value);
					*cfg = cfgs[i];
					new_cfg=cfg;
					break;
				}
			} else {
				GH_verbose(GH_MSG_WARNING, "glxGerFBConfigAttrib failed!\n");
			}
		}
	}

	if (cfgs) {
		GH_XFree(cfgs);
	}

	return new_cfg;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
leaq 0x6f0e(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x6ff2(%rip), %rax      # 0xd308
cmpq $0x0, %rax
jne 0x632f
leaq 0x38a4(%rip), %rdi      # 0x9bc7
callq 0x3640
movq %rax, 0x6fd9(%rip)      # 0xd308
leaq 0x6ee2(%rip), %rdi      # 0xd218
callq 0x2130
leaq 0x6ed6(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x6fc2(%rip), %rax      # 0xd310
cmpq $0x0, %rax
jne 0x6367
leaq 0x387c(%rip), %rdi      # 0x9bd7
callq 0x3640
movq %rax, 0x6fa9(%rip)      # 0xd310
leaq 0x6eaa(%rip), %rdi      # 0xd218
callq 0x2130
leaq 0x6e9e(%rip), %rdi      # 0xd218
callq 0x21a0
movq 0x6f92(%rip), %rax      # 0xd318
cmpq $0x0, %rax
jne 0x639f
leaq 0x3859(%rip), %rdi      # 0x9bec
callq 0x2fc0
movq %rax, 0x6f79(%rip)      # 0xd318
leaq 0x6e72(%rip), %rdi      # 0xd218
callq 0x2130
movq 0x6f56(%rip), %rax      # 0xd308
cmpq $0x0, %rax
je 0x63d2
movq 0x6f51(%rip), %rax      # 0xd310
cmpq $0x0, %rax
je 0x63d2
movq 0x6f4c(%rip), %rax      # 0xd318
cmpq $0x0, %rax
jne 0x63f2
movl $0x1, %edi
leaq 0x3814(%rip), %rsi      # 0x9bf2
movb $0x0, %al
callq 0x3020
movq $0x0, -0x8(%rbp)
jmp 0x6505
movq 0x6f0f(%rip), %rax      # 0xd308
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %esi
leaq -0x38(%rbp), %rdx
callq *%rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x64e9
cmpl $0x0, -0x38(%rbp)
jle 0x64e9
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x64e7
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movq 0x6ed0(%rip), %rax      # 0xd310
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movq (%rcx,%rdx,8), %rsi
movl $0x800b, %edx           # imm = 0x800B
leaq -0x40(%rbp), %rcx
callq *%rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x64c4
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
movl $0x4, %edi
leaq 0x37bf(%rip), %rsi      # 0x9c35
movb $0x0, %al
callq 0x3020
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpl %ecx, %eax
jne 0x64c2
movl -0x3c(%rbp), %edx
movl -0x40(%rbp), %ecx
movl $0x3, %edi
leaq 0x3791(%rip), %rsi      # 0x9c2f
movb $0x0, %al
callq 0x3020
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x64e7
jmp 0x64d7
movl $0x2, %edi
leaq 0x3783(%rip), %rsi      # 0x9c53
movb $0x0, %al
callq 0x3020
jmp 0x64d9
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x6426
jmp 0x64e9
cmpq $0x0, -0x28(%rbp)
je 0x64fd
movq 0x6e21(%rip), %rax      # 0xd318
movq -0x28(%rbp), %rdi
callq *%rax
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop