// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %r8, 0x30(%rsp)
movl %edi, 0x14(%rsp)
leaq 0x11ef6(%rip), %rbp     # 0x224b0
leaq 0x11ec0(%rip), %r12     # 0x22481
movl %ecx, 0x2c(%rsp)
movzbl %cl, %eax
movl %eax, 0x10(%rsp)
movzbl %sil, %eax
movl %eax, 0xc(%rsp)
movzwl %dx, %eax
movl %eax, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
xorl %edx, %edx
xorl %esi, %esi
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x107cf
movq (%rbp), %r13
movb (%r12), %r15b
cmpb $0x1, %r15b
jne 0x10611
movq 0x10(%r13), %rax
cmpq (%r13), %rax
je 0x107c3
movq %r12, %r14
leaq 0x11e65(%rip), %rax     # 0x22480
movb (%rax), %r12b
movq 0x10(%r13), %rbx
cmpb $0x1, %r12b
jne 0x10632
cmpq 0x8(%r13), %rbx
jne 0x106f5
movl %esi, 0x4(%rsp)
movq %rdx, 0x20(%rsp)
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
callq 0x108b4
testb %al, %al
je 0x106c5
leaq 0x11ce1(%rip), %rax     # 0x22340
cmpq $0x0, (%rax)
setne %al
movl 0x4(%rsp), %esi
testl %esi, %esi
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x106ee
testb %r15b, %r15b
movq %r14, %r12
je 0x106fd
leaq 0x11e3b(%rip), %r14     # 0x224c0
movq %r14, %rdi
callq 0xe130
movl $0x2ff, %edx            # imm = 0x2FF
subq %rax, %rdx
movq %r14, %rdi
leaq 0x6d81(%rip), %rsi      # 0x17420
callq 0xe1a0
movq 0x10(%r13), %rbx
movq %r14, %rdi
callq 0xe130
movl $0x2ff, %edx            # imm = 0x2FF
subq %rax, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xe1a0
jmp 0x1071d
testb %r15b, %r15b
movq 0x20(%rsp), %rdx
movl 0x4(%rsp), %esi
je 0x106f5
testb %r12b, %r12b
jne 0x106f3
movl 0x2c(%rsp), %eax
cmpb %al, 0x108(%rbx)
jne 0x106f3
movq (%r13), %rax
movq %rax, 0x10(%r13)
jmp 0x106f5
movq %r14, %r12
jmp 0x10730
incl %esi
movq %r14, %r12
jmp 0x107c3
movl $0x300, %esi            # imm = 0x300
leaq 0x11db7(%rip), %r14     # 0x224c0
movq %r14, %rdi
leaq 0xa14(%rip), %rdx       # 0x11127
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe170
pushq $0x48
popq %rdi
movq %r14, %rsi
callq 0xed3a
movq 0x10(%r13), %rbx
movl 0x4(%rsp), %esi
cmpq $0x0, 0x30(%rsp)
je 0x10749
cmpb $0x1, 0x109(%rbx)
jne 0x10749
movq 0x30(%rsp), %rax
movb $0x1, (%rax)
cmpb $0x1, 0x10a(%rbx)
jne 0x10779
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
leaq 0x11bef(%rip), %rax     # 0x22354
cmpl $0x0, (%rax)
jle 0x10779
xorl %edi, %edi
callq 0xe1c0
movl 0x4(%rsp), %esi
movq 0x10(%r13), %rbx
cmpq 0x8(%r13), %rbx
je 0x1079c
movq 0x110(%rbx), %rdi
movq %rdi, 0x10(%r13)
incl %esi
movl %esi, %ebx
callq 0xedfb
movl %ebx, %esi
movq 0x20(%rsp), %rdx
jmp 0x107c3
movq 0x210(%rbp), %rax
testq %rax, %rax
movq 0x20(%rsp), %rdx
je 0x10897
movzbl 0x4(%rax), %ecx
testl %ecx, %ecx
jne 0x107be
movl (%rax), %ecx
movq %rbp, %rdx
decl %ecx
movl %ecx, 0x4(%rax)
addq $0x218, %rbp            # imm = 0x218
jmp 0x105e8
testq %rdx, %rdx
jne 0x10885
cmpl $0x0, 0x18(%rsp)
jle 0x107e9
leaq 0x11c9a(%rip), %rax     # 0x22480
movb $0x1, (%rax)
movb (%r12), %bl
testb %bl, %bl
je 0x10835
testl %esi, %esi
je 0x10819
leaq 0x11c74(%rip), %rax     # 0x22470
movq (%rax), %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movl 0xc(%rsp), %ecx
movl 0x8(%rsp), %r8d
callq 0x108b4
testb %al, %al
je 0x10860
callq 0x108f5
movq $0x0, 0x18(%rsp)
xorl %edx, %edx
leaq 0x11c80(%rip), %rbp     # 0x224b0
jmp 0x105e6
testl %esi, %esi
jle 0x10860
movb $0x1, (%r12)
leaq 0x6bdd(%rip), %rsi      # 0x17422
pushq $0x42
popq %rdi
callq 0xed3a
leaq 0x11c1c(%rip), %rax     # 0x22470
movq (%rax), %rdi
callq 0xedfb
movb (%r12), %bl
testb $0x1, %bl
je 0x10883
leaq 0x11ae8(%rip), %rax     # 0x22354
movl (%rax), %edi
testl %edi, %edi
setle %al
leaq 0x11c06(%rip), %rcx     # 0x22480
orb (%rcx), %al
jne 0x10883
callq 0xe1c0
xorl %edx, %edx
movq %rdx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, (%r12)
jne 0x108af
leaq 0x11bdb(%rip), %rax     # 0x22480
cmpb $0x0, (%rax)
jne 0x108af
callq 0x108f5
movq %rbp, %rdx
jmp 0x10885