// File: /workspace/github_c_makefile_star2_O2/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, %r13d
movl %edx, %r12d
movl %edi, %r14d
testl %esi, %esi
je 0x10a43
movl %esi, %ebx
movl $0x120, %edi            # imm = 0x120
callq 0xe270
movl %r12d, %ecx
movq %rax, %r12
movl %r14d, 0x100(%rax)
movb %bl, 0x104(%rax)
movw %cx, 0x106(%rax)
movb %r13b, 0x108(%rax)
movb %r15b, 0x109(%rax)
movb %bpl, 0x10a(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x110(%rax)
jmp 0x10ba8
movl %r14d, %edi
callq 0x104dc
testq %rax, %rax
movq %rax, 0x20(%rsp)
je 0x10b8a
movl %r12d, 0x1c(%rsp)
movl %r13d, 0x10(%rsp)
movl %r15d, 0x14(%rsp)
movl %ebp, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x11a0c(%rip), %r15     # 0x22488
movq %rax, %r13
xorl %r12d, %r12d
movb (%r13), %al
testb %al, %al
je 0x10b83
movq (%r15), %rdi
movzbl %al, %esi
xorl %ebx, %ebx
xorl %edx, %edx
callq 0xe250
movl %eax, %ebp
cmpl $0x4, %ebx
je 0x10b7b
movq (%r15), %rdi
movzbl (%r13), %esi
movl %ebx, %edx
callq 0xe250
cmpl %r14d, %eax
je 0x10ac0
incl %ebx
jmp 0x10a9f
xorl %eax, %eax
cmpl $0x2, %ebx
jb 0x10ad8
leaq 0x11e12(%rip), %rax     # 0x228e0
movl (%rax), %edi
callq 0x10284
movzwl %ax, %eax
andl $0x1, %ebx
orl %eax, %ebx
orl 0x1c(%rsp), %ebx
movl $0x120, %edi            # imm = 0x120
callq 0xe270
movb $0x1, %cl
movq 0x8(%rsp), %rdx
testb $0x1, %cl
je 0x10b19
testq %rdx, %rdx
je 0x10b19
movb $0x1, %cl
cmpw %bx, 0x106(%rdx)
jne 0x10b10
cmpl %ebp, 0x100(%rdx)
setne %cl
movq 0x118(%rdx), %rdx
jmp 0x10af2
testb $0x1, %cl
je 0x10b69
movl %ebp, 0x100(%rax)
movb $0x0, 0x104(%rax)
movw %bx, 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)
testq %r12, %r12
je 0x10b73
movq %rax, 0x118(%r12)
jmp 0x10b78
movq %rax, %rdi
callq 0xe040
jmp 0x10b7b
movq %rax, 0x8(%rsp)
movq %rax, %r12
incq %r13
jmp 0x10a82
movq 0x8(%rsp), %r12
jmp 0x10b9e
leaq 0x689d(%rip), %rdi      # 0x1742e
xorl %r12d, %r12d
movl %r14d, %esi
xorl %eax, %eax
callq 0xf160
movq 0x20(%rsp), %rdi
callq 0xe040
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq