// File: /workspace/github_c_makefile_star2_O1/baskerville[P]sxhkd/src/parse.c
// Function: process_hotkey
void process_hotkey(char *hotkey_string, char *command_string)
{
	char hotkey[2 * MAXLEN] = {0};
	char command[2 * MAXLEN] = {0};
	char last_hotkey[2 * MAXLEN] = {0};
	unsigned char num_same = 0;
	chunk_t *hk_chunks = extract_chunks(hotkey_string);
	chunk_t *cm_chunks = extract_chunks(command_string);

#define CHECKCHUNK(s, c) \
	if (c->next == NULL && !c->sequence) { \
		snprintf(s, sizeof(s), "%s", c->text); \
		destroy_chunks(c); \
		c = NULL; \
	}
	CHECKCHUNK(hotkey, hk_chunks)
	CHECKCHUNK(command, cm_chunks)
#undef CHECKCHUNK

	render_next(hk_chunks, hotkey);
	render_next(cm_chunks, command);

	while ((hk_chunks == NULL || hotkey[0] != '\0') && (cm_chunks == NULL || command[0] != '\0')) {

		PRINTF("%s: %s\n", hotkey, command);
		chain_t *chain = make_chain();
		if (parse_chain(hotkey, chain)) {
			hotkey_t *hk = make_hotkey(chain, command);
			for (hotkey_t* i = hotkeys_head; i; i = i->next) {
				if (chains_interfere(i->chain, hk->chain)) {
					warn("Hotkey interference found and may not be matched: '%s' (from '%s').\n", hotkey, hotkey_string);
				}
			}
			add_hotkey(hk);
			if (strcmp(hotkey, last_hotkey) == 0)
				num_same++;
		} else {
			destroy_chain(chain);
		}

		if (hk_chunks == NULL && cm_chunks == NULL)
			break;

		snprintf(last_hotkey, sizeof(last_hotkey), "%s", hotkey);

		render_next(hk_chunks, hotkey);
		render_next(cm_chunks, command);
	}

	if (num_same > 0) {
		int period = num_same + 1;
		int delay = num_same;
		for (hotkey_t *hk = hotkeys_tail; hk != NULL && delay >= 0; hk = hk->prev, delay--)
			hk->cycle = make_cycle(delay, period);
	}

	if (hk_chunks != NULL)
		destroy_chunks(hk_chunks);
	if (cm_chunks != NULL)
		destroy_chunks(cm_chunks);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x210(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0xe190
leaq 0x10(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0xe190
leaq 0x410(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0xe190
movq %r14, %r13
movq %r14, %rdi
callq 0xfa8c
movq %rax, %r14
movq %rbx, %rdi
callq 0xfa8c
movq %rax, %rbx
cmpq $0x0, 0x410(%r14)
jne 0xf71a
cmpb $0x0, 0x408(%r14)
jne 0xf71a
leaq 0x2a43(%rip), %rdx      # 0x12127
leaq 0x210(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0xe170
testq %r14, %r14
je 0xf717
movq 0x410(%r14), %r15
movq %r14, %rdi
callq 0xe040
movq %r15, %r14
testq %r15, %r15
jne 0xf700
xorl %r14d, %r14d
cmpq $0x0, 0x410(%rbx)
jne 0xf766
cmpb $0x0, 0x408(%rbx)
jne 0xf766
leaq 0x29f3(%rip), %rdx      # 0x12127
leaq 0x10(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe170
testq %rbx, %rbx
je 0xf764
movq 0x410(%rbx), %r15
movq %rbx, %rdi
callq 0xe040
movq %r15, %rbx
testq %r15, %r15
jne 0xf74d
xorl %ebx, %ebx
leaq 0x210(%rsp), %rsi
movq %r14, %rdi
callq 0xfc50
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xfc50
testq %r14, %r14
je 0xf79a
cmpb $0x0, 0x210(%rsp)
jne 0xf79a
xorl %r15d, %r15d
jmp 0xf8aa
movq %r14, %rax
orq %rbx, %rax
sete 0xb(%rsp)
xorl %r15d, %r15d
leaq 0x210(%rsp), %r12
testq %rbx, %rbx
je 0xf7c0
cmpb $0x0, 0x10(%rsp)
je 0xf8aa
callq 0x11062
movq %rax, %rbp
movq %r12, %rdi
movq %rax, %rsi
callq 0xfdfe
testb %al, %al
je 0xf828
movl %r15d, 0xc(%rsp)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x1109a
movq %rax, %rbp
leaq 0x13cbd(%rip), %rax     # 0x234b0
movq (%rax), %r15
testq %r15, %r15
je 0xf832
movq (%r15), %rdi
movq (%rbp), %rsi
callq 0x10d4e
testb %al, %al
je 0xf81f
leaq 0x8aff(%rip), %rdi      # 0x18311
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe410
movq 0x218(%r15), %r15
jmp 0xf7f6
movq %rbp, %rdi
callq 0x11147
jmp 0xf856
movq %rbp, %rdi
callq 0x11112
movq %r12, %rdi
leaq 0x410(%rsp), %rsi
callq 0xe220
cmpl $0x1, %eax
movl 0xc(%rsp), %r15d
adcb $0x0, %r15b
cmpb $0x0, 0xb(%rsp)
jne 0xf8aa
movl $0x200, %esi            # imm = 0x200
leaq 0x410(%rsp), %rdi
leaq 0x28b6(%rip), %rdx      # 0x12127
movq %r12, %rcx
xorl %eax, %eax
callq 0xe170
movq %r14, %rdi
movq %r12, %rsi
callq 0xfc50
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xfc50
testq %r14, %r14
je 0xf7b0
cmpb $0x0, 0x210(%rsp)
jne 0xf7b0
testb %r15b, %r15b
je 0xf8f1
leaq 0x13bf2(%rip), %rax     # 0x234a8
movq (%rax), %r12
testq %r12, %r12
je 0xf8f1
movzbl %r15b, %r15d
leal 0x1(%r15), %ebp
movl %r15d, %edi
movl %ebp, %esi
callq 0x1107d
movq %rax, 0x210(%r12)
movq 0x220(%r12), %r12
testq %r12, %r12
je 0xf8f1
leal -0x1(%r15), %eax
testl %r15d, %r15d
movl %eax, %r15d
jg 0xf8c6
testq %r14, %r14
je 0xf90d
movq 0x410(%r14), %r15
movq %r14, %rdi
callq 0xe040
movq %r15, %r14
testq %r15, %r15
jne 0xf8f6
testq %rbx, %rbx
je 0xf929
movq 0x410(%rbx), %r14
movq %rbx, %rdi
callq 0xe040
movq %r14, %rbx
testq %r14, %r14
jne 0xf912
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq