// File: /workspace/github_cpp_makefile_star2_O3/thjaeger[P]bindbutton/bindbutton.cc
// Function: init_xi()
void init_xi() {
	int n;
	XDeviceInfo *devs = XListInputDevices(dpy, &n);
	if (!devs)
		exit(EXIT_FAILURE);

	for (int i = 0; i < n; i++) {
		if (devs[i].use == IsXKeyboard || devs[i].use == IsXPointer)
			continue;

		XiDevice dev;

		dev.num_buttons = 0;
		XAnyClassPtr any = (XAnyClassPtr) (devs[i].inputclassinfo);
		for (int j = 0; j < devs[i].num_classes; j++) {
			if (any->c_class == ButtonClass) {
				XButtonInfo *info = (XButtonInfo *)any;
				dev.num_buttons = info->num_buttons;
			}
			any = (XAnyClassPtr) ((char *) any + any->length);
		}
		if (!dev.num_buttons)
			continue;

		if (device_name && strcasecmp(device_name, devs[i].name))
			continue;

		dev.dev = XOpenDevice(dpy, devs[i].id);
		if (!dev.dev) {
			printf("Opening Device %s failed.\n", devs[i].name);
			continue;
		}

		DeviceButtonPress(dev.dev, dev.press, dev.classes[0]);
		DeviceButtonRelease(dev.dev, dev.release, dev.classes[1]);

		devices.push_back(dev);
	}
	XFreeDeviceList(devs);
	if (devices.size() == 0) {
		printf("Error: No devices found\n");
		exit(EXIT_FAILURE);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0x3d47(%rip), %rdi      # 0x6148
leaq 0xc(%rsp), %rsi
callq 0x2160
testq %rax, %rax
je 0x25f9
movq %rax, %rbx
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x25cc
leaq 0x40(%rsp), %rbp
leaq 0x38(%rsp), %r14
xorl %r15d, %r15d
xorl %r13d, %r13d
leaq (,%r13,4), %rcx
addq %r13, %rcx
cmpl $0x2, 0x1c(%rbx,%rcx,8)
jb 0x25bd
leaq (%rbx,%rcx,8), %r12
movl %r15d, 0x40(%rsp)
movq %r15, 0x48(%rsp)
movq %rbp, 0x50(%rsp)
movq %rbp, 0x58(%rsp)
movq %r15, 0x60(%rsp)
movl %r15d, 0x30(%rsp)
movl 0x18(%r12), %eax
testl %eax, %eax
jle 0x25b1
movq 0x20(%r12), %rcx
xorl %edx, %edx
cmpq $0x1, (%rcx)
jne 0x248d
movswl 0xc(%rcx), %edx
movl %edx, 0x30(%rsp)
movslq 0x8(%rcx), %rsi
addq %rsi, %rcx
decl %eax
jne 0x247f
testl %edx, %edx
je 0x25b1
movq 0x3cb1(%rip), %rdi      # 0x6158
testq %rdi, %rdi
je 0x24be
movq 0x10(%r12), %rsi
callq 0x2140
testl %eax, %eax
jne 0x25b1
movq 0x3c83(%rip), %rdi      # 0x6148
movq (%r12), %rsi
callq 0x20c0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2564
movl $0x0, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movl 0x8(%rax), %ecx
testl %ecx, %ecx
jle 0x2579
movq 0x10(%rax), %rdx
xorl %esi, %esi
cmpb $0x1, (%rdx,%rsi,2)
jne 0x251c
movzbl 0x1(%rdx,%rsi,2), %edi
movl %edi, 0x28(%rsp)
movq (%rax), %r8
shlq $0x8, %r8
orq %rdi, %r8
movq %r8, 0x18(%rsp)
incq %rsi
cmpl %esi, %ecx
jne 0x24fe
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x20(%rsp)
testl %ecx, %ecx
jle 0x258a
xorl %esi, %esi
cmpb $0x1, (%rdx,%rsi,2)
jne 0x255b
movzbl 0x1(%rdx,%rsi,2), %edi
incq %rdi
movl %edi, 0x2c(%rsp)
movq (%rax), %r8
shlq $0x8, %r8
orq %rdi, %r8
movq %r8, 0x20(%rsp)
incq %rsi
cmpl %esi, %ecx
jne 0x253a
jmp 0x258a
movq 0x10(%r12), %rsi
leaq 0x1ac4(%rip), %rdi      # 0x4034
xorl %eax, %eax
callq 0x2030
jmp 0x25b1
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x3bcf(%rip), %rdi      # 0x6160
leaq 0x10(%rsp), %rsi
callq 0x2e38
movq %rax, %rdi
leaq 0x3bbb(%rip), %rsi      # 0x6160
callq 0x2040
incq 0x3bbf(%rip)            # 0x6170
movq %r14, %rdi
callq 0x2de8
movl 0xc(%rsp), %eax
incq %r13
movslq %eax, %rcx
cmpq %rcx, %r13
jl 0x2433
movq %rbx, %rdi
callq 0x2060
cmpq $0x0, 0x3b94(%rip)      # 0x6170
je 0x25ed
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b3f(%rip), %rdi      # 0x4133
callq 0x21f0
movl $0x1, %edi
callq 0x2190
movq %rax, %rbx
movq %r14, %rdi
callq 0x2de8
movq %rbx, %rdi
callq 0x2220