// File: /workspace/github_c_makefile_star2_O1/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, 0xe275(%rip)     # 0x1dc28
jne 0xfbdd
movq %rdi, %rbx
movq 0xe195(%rip), %rdi      # 0x1db58
testq %rdi, %rdi
je 0xf9f0
leaq 0x10(%rsp), %rdx
movq %rsp, %r8
leaq 0xc(%rsp), %r14
movq %rbx, %rsi
movl $0x40, %ecx
movq %r14, %r9
callq 0x6770
cmpl $-0x1, (%r14)
jne 0xfa08
jmp 0xfbdd
leaq 0x10(%rsp), %rsi
movq %rsp, %rcx
movq %rbx, %rdi
movl $0x40, %edx
xorl %r8d, %r8d
callq 0x6150
movl 0xe21a(%rip), %ecx      # 0x1dc28
btl $0x12, %ecx
jb 0xfaa5
movl $0x18, %edx
movq (%rsp), %rdi
leaq 0xa798(%rip), %rsi      # 0x1a1c0
movl $0xffff9fef, %r8d       # imm = 0xFFFF9FEF
cmpq -0x10(%rdx,%rsi), %rdi
jne 0xfa54
movl -0x18(%rdx,%rsi), %r9d
cmpl $-0x1, %r9d
je 0xfadd
movl 0x50(%rbx), %r10d
andl %r8d, %r10d
cmpl %r9d, %r10d
je 0xfadd
leaq 0x20(%rdx), %r9
addq $-0x18, %rdx
cmpq $0x200, %rdx            # imm = 0x200
movq %r9, %rdx
jb 0xfa2e
movq (%rsp), %rsi
movl 0x50(%rbx), %edx
xorl %r8d, %r8d
movl %r8d, %edi
cmpq $-0x1, %rsi
je 0xfa84
movb $0x1, %r8b
testb $0x1, %dil
je 0xfa72
movl %esi, %r8d
andl $0xff00, %r8d           # imm = 0xFF00
cmpl $0xfd00, %r8d           # imm = 0xFD00
setb %r8b
testb %dil, %r8b
je 0xfaea
xorl %ebx, %ebx
jmp 0xfb6a
movl 0x50(%rbx), %ecx
testl $0xffff9fef, %ecx       # imm = 0xFFFF9FEF
setne %dl
testl $0xffe3, %ecx           # imm = 0xFFE3
sete %cl
testb %cl, %dl
jne 0xfbdd
movq (%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0x8c54
xorl %eax, 0xe150(%rip)      # 0x1dc28
jmp 0xfbdd
leaq (%rsi,%rdx), %rdi
callq *-0x8(%rdx,%rsi)
jmp 0xfbdd
movl %edx, %edi
andl $0xffff9fef, %edi       # imm = 0xFFFF9FEF
movq $-0x20, %r8
leaq 0x7870(%rip), %r9       # 0x17370
xorl %ebx, %ebx
cmpq %rsi, 0x20(%r8,%r9)
jne 0xfb5d
movl 0x28(%r8,%r9), %r10d
cmpl $-0x1, %r10d
setne %r11b
cmpl %r10d, %edi
setne %r10b
testb %r10b, %r11b
jne 0xfb5d
movb 0x38(%r8,%r9), %r10b
testb $0x4, %cl
jne 0xfb33
testb %r10b, %r10b
jg 0xfb5d
jmp 0xfb38
testb %r10b, %r10b
js 0xfb5d
btl $0x11, %ecx
jae 0xfb46
cmpb $0x2, 0x38(%r8,%r9)
je 0xfb5d
btl $0x8, %ecx
movb 0x39(%r8,%r9), %r10b
jb 0xfb58
testb %r10b, %r10b
jg 0xfb5d
jmp 0xfbac
testb %r10b, %r10b
jns 0xfbac
addq $0x20, %r8
cmpq $0x1a00, %r8            # imm = 0x1A00
jb 0xfb02
testq %rbx, %rbx
je 0xfb7f
movq %rbx, %rdi
callq 0x6390
movq %rbx, %rdi
movq %rax, %rsi
jmp 0xfbd3
testl %eax, %eax
je 0xfbdd
cmpl $0x1, %eax
jne 0xfbcb
movl $0x1, %eax
testb $0x8, %dl
je 0xfbcb
btl $0xa, %ecx
movb 0x10(%rsp), %cl
jb 0xfbb3
movb %cl, 0x11(%rsp)
movb $0x1b, 0x10(%rsp)
movl $0x2, %eax
jmp 0xfbcb
movq 0x30(%r8,%r9), %rbx
jmp 0xfb6a
cmpb $0x7f, %cl
je 0xfbcb
movsbl %cl, %edi
orl $0x80, %edi
leaq 0x10(%rsp), %rsi
callq 0x709d
movslq %eax, %rsi
leaq 0x10(%rsp), %rdi
movl $0x1, %edx
callq 0x7f0a
addq $0x58, %rsp
popq %rbx
popq %r14
retq