// File: /workspace/github_c_makefile_star2_O1/kyx0r[P]xkeyboard/xkeyboard.c
// Function: get_keyboard_mapping
int get_keyboard_mapping(void)
{
	int i, j;
	int min_keycode, max_keycode, keysyms_per_keycode, keycode_count;
	XModifierKeymap *map;
	KeySym *keymap;
	char *tmp, *s;

	for (j = 0; j < 8; j++)
		for (i = 0; i < 16; i++)
			modifiermap[j][i] = 0;
	map = XGetModifierMapping(dpy);
	keycode_count = map->max_keypermod;
	for (i = 0; i < 8; i++) {
		for (j = 0; j < keycode_count && j < 16; j++) {
			modifiermap[i][j] =
				map->modifiermap[i * keycode_count + j];
		}
	}

	for (j = 0; j < 8; j++)
		for (i = 0; i < 256; i++)
			if (scanname[j][i] != NULL) {
				free(scanname[j][i]);
				scanname[j][i] = NULL;
			}
	XDisplayKeycodes(dpy, &min_keycode, &max_keycode);
	keycode_count = (max_keycode - min_keycode) + 1;
	if (!(keymap = XGetKeyboardMapping(dpy, min_keycode,
		keycode_count, &keysyms_per_keycode))) {
		fprintf(stderr, "Unable to get keyboard mapping table\n");
		return 1;
	}
	myevent.type = KeyPress;
	myevent.xkey.display = dpy;
	myevent.xkey.window = mywindow;
	myevent.xkey.same_screen = True;
	for (j = 0; j < keycode_count; j++) {
		for (i = 0; i < keysyms_per_keycode; i++) {
			KeySym ks = keymap[j * keysyms_per_keycode + i];
			if (ks != NoSymbol) {
				if ((s = XKeysymToString(ks)) != NULL) {
					tmp = malloc(16);
					memcpy(tmp, s, 16);
					tmp[15] = 0;
					scanname[i][j + min_keycode] = tmp;
					myevent.xkey.keycode = j + min_keycode;
					myevent.xkey.state = i & 3;
					XLookupString((XKeyEvent *) &myevent,
						tmpbuf, 16, &ks, NULL);
					if (tmpbuf[0] >= ' ' &&
					    tmpbuf[0] != 0x7f)
						memcpy(tmp, tmpbuf, 16);
					if ((tmp = strchr(&tmp[1], '_'))!=NULL)
						*tmp = 0;
				}
			}
		}
	}
	XFree((char *) keymap);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x19b5d(%rip), %rbx     # 0x1cf70
xorl %r14d, %r14d
movl $0x200, %edx            # imm = 0x200
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2130
movq 0x153cc(%rip), %rdi     # 0x187f8
callq 0x21a0
movl (%rax), %ecx
leal -0x1(%rcx), %esi
cmpl $0xf, %esi
movl $0xf, %edx
cmovbl %esi, %edx
incl %edx
xorl %esi, %esi
testl %ecx, %ecx
jle 0x3464
movq 0x8(%rax), %rdi
addq %r14, %rdi
xorl %r8d, %r8d
movzbl (%rdi,%r8), %r9d
movl %r9d, (%rbx,%r8,4)
incq %r8
cmpq %r8, %rdx
jne 0x3453
incq %rsi
addq %rcx, %r14
addq $0x40, %rbx
cmpq $0x8, %rsi
jne 0x3445
leaq 0x15ad5(%rip), %rbx     # 0x18f50
xorl %r14d, %r14d
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
testq %rdi, %rdi
je 0x3497
callq 0x2050
movq $0x0, (%rbx,%r15,8)
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0x3481
incq %r14
addq $0x800, %rbx            # imm = 0x800
cmpq $0x8, %r14
jne 0x347e
movq 0x1533e(%rip), %rdi     # 0x187f8
leaq 0xc(%rsp), %rbx
leaq 0x24(%rsp), %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22d0
movl (%r14), %r15d
movl (%rbx), %eax
subl %eax, %r15d
leal 0x1(%r15), %edx
movq 0x15316(%rip), %rdi     # 0x187f8
movzbl %al, %esi
leaq 0x4(%rsp), %rcx
movl %edx, 0x8(%rsp)
callq 0x2300
testq %rax, %rax
je 0x364f
movq %rax, %r14
movl $0x2, 0x19c67(%rip)     # 0x1d170
movq 0x152e8(%rip), %rax     # 0x187f8
movq %rax, 0x19c71(%rip)     # 0x1d188
movq 0x15452(%rip), %rax     # 0x18970
movq %rax, 0x19c6b(%rip)     # 0x1d190
movl $0x1, 0x19c99(%rip)     # 0x1d1c8
testl %r15d, %r15d
js 0x3636
xorl %r15d, %r15d
movl 0x4(%rsp), %eax
testl %eax, %eax
jle 0x3628
movslq %r15d, %rcx
movq %rcx, 0x10(%rsp)
leaq 0x159fa(%rip), %r13     # 0x18f50
xorl %r12d, %r12d
imull %r15d, %eax
cltq
addq %r12, %rax
movq (%r14,%rax,8), %rdi
movq %rdi, 0x18(%rsp)
testq %rdi, %rdi
je 0x3610
callq 0x23b0
testq %rax, %rax
je 0x3610
movq %rax, %rbx
movl $0x10, %edi
callq 0x2200
movq %rax, %rbp
movups (%rbx), %xmm0
movups %xmm0, (%rax)
movb $0x0, 0xf(%rax)
movslq 0xc(%rsp), %rax
leal (%rax,%r15), %ecx
addq 0x10(%rsp), %rax
movq %rbp, (%r13,%rax,8)
movl %ecx, 0x19c0f(%rip)     # 0x1d1c4
movl %r12d, %eax
andl $0x3, %eax
movl %eax, 0x19bff(%rip)     # 0x1d1c0
leaq 0x19ba8(%rip), %rdi     # 0x1d170
leaq 0x153b1(%rip), %rsi     # 0x18980
movl $0x10, %edx
leaq 0x18(%rsp), %rcx
xorl %r8d, %r8d
callq 0x20a0
movb 0x15399(%rip), %al      # 0x18980
addb $-0x20, %al
cmpb $0x5e, %al
ja 0x35f8
movaps 0x1538c(%rip), %xmm0    # 0x18980
movups %xmm0, (%rbp)
incq %rbp
movq %rbp, %rdi
movl $0x5f, %esi
callq 0x20d0
testq %rax, %rax
je 0x3610
movb $0x0, (%rax)
incq %r12
movslq 0x4(%rsp), %rax
addq $0x800, %r13            # imm = 0x800
cmpq %rax, %r12
jl 0x3559
incl %r15d
cmpl 0x8(%rsp), %r15d
jne 0x353b
movq %r14, %rdi
callq 0x20e0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x24c0
movl $0x1, %eax
jmp 0x3640