// File: /workspace/github_c_makefile_star2_O3/mrdotx[P]st/x.c
// Function: kpress
void
kpress(XEvent *ev)
{
	XKeyEvent *e = &ev->xkey;
	KeySym ksym = NoSymbol;
	char buf[64], *customkey;
	int len;
	Rune c;
	Status status;
	Shortcut *bp;

	if (IS_SET(MODE_KBDLOCK))
		return;

	if (xw.ime.xic) {
		len = XmbLookupString(xw.ime.xic, e, buf, sizeof buf, &ksym, &status);
		if (status == XBufferOverflow)
			return;
	} else {
		len = XLookupString(e, buf, sizeof buf, &ksym, NULL);
	}
	if ( IS_SET(MODE_KBDSELECT) ) {
		if ( match(XK_NO_MOD, e->state) ||
		     (XK_Shift_L | XK_Shift_R) & e->state )
			win.mode ^= trt_kbdselect(ksym, buf, len);
		return;
	}
	/* 1. shortcuts */
	for (bp = shortcuts; bp < shortcuts + LEN(shortcuts); bp++) {
		if (ksym == bp->keysym && match(bp->mod, e->state)) {
			bp->func(&(bp->arg));
			return;
		}
	}

	/* 2. custom keys from config.h */
	if ((customkey = kmap(ksym, e->state))) {
		ttywrite(customkey, strlen(customkey), 1);
		return;
	}

	/* 3. composed string from input method */
	if (len == 0)
		return;
	if (len == 1 && e->state & Mod1Mask) {
		if (IS_SET(MODE_8BIT)) {
			if (*buf < 0177) {
				c = *buf | 0x80;
				len = utf8encode(c, buf);
			}
		} else {
			buf[1] = buf[0];
			buf[0] = '\033';
			len = 2;
		}
	}
	ttywrite(buf, len, 1);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x58, %rsp
movq $0x0, (%rsp)
testb $0x40, 0xda10(%rip)     # 0x1dc18
jne 0x103f4
movq %rdi, %rbx
movq 0xd930(%rip), %rdi      # 0x1db48
testq %rdi, %rdi
je 0x10245
leaq 0x10(%rsp), %rdx
movq %rsp, %r8
leaq 0xc(%rsp), %r14
movq %rbx, %rsi
movl $0x40, %ecx
movq %r14, %r9
callq 0x6760
cmpl $-0x1, (%r14)
jne 0x1025d
jmp 0x103f4
leaq 0x10(%rsp), %rsi
movq %rsp, %rcx
movq %rbx, %rdi
movl $0x40, %edx
xorl %r8d, %r8d
callq 0x6150
movl 0xd9b5(%rip), %ecx      # 0x1dc18
btl $0x12, %ecx
jb 0x1038e
movl $0x18, %esi
movq (%rsp), %rdx
leaq 0x9f33(%rip), %r8       # 0x1a1b0
movl $0xffff9fef, %edi       # imm = 0xFFFF9FEF
cmpq -0x10(%rsi,%r8), %rdx
jne 0x102a8
movl -0x18(%rsi,%r8), %r9d
cmpl $-0x1, %r9d
je 0x103bf
movl 0x50(%rbx), %r10d
andl %edi, %r10d
cmpl %r9d, %r10d
je 0x103bf
leaq 0x20(%rsi), %r9
addq $-0x18, %rsi
cmpq $0x200, %rsi            # imm = 0x200
movq %r9, %rsi
jb 0x10282
movl 0x50(%rbx), %esi
movl %edx, %edi
andl $0xff00, %edi           # imm = 0xFF00
cmpl $0xfd00, %edi           # imm = 0xFD00
jb 0x1035c
movl %esi, %edi
andl $0xffff9fef, %edi       # imm = 0xFFFF9FEF
movq $-0x20, %r8
leaq 0x7087(%rip), %r9       # 0x17370
movl %ecx, %r10d
shrl $0x11, %r10d
cmpq %rdx, 0x20(%r8,%r9)
jne 0x1034f
movl 0x28(%r8,%r9), %r11d
cmpl $-0x1, %r11d
setne %bl
cmpl %r11d, %edi
setne %r11b
testb %r11b, %bl
jne 0x1034f
movb 0x38(%r8,%r9), %r11b
testb $0x4, %cl
jne 0x10320
testb %r11b, %r11b
jg 0x1034f
jmp 0x10331
cmpb $0x2, %r11b
sete %bl
testb %r11b, %r11b
js 0x1034f
andb %r10b, %bl
jne 0x1034f
btl $0x8, %ecx
movb 0x39(%r8,%r9), %r11b
jb 0x10346
testb %r11b, %r11b
jg 0x1034f
jmp 0x103fc
testb %r11b, %r11b
jns 0x103fc
addq $0x20, %r8
cmpq $0x1a00, %r8            # imm = 0x1A00
jb 0x102f0
testl %eax, %eax
je 0x103f4
cmpl $0x1, %eax
jne 0x103e2
movl $0x1, %eax
testb $0x8, %sil
je 0x103e2
btl $0xa, %ecx
movb 0x10(%rsp), %cl
jb 0x103ca
movb %cl, 0x11(%rsp)
movb $0x1b, 0x10(%rsp)
movl $0x2, %eax
jmp 0x103e2
movl 0x50(%rbx), %ecx
testl $0xffff9fef, %ecx       # imm = 0xFFFF9FEF
setne %dl
testl $0xffe3, %ecx           # imm = 0xFFE3
sete %cl
testb %cl, %dl
jne 0x103f4
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0x8f2f
xorl %eax, 0xd85b(%rip)      # 0x1dc18
jmp 0x103f4
leaq (%r8,%rsi), %rdi
callq *-0x8(%rsi,%r8)
jmp 0x103f4
cmpb $0x7f, %cl
je 0x103e2
movsbl %cl, %edi
orl $0x80, %edi
leaq 0x10(%rsp), %rsi
callq 0x708d
movslq %eax, %rsi
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
callq 0x7ffe
addq $0x58, %rsp
popq %rbx
popq %r14
retq
movq 0x30(%r8,%r9), %rbx
testq %rbx, %rbx
je 0x1035c
movq %rbx, %rdi
callq 0x6390
movq %rbx, %rdi
movq %rax, %rsi
jmp 0x103ea