// File: /workspace/github_c_makefile_star2_O3/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 0xfa6f
movq %rax, %r14
movq %rbx, %rdi
callq 0xfa6f
movq %rax, %rbx
cmpq $0x0, 0x410(%r14)
jne 0xf706
cmpb $0x0, 0x408(%r14)
jne 0xf706
leaq 0x1a52(%rip), %rdx      # 0x11127
leaq 0x210(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %r14, %rcx
xorl %eax, %eax
callq 0xe170
movq 0x410(%r14), %r12
movq %r14, %rdi
callq 0xe040
movq %r12, %r14
testq %r12, %r12
jne 0xf6ec
xorl %r14d, %r14d
cmpq $0x0, 0x410(%rbx)
jne 0xf74d
cmpb $0x0, 0x408(%rbx)
jne 0xf74d
leaq 0x1a07(%rip), %rdx      # 0x11127
leaq 0x10(%rsp), %rdi
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rcx
xorl %eax, %eax
callq 0xe170
movq 0x410(%rbx), %r12
movq %rbx, %rdi
callq 0xe040
movq %r12, %rbx
testq %r12, %r12
jne 0xf734
xorl %ebx, %ebx
leaq 0x210(%rsp), %rsi
movq %r14, %rdi
callq 0xfbcc
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xfbcc
testq %r14, %r14
je 0xf77d
cmpb $0x0, 0x210(%rsp)
je 0xf8d9
movq %r14, %rax
orq %rbx, %rax
sete 0xb(%rsp)
xorl %r13d, %r13d
leaq 0x210(%rsp), %r12
testq %rbx, %rbx
je 0xf7a3
cmpb $0x0, 0x10(%rsp)
je 0xf88e
callq 0x10e7e
movq %rax, %rbp
movq %r12, %rdi
movq %rax, %rsi
callq 0xfd96
testb %al, %al
je 0xf80c
movl %r13d, 0xc(%rsp)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x10eaa
movq %rax, %rbp
leaq 0x12cda(%rip), %rax     # 0x224b0
movq (%rax), %r13
testq %r13, %r13
je 0xf816
movq (%r13), %rdi
movq (%rbp), %rsi
callq 0x10bb5
testb %al, %al
je 0xf803
leaq 0x7b1b(%rip), %rdi      # 0x17311
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe410
movq 0x218(%r13), %r13
jmp 0xf7d9
movq %rbp, %rdi
callq 0x10f57
jmp 0xf83a
movq %rbp, %rdi
callq 0x10f22
movq %r12, %rdi
leaq 0x410(%rsp), %rsi
callq 0xe220
cmpl $0x1, %eax
movl 0xc(%rsp), %r13d
adcb $0x0, %r13b
cmpb $0x0, 0xb(%rsp)
jne 0xf88e
movl $0x200, %esi            # imm = 0x200
leaq 0x410(%rsp), %rdi
leaq 0x18d2(%rip), %rdx      # 0x11127
movq %r12, %rcx
xorl %eax, %eax
callq 0xe170
movq %r14, %rdi
movq %r12, %rsi
callq 0xfbcc
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xfbcc
testq %r14, %r14
je 0xf793
cmpb $0x0, 0x210(%rsp)
jne 0xf793
testb %r13b, %r13b
je 0xf8d4
leaq 0x12c0e(%rip), %rax     # 0x224a8
movq (%rax), %r12
testq %r12, %r12
je 0xf8d4
movzbl %r13b, %r15d
leal 0x1(%r15), %ebp
movl %r15d, %edi
movl %ebp, %esi
callq 0x10e8d
movq %rax, 0x210(%r12)
addl $-0x1, %r15d
setb %al
movq 0x220(%r12), %r12
testq %r12, %r12
je 0xf8d4
testb %al, %al
jne 0xf8aa
testq %r14, %r14
je 0xf8f0
movq 0x410(%r14), %r15
movq %r14, %rdi
callq 0xe040
movq %r15, %r14
testq %r15, %r15
jne 0xf8d9
testq %rbx, %rbx
je 0xf90c
movq 0x410(%rbx), %r14
movq %rbx, %rdi
callq 0xe040
movq %r14, %rbx
testq %r14, %r14
jne 0xf8f5
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq