// File: /workspace/github_cpp_makefile_star2_O1/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 0x25dc
movq %rax, %rbx
cmpl $0x0, 0xc(%rsp)
jle 0x25af
leaq 0x40(%rsp), %rbp
leaq 0x38(%rsp), %r14
xorl %r15d, %r15d
xorl %r13d, %r13d
leaq (,%r13,4), %rax
addq %r13, %rax
cmpl $0x2, 0x1c(%rbx,%rax,8)
jb 0x259e
leaq (%rbx,%rax,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 0x2491
movq 0x20(%r12), %rcx
cmpq $0x1, (%rcx)
jne 0x2486
movswl 0xc(%rcx), %edx
movl %edx, 0x30(%rsp)
movslq 0x8(%rcx), %rdx
addq %rdx, %rcx
decl %eax
jne 0x2478
cmpl $0x0, 0x30(%rsp)
je 0x2596
movq 0x3cb5(%rip), %rdi      # 0x6158
testq %rdi, %rdi
je 0x24ba
movq 0x10(%r12), %rsi
callq 0x2140
testl %eax, %eax
jne 0x2596
movq 0x3c87(%rip), %rdi      # 0x6148
movq (%r12), %rsi
callq 0x20c0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2583
movl $0x0, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
movq 0x10(%rax), %rcx
movl 0x8(%rax), %edx
testl %edx, %edx
jle 0x251b
xorl %esi, %esi
cmpb $0x1, (%rcx,%rsi,2)
jne 0x2514
movzbl 0x1(%rcx,%rsi,2), %edi
movl %edi, 0x28(%rsp)
movq (%rax), %r8
shlq $0x8, %r8
orq %rdi, %r8
movq %r8, 0x18(%rsp)
incq %rsi
cmpl %esi, %edx
jne 0x24f6
movl $0x0, 0x2c(%rsp)
movq $0x0, 0x20(%rsp)
testl %edx, %edx
jle 0x255a
xorl %esi, %esi
cmpb $0x1, (%rcx,%rsi,2)
jne 0x2553
movzbl 0x1(%rcx,%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, %edx
jne 0x2532
leaq 0x3bff(%rip), %rdi      # 0x6160
leaq 0x10(%rsp), %rsi
callq 0x2df6
movq %rax, %rdi
leaq 0x3beb(%rip), %rsi      # 0x6160
callq 0x2040
incq 0x3bef(%rip)            # 0x6170
jmp 0x2596
movq 0x10(%r12), %rsi
leaq 0x1aa5(%rip), %rdi      # 0x4034
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x2da6
incq %r13
movslq 0xc(%rsp), %rax
cmpq %rax, %r13
jl 0x2432
movq %rbx, %rdi
callq 0x2060
cmpq $0x0, 0x3bb1(%rip)      # 0x6170
je 0x25d0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b5c(%rip), %rdi      # 0x4133
callq 0x21f0
movl $0x1, %edi
callq 0x2190
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2da6
movq %rbx, %rdi
callq 0x2220