// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0x3867
movl $0x0, -0x8(%rbp)
cmpl $0x10, -0x8(%rbp)
jge 0x385a
movslq -0xc(%rbp), %rcx
leaq 0x1a733(%rip), %rax     # 0x1df70
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x382c
jmp 0x385c
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x381f
movq 0x15f8a(%rip), %rdi     # 0x197f8
callq 0x21b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x8(%rbp)
cmpl $0x8, -0x8(%rbp)
jge 0x38fe
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x49(%rbp)
jge 0x38ab
cmpl $0x10, -0xc(%rbp)
setl %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x38b4
jmp 0x38f1
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x8(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
movslq -0x8(%rbp), %rcx
leaq 0x1a698(%rip), %rax     # 0x1df70
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0xc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3894
jmp 0x38f3
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x3887
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0x3996
movl $0x0, -0x8(%rbp)
cmpl $0x100, -0x8(%rbp)      # imm = 0x100
jge 0x3986
movslq -0xc(%rbp), %rcx
leaq 0x16626(%rip), %rax     # 0x19f50
shlq $0xb, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x3979
movslq -0xc(%rbp), %rcx
leaq 0x16609(%rip), %rax     # 0x19f50
shlq $0xb, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2050
movslq -0xc(%rbp), %rcx
leaq 0x165ea(%rip), %rax     # 0x19f50
shlq $0xb, %rcx
addq %rcx, %rax
movslq -0x8(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x397b
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x3916
jmp 0x3988
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3905
movq 0x15e5b(%rip), %rdi     # 0x197f8
leaq -0x10(%rbp), %rsi
leaq -0x14(%rbp), %rdx
callq 0x22e0
movl -0x14(%rbp), %eax
subl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq 0x15e3b(%rip), %rdi     # 0x197f8
movl -0x10(%rbp), %eax
movl -0x1c(%rbp), %edx
leaq -0x18(%rbp), %rcx
movzbl %al, %esi
callq 0x2310
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x39fd
movq 0x5618(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
leaq 0x380f(%rip), %rsi      # 0x71f9
movb $0x0, %al
callq 0x21a0
movl $0x1, -0x4(%rbp)
jmp 0x3b9e
movl $0x2, 0x1a769(%rip)     # 0x1e170
movq 0x15dea(%rip), %rax     # 0x197f8
movq %rax, 0x1a773(%rip)     # 0x1e188
movq 0x15f54(%rip), %rax     # 0x19970
movq %rax, 0x1a76d(%rip)     # 0x1e190
movl $0x1, 0x1a79b(%rip)     # 0x1e1c8
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3b8e
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3b7e
movq -0x30(%rbp), %rax
movl -0xc(%rbp), %ecx
imull -0x18(%rbp), %ecx
addl -0x8(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x3b6e
movq -0x48(%rbp), %rdi
callq 0x23b0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x3b6c
movl $0x10, %edi
callq 0x2210
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movb $0x0, 0xf(%rax)
movq -0x38(%rbp), %rdx
movslq -0x8(%rbp), %rcx
leaq 0x16487(%rip), %rax     # 0x19f50
shlq $0xb, %rcx
addq %rcx, %rax
movl -0xc(%rbp), %ecx
addl -0x10(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl -0x10(%rbp), %eax
movl %eax, 0x1a6db(%rip)     # 0x1e1c4
movl -0x8(%rbp), %eax
andl $0x3, %eax
movl %eax, 0x1a6cb(%rip)     # 0x1e1c0
leaq 0x1a674(%rip), %rdi     # 0x1e170
leaq 0x15e7d(%rip), %rsi     # 0x19980
movl $0x10, %edx
leaq -0x48(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0x20b0
movsbl 0x15e63(%rip), %eax     # 0x19980
cmpl $0x20, %eax
jl 0x3b47
movsbl 0x15e57(%rip), %eax     # 0x19980
cmpl $0x7f, %eax
je 0x3b47
movq -0x38(%rbp), %rax
movq 0x15e47(%rip), %rcx     # 0x19980
movq %rcx, (%rax)
movq 0x15e45(%rip), %rcx     # 0x19988
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rdi
addq $0x1, %rdi
movl $0x5f, %esi
callq 0x20e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x3b6a
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
jmp 0x3b6c
jmp 0x3b6e
jmp 0x3b70
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x3a47
jmp 0x3b80
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3a34
movq -0x30(%rbp), %rdi
callq 0x20f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)