// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movb %cl, %al
movw %dx, %cx
movb %sil, %dl
movl %edi, -0xc(%rbp)
movb %dl, -0xd(%rbp)
movw %cx, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %r8, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
leaq 0x11e42(%rip), %rax     # 0x234c0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1194e
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq 0x11def(%rip), %rax     # 0x23491
testb $0x1, (%rax)
je 0x116b8
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
je 0x116d6
leaq 0x11dd1(%rip), %rax     # 0x23490
testb $0x1, (%rax)
je 0x116db
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
je 0x116db
jmp 0x1193a
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
movb -0x11(%rbp), %cl
movl -0xc(%rbp), %edx
movb -0xd(%rbp), %al
movzbl %cl, %esi
movzbl %al, %ecx
movzwl -0x10(%rbp), %r8d
callq 0x11a50
testb $0x1, %al
jne 0x11705
jmp 0x118eb
leaq 0x11c44(%rip), %rax     # 0x23350
cmpq $0x0, (%rax)
je 0x117c0
cmpl $0x0, -0x24(%rbp)
jne 0x117c0
leaq 0x11d6a(%rip), %rax     # 0x23491
testb $0x1, (%rax)
jne 0x11750
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x11d95(%rip), %rdi     # 0x234d0
movl $0x300, %esi            # imm = 0x300
leaq 0x1a32(%rip), %rdx      # 0x13179
movb $0x0, %al
callq 0xe170
jmp 0x117af
leaq 0x11d79(%rip), %rdi     # 0x234d0
callq 0xe120
movl $0x300, %edx            # imm = 0x300
subq %rax, %rdx
subq $0x1, %rdx
leaq 0x11d61(%rip), %rdi     # 0x234d0
leaq 0x7c5d(%rip), %rsi      # 0x193d3
callq 0xe1a0
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
leaq 0x11d42(%rip), %rdi     # 0x234d0
callq 0xe120
movq -0x50(%rbp), %rsi
movl $0x300, %edx            # imm = 0x300
subq %rax, %rdx
subq $0x1, %rdx
leaq 0x11d26(%rip), %rdi     # 0x234d0
callq 0xe1a0
movl $0x48, %edi
leaq 0x11d15(%rip), %rsi     # 0x234d0
callq 0xefc0
cmpq $0x0, -0x20(%rbp)
je 0x117df
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
testb $0x1, 0x109(%rax)
je 0x117df
movq -0x20(%rbp), %rax
movb $0x1, (%rax)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
testb $0x1, 0x10a(%rax)
je 0x1180e
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
leaq 0x11b64(%rip), %rax     # 0x23364
cmpl $0x0, (%rax)
jle 0x1180c
xorl %edi, %edi
callq 0xe1c0
jmp 0x1180e
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x118bc
movq -0x38(%rbp), %rax
cmpq $0x0, 0x210(%rax)
je 0x11892
movq -0x38(%rbp), %rax
movq 0x210(%rax), %rax
movl 0x4(%rax), %eax
movb %al, -0x41(%rbp)
movzbl -0x41(%rbp), %eax
cmpl $0x0, %eax
jne 0x11861
movq -0x38(%rbp), %rax
movq 0x210(%rax), %rax
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x1186b
movzbl -0x41(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %ecx
movq -0x38(%rbp), %rax
movq 0x210(%rax), %rax
movl %ecx, 0x4(%rax)
movzbl -0x41(%rbp), %eax
cmpl $0x0, %eax
jne 0x1188d
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x1193a
leaq 0x11bf8(%rip), %rax     # 0x23491
testb $0x1, (%rax)
je 0x118af
leaq 0x11beb(%rip), %rax     # 0x23490
testb $0x1, (%rax)
jne 0x118af
callq 0x11b00
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x11a45
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x110(%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xf0f0
jmp 0x11938
leaq 0x11b9f(%rip), %rax     # 0x23491
testb $0x1, (%rax)
je 0x11936
leaq 0x11b92(%rip), %rax     # 0x23490
testb $0x1, (%rax)
jne 0x1192b
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movzbl 0x108(%rax), %eax
movzbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
jne 0x1192b
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x11934
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x11936
jmp 0x11938
jmp 0x1193a
movq -0x38(%rbp), %rax
movq 0x218(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x11685
cmpq $0x0, -0x30(%rbp)
je 0x11962
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x11a45
cmpl $0x0, -0x28(%rbp)
jle 0x11972
leaq 0x11b21(%rip), %rax     # 0x23490
movb $0x1, (%rax)
leaq 0x11b18(%rip), %rax     # 0x23491
testb $0x1, (%rax)
jne 0x119b0
cmpl $0x0, -0x24(%rbp)
jle 0x119ae
leaq 0x11b06(%rip), %rax     # 0x23491
movb $0x1, (%rax)
movl $0x42, %edi
leaq 0x7a3b(%rip), %rsi      # 0x193d5
callq 0xefc0
leaq 0x11ada(%rip), %rax     # 0x23480
movq (%rax), %rdi
callq 0xf0f0
jmp 0x11a0b
cmpl $0x0, -0x24(%rbp)
je 0x119df
leaq 0x11ac3(%rip), %rax     # 0x23480
movq (%rax), %rdi
movb -0x11(%rbp), %cl
movl -0xc(%rbp), %edx
movb -0xd(%rbp), %al
movzbl %cl, %esi
movzbl %al, %ecx
movzwl -0x10(%rbp), %r8d
callq 0x11a50
testb $0x1, %al
jne 0x119df
jmp 0x11a09
callq 0x11b00
movl -0xc(%rbp), %edi
movb -0xd(%rbp), %dl
movw -0x10(%rbp), %cx
movb -0x11(%rbp), %al
movq -0x20(%rbp), %r8
movzbl %dl, %esi
movzwl %cx, %edx
movzbl %al, %ecx
callq 0x11640
movq %rax, -0x8(%rbp)
jmp 0x11a45
jmp 0x11a0b
leaq 0x11a7f(%rip), %rax     # 0x23491
testb $0x1, (%rax)
je 0x11a3d
leaq 0x11a72(%rip), %rax     # 0x23490
testb $0x1, (%rax)
jne 0x11a3d
leaq 0x1193a(%rip), %rax     # 0x23364
cmpl $0x0, (%rax)
jle 0x11a3d
leaq 0x1192e(%rip), %rax     # 0x23364
movl (%rax), %edi
callq 0xe1c0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop