// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movl %ecx, %r15d
movl %edx, %r13d
movl %esi, %r12d
movl %edi, %r14d
testl %esi, %esi
je 0x10e78
movl $0x120, %edi            # imm = 0x120
callq 0xe270
movl %r14d, 0x100(%rax)
movb %r12b, 0x104(%rax)
movw %r13w, 0x106(%rax)
movb %r15b, 0x108(%rax)
movb %bpl, 0x109(%rax)
movb %bl, 0x10a(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x110(%rax)
jmp 0x1102f
movl %r14d, %edi
callq 0x107c1
testq %rax, %rax
movq %rax, 0x30(%rsp)
je 0x10ffe
movl %r12d, 0x28(%rsp)
movb (%rax), %cl
xorl %r12d, %r12d
testb %cl, %cl
je 0x11019
movl %r13d, 0x2c(%rsp)
movl %r15d, 0x1c(%rsp)
movl %ebp, 0x20(%rsp)
movl %ebx, 0x24(%rsp)
leaq 0x125cf(%rip), %rbx     # 0x23488
movq $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
movq %rax, 0x10(%rsp)
movq (%rbx), %rdi
movzbl %cl, %esi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0xe250
movl %eax, %r15d
movq (%rbx), %rdi
movq 0x10(%rsp), %rax
movzbl (%rax), %esi
movl %ebp, %edx
callq 0xe250
movl %eax, %r13d
cmpl %r14d, %eax
jne 0x10fd1
xorl %eax, %eax
cmpl $0x2, %ebp
jb 0x10f17
leaq 0x129d3(%rip), %rax     # 0x238e0
movl (%rax), %edi
callq 0x1055a
movzwl %ax, %eax
movl %ebp, %ebx
andl $0x1, %ebx
orl %eax, %ebx
orl 0x2c(%rsp), %ebx
movl $0x120, %edi            # imm = 0x120
callq 0xe270
movq (%rsp), %rdx
testq %rdx, %rdx
je 0x10f64
movb $0x1, %cl
cmpw %bx, 0x106(%rdx)
jne 0x10f4e
cmpl %r15d, 0x100(%rdx)
movzbl %cl, %ecx
cmovel %r12d, %ecx
testb $0x1, %cl
je 0x10f5f
movq 0x118(%rdx), %rdx
testq %rdx, %rdx
jne 0x10f37
testb $0x1, %cl
je 0x10fb7
movl %r15d, 0x100(%rax)
movl 0x28(%rsp), %ecx
movb %cl, 0x104(%rax)
movw %bx, 0x106(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x110(%rax)
movl 0x1c(%rsp), %ecx
movb %cl, 0x108(%rax)
movl 0x20(%rsp), %ecx
movb %cl, 0x109(%rax)
movl 0x24(%rsp), %ecx
movb %cl, 0x10a(%rax)
movq 0x8(%rsp), %rcx
testq %rcx, %rcx
je 0x10fc1
movq %rax, 0x118(%rcx)
jmp 0x10fc5
movq %rax, %rdi
callq 0xe040
jmp 0x10fca
movq %rax, (%rsp)
movq %rax, 0x8(%rsp)
leaq 0x124b7(%rip), %rbx     # 0x23488
cmpl %r14d, %r13d
je 0x10fe4
leal 0x1(%rbp), %eax
cmpl $0x3, %ebp
movl %eax, %ebp
jb 0x10ee1
movq 0x10(%rsp), %rax
movb 0x1(%rax), %cl
incq %rax
movq %rax, 0x10(%rsp)
testb %cl, %cl
jne 0x10ecf
jmp 0x11021
leaq 0x7429(%rip), %rdi      # 0x1842e
movq $0x0, (%rsp)
movl %r14d, %esi
xorl %eax, %eax
callq 0xe410
jmp 0x11021
movq $0x0, (%rsp)
movq 0x30(%rsp), %rdi
callq 0xe040
movq (%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq