// File: gatecat[P]subprime/subprime.cpp
// Function: (anonymous namespace)::glx_choose_fb_config(_XDisplay*, int, int const*, int*)
GLXFBConfig *glx_choose_fb_config(Display *dpy, int screen, const int *attrib_list, int *nelements) {
	SP_TRACE("");
	auto conv_attrs = convert_attribute_list(attrib_list);
	std::array<EGLConfig, 256> configs_out;
	int config_count = 0;
	SP_CHECK(fn_eglChooseConfig(disp(), conv_attrs.data(), configs_out.data(), 256, &config_count));

	GLXFBConfig *result = reinterpret_cast<GLXFBConfig*>(malloc(sizeof(GLXFBConfig) * config_count));
	SP_TRACE("count=%d", config_count);
	for (int i = 0; i < config_count; i++) {
		config_store.emplace_back(std::make_unique<EGLConfig>(configs_out.at(i)));
		result[i] = reinterpret_cast<GLXFBConfig>(config_store.back().get());
	}

	*nelements = config_count;

	return result;
}

// Assembly:
subq $0x8a8, %rsp            # imm = 0x8A8
movq %rdi, 0x8a0(%rsp)
movl %esi, 0x89c(%rsp)
movq %rdx, 0x890(%rsp)
movq %rcx, 0x888(%rsp)
testb $0x1, 0x12843(%rip)     # 0x2b110
je 0x1891e
movq 0x11702(%rip), %rax     # 0x29fd8
movq (%rax), %rdi
leaq 0xaa80(%rip), %rsi      # 0x23360
leaq 0xaf22(%rip), %rdx      # 0x23809
movb $0x0, %al
callq 0x16680
movq 0x116e3(%rip), %rax     # 0x29fd8
movq (%rax), %rdi
leaq 0xaa55(%rip), %rsi      # 0x23354
movb $0x0, %al
callq 0x16680
movq 0x116cb(%rip), %rax     # 0x29fd8
movq (%rax), %rdi
leaq 0xaa3c(%rip), %rsi      # 0x23353
movb $0x0, %al
callq 0x16680
jmp 0x18920
movq 0x890(%rsp), %rsi
leaq 0x870(%rsp), %rdi
callq 0x1bbf0
movl $0x0, 0x6c(%rsp)
movq 0x1289c(%rip), %rax     # 0x2b1e0
movq %rax, 0x30(%rsp)
callq 0x1a260
movq %rax, 0x38(%rsp)
jmp 0x18955
leaq 0x870(%rsp), %rdi
callq 0x161b0
movq %rax, 0x20(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x15610
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq %rax, %rdx
movq 0x30(%rsp), %rax
movl $0x100, %ecx            # imm = 0x100
leaq 0x6c(%rsp), %r8
callq *%rax
movl %eax, 0x2c(%rsp)
jmp 0x18995
movl 0x2c(%rsp), %eax
movl %eax, 0x68(%rsp)
cmpl $0x1, 0x68(%rsp)
je 0x18a05
movq 0x1162d(%rip), %rax     # 0x29fd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x12836(%rip), %rax     # 0x2b1f8
callq *%rax
movl %eax, 0x1c(%rsp)
jmp 0x189ca
movl 0x1c(%rsp), %r8d
movl 0x18(%rsp), %ecx
movq 0x10(%rsp), %rdi
leaq 0xaab2(%rip), %rsi      # 0x23491
leaq 0xae38(%rip), %rdx      # 0x2381e
movb $0x0, %al
callq 0x16680
callq 0x153b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
jmp 0x18b55
jmp 0x18a07
jmp 0x18a09
movslq 0x6c(%rsp), %rdi
shlq $0x3, %rdi
callq 0x16450
movq %rax, 0x50(%rsp)
testb $0x1, 0x126ed(%rip)     # 0x2b110
je 0x18a78
movq 0x115ac(%rip), %rax     # 0x29fd8
movq (%rax), %rdi
leaq 0xa92a(%rip), %rsi      # 0x23360
leaq 0xadcc(%rip), %rdx      # 0x23809
movb $0x0, %al
callq 0x16680
movq 0x1158d(%rip), %rax     # 0x29fd8
movq (%rax), %rdi
movl 0x6c(%rsp), %edx
leaq 0xae1b(%rip), %rsi      # 0x23874
movb $0x0, %al
callq 0x16680
movq 0x11571(%rip), %rax     # 0x29fd8
movq (%rax), %rdi
leaq 0xa8e2(%rip), %rsi      # 0x23353
movb $0x0, %al
callq 0x16680
jmp 0x18a7a
jmp 0x18a7c
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x18b25
movslq 0x4c(%rsp), %rsi
leaq 0x70(%rsp), %rdi
callq 0x169b0
movq %rax, 0x8(%rsp)
jmp 0x18aa8
movq 0x8(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x153e0
jmp 0x18ab9
leaq 0x125f8(%rip), %rdi     # 0x2b0b8
leaq 0x40(%rsp), %rsi
callq 0x165a0
jmp 0x18acc
leaq 0x40(%rsp), %rdi
callq 0x158e0
leaq 0x125db(%rip), %rdi     # 0x2b0b8
callq 0x153f0
movq %rax, %rdi
callq 0x15850
movq %rax, %rdx
movq 0x50(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x18a84
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x158e0
jmp 0x18b55
movl 0x6c(%rsp), %ecx
movq 0x888(%rsp), %rax
movl %ecx, (%rax)
movq 0x50(%rsp), %rax
movq %rax, (%rsp)
leaq 0x870(%rsp), %rdi
callq 0x15bb0
movq (%rsp), %rax
addq $0x8a8, %rsp            # imm = 0x8A8
retq
leaq 0x870(%rsp), %rdi
callq 0x15bb0
movq 0x60(%rsp), %rdi
callq 0x16bc0
nopl (%rax)