// File: /workspace/github_c_makefile_star2_O3/baskerville[P]sxhkd/src/types.c
// Function: make_chord
chord_t *make_chord(xcb_keysym_t keysym, xcb_button_t button, uint16_t modfield, uint8_t event_type, bool replay_event, bool lock_chain)
{
	chord_t *chord;
	if (button == XCB_NONE) {
		chord_t *prev = NULL;
		chord_t *orig = NULL;
		xcb_keycode_t *keycodes = keycodes_from_keysym(keysym);
		if (keycodes != NULL) {
			for (xcb_keycode_t *kc = keycodes; *kc != XCB_NO_SYMBOL; kc++) {
				xcb_keysym_t natural_keysym = xcb_key_symbols_get_keysym(symbols, *kc, 0);
				for (unsigned char col = 0; col < KEYSYMS_PER_KEYCODE; col++) {
					xcb_keysym_t ks = xcb_key_symbols_get_keysym(symbols, *kc, col);
					if (ks == keysym) {
						uint16_t implicit_modfield = (col & 1 ? XCB_MOD_MASK_SHIFT : 0) | (col & 2 ? modfield_from_keysym(Mode_switch) : 0);
						uint16_t explicit_modfield = modfield | implicit_modfield;
						chord = malloc(sizeof(chord_t));
						bool unique = true;
						for (chord_t *c = orig; unique && c != NULL; c = c->more)
							if (c->modfield == explicit_modfield && c->keysym == natural_keysym)
								unique = false;
						if (!unique) {
							free(chord);
							break;
						}
						chord->keysym = natural_keysym;
						chord->button = button;
						chord->modfield = explicit_modfield;
						chord->next = chord->more = NULL;
						chord->event_type = event_type;
						chord->replay_event = replay_event;
						chord->lock_chain = lock_chain;
						if (prev != NULL)
							prev->more = chord;
						else
							orig = chord;
						prev = chord;
						PRINTF("key chord %u %u\n", natural_keysym, explicit_modfield);
						break;
					}
				}
			}
		} else {
			warn("No keycodes found for keysym %u.\n", keysym);
		}
		free(keycodes);
		chord = orig;
	} else {
		chord = malloc(sizeof(chord_t));
		chord->keysym = keysym;
		chord->button = button;
		chord->modfield = modfield;
		chord->event_type = event_type;
		chord->replay_event = replay_event;
		chord->lock_chain = lock_chain;
		chord->next = chord->more = NULL;
		PRINTF("button chord %u %u\n", button, modfield);
	}
	return chord;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %ebp
movl %r8d, %r15d
movl %ecx, %r12d
movl %edx, %r13d
movl %edi, %r14d
testl %esi, %esi
je 0x10ccf
movl %esi, %ebx
movl $0x120, %edi            # imm = 0x120
callq 0xe270
movl %r13d, %ecx
movq %rax, %r13
movl %r14d, 0x100(%rax)
movb %bl, 0x104(%rax)
movw %cx, 0x106(%rax)
movb %r12b, 0x108(%rax)
movb %r15b, 0x109(%rax)
movb %bpl, 0x10a(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x110(%rax)
jmp 0x10e48
movl %r14d, %edi
callq 0x106d4
testq %rax, %rax
movq %rax, 0x20(%rsp)
je 0x10e25
movq %rax, %rcx
movb (%rax), %al
testb %al, %al
je 0x10e3b
movl %r13d, 0x1c(%rsp)
movl %r12d, 0x10(%rsp)
movl %r15d, 0x14(%rsp)
movl %ebp, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x11773(%rip), %r15     # 0x22488
xorl %r13d, %r13d
movq %rcx, %r12
movq (%r15), %rdi
movzbl %al, %esi
xorl %edx, %edx
callq 0xe250
movl %eax, %ebx
xorl %ebp, %ebp
movq (%r15), %rdi
movzbl (%r12), %esi
movl %ebp, %edx
callq 0xe250
cmpl %r14d, %eax
je 0x10d4c
incl %ebp
cmpl $0x4, %ebp
jne 0x10d2c
jmp 0x10e09
xorl %eax, %eax
cmpl $0x2, %ebp
jb 0x10d64
leaq 0x11b86(%rip), %rax     # 0x228e0
movl (%rax), %edi
callq 0x1046d
movzwl %ax, %eax
andl $0x1, %ebp
orl %eax, %ebp
orl 0x1c(%rsp), %ebp
movl $0x120, %edi            # imm = 0x120
callq 0xe270
movq %r13, %rcx
testq %r13, %r13
je 0x10db2
cmpw %bp, 0x106(%rcx)
jne 0x10da0
movl 0x100(%rcx), %edx
cmpl %ebx, %edx
je 0x10dae
movq 0x118(%rcx), %rcx
testq %rcx, %rcx
jne 0x10d7f
jmp 0x10dae
movq 0x118(%rcx), %rcx
testq %rcx, %rcx
jne 0x10d7f
jmp 0x10db2
cmpl %ebx, %edx
je 0x10e1b
movl %ebx, 0x100(%rax)
movb $0x0, 0x104(%rax)
movw %bp, 0x106(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x110(%rax)
movl 0x10(%rsp), %ecx
movb %cl, 0x108(%rax)
movl 0x14(%rsp), %ecx
movb %cl, 0x109(%rax)
movl 0x18(%rsp), %ecx
movb %cl, 0x10a(%rax)
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
je 0x10e01
movq %rax, 0x118(%rcx)
jmp 0x10e04
movq %rax, %r13
movq %rax, 0x8(%rsp)
movb 0x1(%r12), %al
incq %r12
testb %al, %al
jne 0x10d1b
jmp 0x10e3e
movq %rax, %rdi
callq 0xe040
jmp 0x10e09
leaq 0x6602(%rip), %rdi      # 0x1742e
xorl %r13d, %r13d
movl %r14d, %esi
xorl %eax, %eax
callq 0xe410
jmp 0x10e3e
xorl %r13d, %r13d
movq 0x20(%rsp), %rdi
callq 0xe040
movq %r13, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq