// File: /workspace/github_c_makefile_star2_O2/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, %r15
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 %r15, %rdi
callq 0xf966
movq %rax, %r14
movq %rbx, %rdi
callq 0xf966
movq %rax, %rbx
cmpq $0x0, 0x410(%r14)
jne 0xf643
cmpb $0x0, 0x408(%r14)
jne 0xf643
leaq 0x1b06(%rip), %rdx      # 0x11127
leaq 0x210(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0xe170
movq %r14, %rdi
callq 0xfa5d
xorl %r14d, %r14d
cmpq $0x0, 0x410(%rbx)
jne 0xf67b
cmpb $0x0, 0x408(%rbx)
jne 0xf67b
leaq 0x1aca(%rip), %rdx      # 0x11127
leaq 0x10(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe170
movq %rbx, %rdi
callq 0xfa5d
xorl %ebx, %ebx
leaq 0x210(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xfa76
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xfa76
movq %r14, %rax
orq %rbx, %rax
sete 0x3(%rsp)
movl $0x0, 0x4(%rsp)
leaq 0x7c5c(%rip), %r13      # 0x17311
movq %rbx, 0x8(%rsp)
testq %r14, %r14
je 0xf6cd
cmpb $0x0, 0x210(%rsp)
je 0xf7af
testq %rbx, %rbx
je 0xf6dd
cmpb $0x0, 0x10(%rsp)
je 0xf7af
callq 0x10bde
movq %rax, %rbp
movq %r12, %rdi
movq %rax, %rsi
callq 0xfc58
movq %rbp, %rdi
testb %al, %al
je 0xf73c
leaq 0x10(%rsp), %rsi
callq 0x10c04
movq %rax, %rbp
leaq 0x12da5(%rip), %rbx     # 0x224b0
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xf743
movq (%rbx), %rdi
movq (%rbp), %rsi
callq 0x10958
testb %al, %al
je 0xf733
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0xf160
addq $0x218, %rbx            # imm = 0x218
jmp 0xf70b
callq 0x10cae
jmp 0xf76d
movq %rbp, %rdi
callq 0x10c79
movq %r12, %rdi
leaq 0x410(%rsp), %rsi
callq 0xe220
cmpl $0x1, %eax
movl 0x4(%rsp), %eax
adcb $0x0, %al
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rbx
cmpb $0x0, 0x3(%rsp)
jne 0xf7af
movl $0x200, %esi            # imm = 0x200
leaq 0x410(%rsp), %rdi
leaq 0x199f(%rip), %rdx      # 0x11127
movq %r12, %rcx
xorl %eax, %eax
callq 0xe170
movq %r14, %rdi
movq %r12, %rsi
callq 0xfa76
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xfa76
jmp 0xf6ba
movl 0x4(%rsp), %eax
testb %al, %al
je 0xf7f0
movzbl %al, %r15d
leal 0x1(%r15), %ebp
leaq 0x12ce2(%rip), %rbx     # 0x224a8
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xf7f0
testl %r15d, %r15d
js 0xf7f0
movl %r15d, %edi
movl %ebp, %esi
callq 0x10be9
movq %rax, 0x210(%rbx)
addq $0x220, %rbx            # imm = 0x220
decl %r15d
jmp 0xf7c6
testq %r14, %r14
je 0xf7fd
movq %r14, %rdi
callq 0xfa5d
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xf80c
callq 0xfa5d
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq