// File: /workspace/github_cpp_makefile_star2_O2/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 0x4d57(%rip), %rdi      # 0x7158
leaq 0xc(%rsp), %rsi
callq 0x2180
testq %rax, %rax
je 0x25b8
movq %rax, %rbx
leaq 0x40(%rsp), %rbp
leaq 0x38(%rsp), %r14
leaq 0x10(%rsp), %r13
xorl %r15d, %r15d
movslq 0xc(%rsp), %rax
cmpq %rax, %r15
jge 0x258b
imulq $0x28, %r15, %r12
cmpl $0x2, 0x1c(%rbx,%r12)
jb 0x2583
andl $0x0, 0x40(%rsp)
andq $0x0, 0x48(%rsp)
movq %rbp, 0x50(%rsp)
movq %rbp, 0x58(%rsp)
andq $0x0, 0x60(%rsp)
andl $0x0, 0x30(%rsp)
addq %rbx, %r12
movq 0x20(%r12), %rax
movl 0x18(%r12), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
subl $0x1, %ecx
jb 0x2497
cmpq $0x1, (%rax)
jne 0x248e
movswl 0xc(%rax), %edx
movl %edx, 0x30(%rsp)
movslq 0x8(%rax), %rsi
addq %rsi, %rax
jmp 0x247b
testl %edx, %edx
je 0x257b
movq 0x4cc2(%rip), %rdi      # 0x7168
testq %rdi, %rdi
je 0x24bd
movq 0x10(%r12), %rsi
callq 0x2160
testl %eax, %eax
jne 0x257b
movq 0x4c94(%rip), %rdi      # 0x7158
movq (%r12), %rsi
callq 0x20d0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2568
andl $0x0, 0x28(%rsp)
andq $0x0, 0x18(%rsp)
movq 0x10(%rax), %rcx
movl 0x8(%rax), %edx
testl %edx, %edx
movl $0x0, %esi
cmovlel %esi, %edx
xorl %esi, %esi
cmpl %esi, %edx
je 0x2520
cmpb $0x1, (%rcx,%rsi,2)
jne 0x251b
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
jmp 0x24f9
andl $0x0, 0x2c(%rsp)
andq $0x0, 0x20(%rsp)
xorl %esi, %esi
cmpl %esi, %edx
je 0x2557
cmpb $0x1, (%rcx,%rsi,2)
jne 0x2552
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
jmp 0x252d
leaq 0x4c12(%rip), %rdi      # 0x7170
movq %r13, %rsi
callq 0x2b42
jmp 0x257b
movq 0x10(%r12), %rsi
leaq 0x1ac0(%rip), %rdi      # 0x4034
xorl %eax, %eax
callq 0x2030
movq %r14, %rdi
callq 0x2d2c
incq %r15
jmp 0x2429
movq %rbx, %rdi
callq 0x2060
cmpq $0x0, 0x4be5(%rip)      # 0x7180
je 0x25ac
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b80(%rip), %rdi      # 0x4133
callq 0x2210
pushq $0x1
popq %rdi
callq 0x21b0
movq %rax, %rbx
movq %r14, %rdi
callq 0x2d2c
movq %rbx, %rdi
callq 0x2240