// File: /workspace/github_c_makefile_star2_O2/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 0x18c0f(%rip), %rax     # 0x1bf70
xorl %ecx, %ecx
cmpq $0x8, %rcx
je 0x3383
xorl %edx, %edx
cmpq $0x10, %rdx
je 0x337a
andl $0x0, (%rax,%rdx,4)
incq %rdx
jmp 0x336b
incq %rcx
addq $0x40, %rax
jmp 0x3363
movq 0x1446e(%rip), %rdi     # 0x177f8
callq 0x21a0
movslq (%rax), %rcx
leaq 0x18bd7(%rip), %rdx     # 0x1bf70
xorl %esi, %esi
xorl %edi, %edi
cmpq $0x8, %rdi
je 0x33d2
xorl %r8d, %r8d
cmpq %rcx, %r8
jge 0x33c6
cmpq $0xf, %r8
ja 0x33c6
movq 0x8(%rax), %r9
addq %rsi, %r9
movzbl (%r8,%r9), %r9d
movl %r9d, (%rdx,%r8,4)
incq %r8
jmp 0x33a6
incq %rdi
addq %rcx, %rsi
addq $0x40, %rdx
jmp 0x339d
leaq 0x14b77(%rip), %rbx     # 0x17f50
xorl %r14d, %r14d
cmpq $0x8, %r14
je 0x3412
xorl %r15d, %r15d
cmpq $0x100, %r15            # imm = 0x100
je 0x3406
movq (%rbx,%r15,8), %rdi
testq %rdi, %rdi
je 0x3401
callq 0x2050
andq $0x0, (%rbx,%r15,8)
incq %r15
jmp 0x33e5
incq %r14
addq $0x800, %rbx            # imm = 0x800
jmp 0x33dc
movq 0x143df(%rip), %rdi     # 0x177f8
leaq 0xc(%rsp), %rbx
leaq 0x24(%rsp), %r14
movq %rbx, %rsi
movq %r14, %rdx
callq 0x22d0
movl (%r14), %ecx
movl (%rbx), %eax
subl %eax, %ecx
movq %rcx, 0x10(%rsp)
leal 0x1(%rcx), %edx
movq 0x143b4(%rip), %rdi     # 0x177f8
movzbl %al, %esi
leaq 0x8(%rsp), %rcx
callq 0x2300
testq %rax, %rax
je 0x3599
movq %rax, %rbx
movl $0x2, 0x18d09(%rip)     # 0x1c170
movq 0x1438a(%rip), %rax     # 0x177f8
movq %rax, 0x18d13(%rip)     # 0x1c188
movq 0x144f4(%rip), %rax     # 0x17970
movq %rax, 0x18d0d(%rip)     # 0x1c190
movl $0x1, 0x18d3b(%rip)     # 0x1c1c8
xorl %ebp, %ebp
cmpl 0x10(%rsp), %ebp
jg 0x3580
leaq 0x14ab0(%rip), %r13     # 0x17f50
xorl %r14d, %r14d
movslq 0x8(%rsp), %rax
cmpq %rax, %r14
jge 0x3578
imull %ebp, %eax
addl %r14d, %eax
cltq
movq (%rbx,%rax,8), %rdi
movq %rdi, 0x18(%rsp)
testq %rdi, %rdi
je 0x3569
callq 0x23b0
testq %rax, %rax
je 0x3569
movq %rax, %r12
pushq $0x10
popq %rdi
callq 0x2200
movq %rax, %r15
movq (%r12), %rax
movq 0x7(%r12), %rcx
movq %rax, (%r15)
movq %rcx, 0x7(%r15)
movb $0x0, 0xf(%r15)
movslq 0xc(%rsp), %rax
leal (%rax,%rbp), %ecx
addq %rbp, %rax
movq %r15, (%r13,%rax,8)
movl %ecx, 0x18cb2(%rip)     # 0x1c1c4
movl %r14d, %eax
andl $0x3, %eax
movl %eax, 0x18ca2(%rip)     # 0x1c1c0
leaq 0x18c4b(%rip), %rdi     # 0x1c170
leaq 0x14454(%rip), %rsi     # 0x17980
pushq $0x10
popq %rdx
leaq 0x18(%rsp), %rcx
xorl %r8d, %r8d
callq 0x20a0
movb 0x1443e(%rip), %al      # 0x17980
addb $-0x20, %al
cmpb $0x5e, %al
ja 0x3553
movaps 0x14431(%rip), %xmm0    # 0x17980
movups %xmm0, (%r15)
incq %r15
movq %r15, %rdi
pushq $0x5f
popq %rsi
callq 0x20d0
testq %rax, %rax
je 0x3569
movb $0x0, (%rax)
incq %r14
addq $0x800, %r13            # imm = 0x800
jmp 0x34a3
incq %rbp
jmp 0x348f
movq %rbx, %rdi
callq 0x20e0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3a58(%rip), %rax      # 0x6ff8
movq (%rax), %rcx
leaq 0x1b0b(%rip), %rdi      # 0x50b5
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x2360
pushq $0x1
popq %rax
jmp 0x358a