// File: /workspace/github_c_makefile_star2_O3/baskerville[P]sxhkd/src/types.c
// Function: find_hotkey
hotkey_t *find_hotkey(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool *replay_event)
{
	int num_active = 0;
	int num_locked = 0;
	hotkey_t *result = NULL;

	for (hotkey_t *hk = hotkeys_head; hk != NULL; hk = hk->next) {
		chain_t *c = hk->chain;
		if ((chained && c->state == c->head) || (locked && c->state != c->tail))
			continue;
		if (match_chord(c->state, event_type, keysym, button, modfield)) {
			if (status_fifo != NULL && num_active == 0) {
				if (!chained) {
					snprintf(progress, sizeof(progress), "%s", c->state->repr);
				} else {
					strncat(progress, ";", sizeof(progress) - strlen(progress) - 1);
					strncat(progress, c->state->repr, sizeof(progress) - strlen(progress) - 1);
				}
				put_status(HOTKEY_PREFIX, progress);
			}
			if (replay_event != NULL && c->state->replay_event)
				*replay_event = true;
			if (c->state->lock_chain) {
				num_locked += 1;
				if (timeout > 0)
					alarm(0);
			}
			if (c->state == c->tail) {
				if (hk->cycle != NULL) {
					unsigned char delay = hk->cycle->delay;
					hk->cycle->delay = (delay == 0 ? hk->cycle->period - 1 : delay - 1);
					if (delay == 0)
						result = hk;
					continue;
				}
				if (chained && !locked)
					abort_chain();
				return hk;
			} else {
				c->state = c->state->next;
				num_active++;
				grab_chord(c->state);
			}
		} else if (chained) {
			if (!locked && c->state->event_type == event_type)
				c->state = c->head;
			else
				num_active++;
		}
	}

	if (result != NULL)
		return result;

	if (num_locked > 0) {
		locked = true;
	}

	if (!chained) {
		if (num_active > 0) {
			chained = true;
			put_status(BEGIN_CHAIN_PREFIX, "Begin chain");
			grab_chord(abort_chord);
		}
	} else if (num_active == 0 || match_chord(abort_chord, event_type, keysym, button, modfield)) {
		abort_chain();
		return find_hotkey(keysym, button, modfield, event_type, replay_event);
	}
	if (chained && !locked && timeout > 0)
		alarm(timeout);
	PRINTF("num active %i\n", num_active);

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %r15d
movl %edi, %r12d
leaq 0x11cf7(%rip), %r13     # 0x224b0
leaq 0x11cc1(%rip), %r9      # 0x22481
leaq 0x11cb9(%rip), %r8      # 0x22480
leaq 0x11cf2(%rip), %rdi     # 0x224c0
movq (%r13), %rbx
testq %rbx, %rbx
je 0x10a69
xorl %r11d, %r11d
movq $0x0, 0x10(%rsp)
movl $0x0, 0x4(%rsp)
movq (%rbx), %r13
movb (%r9), %al
cmpb $0x1, %al
jne 0x10803
movq 0x10(%r13), %rcx
cmpq (%r13), %rcx
je 0x10879
movb (%r8), %dl
movq 0x10(%r13), %rcx
cmpb $0x1, %dl
jne 0x10815
cmpq 0x8(%r13), %rcx
jne 0x10879
testq %rcx, %rcx
je 0x1085b
movq %rcx, %rsi
cmpb %bpl, 0x108(%rsi)
jne 0x1084f
cmpl %r12d, 0x100(%rsi)
jne 0x1084f
cmpb %r15b, 0x104(%rsi)
jne 0x1084f
movzwl 0x106(%rsi), %r10d
cmpl $0x8000, %r10d          # imm = 0x8000
je 0x1088e
cmpw %r14w, %r10w
je 0x1088e
movq 0x118(%rsi), %rsi
testq %rsi, %rsi
jne 0x1081d
testb %al, %al
je 0x10879
testb %dl, %dl
jne 0x10876
cmpb %bpl, 0x108(%rcx)
jne 0x10876
movq (%r13), %rax
movq %rax, 0x10(%r13)
jmp 0x10879
incl %r11d
movq 0x218(%rbx), %rbx
testq %rbx, %rbx
jne 0x107ef
jmp 0x109f1
leaq 0x11aab(%rip), %rdx     # 0x22340
cmpq $0x0, (%rdx)
setne %dl
testl %r11d, %r11d
sete %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x1093d
movq %r11, 0x8(%rsp)
testb %al, %al
je 0x10909
callq 0xe130
movl $0x2ff, %edx            # imm = 0x2FF
subq %rax, %rdx
leaq 0x11bf3(%rip), %rdi     # 0x224c0
leaq 0x6b4c(%rip), %rsi      # 0x17420
callq 0xe1a0
movq 0x10(%r13), %rax
movq %rax, 0x20(%rsp)
leaq 0x11bd7(%rip), %rdi     # 0x224c0
callq 0xe130
movl $0x2ff, %edx            # imm = 0x2FF
subq %rax, %rdx
leaq 0x11bc3(%rip), %rdi     # 0x224c0
movq 0x20(%rsp), %rsi
callq 0xe1a0
jmp 0x1091c
movl $0x300, %esi            # imm = 0x300
leaq 0x812(%rip), %rdx       # 0x11127
xorl %eax, %eax
callq 0xe170
movl $0x48, %edi
leaq 0x11b98(%rip), %rsi     # 0x224c0
callq 0xee68
movq 0x10(%r13), %rcx
leaq 0x11b48(%rip), %r8      # 0x22480
movq 0x8(%rsp), %r11
cmpq $0x0, 0x18(%rsp)
je 0x10956
cmpb $0x1, 0x109(%rcx)
jne 0x10956
movq 0x18(%rsp), %rax
movb $0x1, (%rax)
cmpb $0x1, 0x10a(%rcx)
jne 0x1098b
incl 0x4(%rsp)
leaq 0x119ea(%rip), %rax     # 0x22354
cmpl $0x0, (%rax)
jle 0x1098b
xorl %edi, %edi
movq %r11, 0x8(%rsp)
callq 0xe1c0
movq 0x8(%rsp), %r11
leaq 0x11af9(%rip), %r8      # 0x22480
movq 0x10(%r13), %rcx
cmpq 0x8(%r13), %rcx
je 0x109ba
movq 0x110(%rcx), %rdi
movq %rdi, 0x10(%r13)
incl %r11d
movq %r11, %r13
callq 0xef2b
movq %r13, %r11
leaq 0x11acf(%rip), %r8      # 0x22480
leaq 0x11ac9(%rip), %r9      # 0x22481
jmp 0x109e5
movq 0x210(%rbx), %rax
testq %rax, %rax
je 0x10af0
movzbl 0x4(%rax), %ecx
testl %ecx, %ecx
leaq 0x11aaa(%rip), %r9      # 0x22481
jne 0x109e0
movl (%rax), %ecx
movq %rbx, 0x10(%rsp)
decl %ecx
movl %ecx, 0x4(%rax)
leaq 0x11ad4(%rip), %rdi     # 0x224c0
jmp 0x10879
movq 0x10(%rsp), %rax
testq %rax, %rax
jne 0x10ae1
cmpl $0x0, 0x4(%rsp)
jle 0x10a0a
movb $0x1, (%r8)
movb (%r9), %al
testb %al, %al
leaq 0x11a9a(%rip), %r13     # 0x224b0
je 0x10a8f
testl %r11d, %r11d
je 0x10a70
leaq 0x11a4c(%rip), %rcx     # 0x22470
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x10abd
cmpb %bpl, 0x108(%rcx)
jne 0x10a60
cmpl %r12d, 0x100(%rcx)
jne 0x10a60
cmpb %r15b, 0x104(%rcx)
jne 0x10a60
movzwl 0x106(%rcx), %edx
cmpl $0x8000, %edx           # imm = 0x8000
je 0x10a70
cmpw %r14w, %dx
je 0x10a70
movq 0x118(%rcx), %rcx
jmp 0x10a27
movb (%r9), %al
testb %al, %al
je 0x10abd
callq 0x10b4f
leaq 0x11a44(%rip), %rdi     # 0x224c0
leaq 0x119fe(%rip), %r9      # 0x22481
leaq 0x119f6(%rip), %r8      # 0x22480
jmp 0x107ce
testl %r11d, %r11d
jle 0x10abd
movb $0x1, (%r9)
leaq 0x6983(%rip), %rsi      # 0x17422
movl $0x42, %edi
movq %r9, %rbx
callq 0xee68
leaq 0x119bd(%rip), %rax     # 0x22470
movq (%rax), %rdi
callq 0xef2b
movb (%rbx), %al
testb $0x1, %al
je 0x10adf
leaq 0x1188c(%rip), %rax     # 0x22354
movl (%rax), %edi
testl %edi, %edi
setle %al
leaq 0x119aa(%rip), %rcx     # 0x22480
orb (%rcx), %al
jne 0x10adf
callq 0xe1c0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1198a(%rip), %rax     # 0x22481
cmpb $0x1, (%rax)
jne 0x10b07
cmpb $0x0, (%r8)
jne 0x10b07
callq 0x10b4f
movq %rbx, %rax
jmp 0x10ae1