// File: /workspace/github_c_makefile_star2_O0/baskerville[P]bspwm/src/pointer.c
// Function: modfield_from_keysym
int16_t modfield_from_keysym(xcb_keysym_t keysym)
{
	uint16_t modfield = 0;
	xcb_keycode_t *keycodes = NULL, *mod_keycodes = NULL;
	xcb_get_modifier_mapping_reply_t *reply = NULL;
	xcb_key_symbols_t *symbols = xcb_key_symbols_alloc(dpy);

	if ((keycodes = xcb_key_symbols_get_keycode(symbols, keysym)) == NULL ||
	    (reply = xcb_get_modifier_mapping_reply(dpy, xcb_get_modifier_mapping(dpy), NULL)) == NULL ||
	    reply->keycodes_per_modifier < 1 ||
	    (mod_keycodes = xcb_get_modifier_mapping_keycodes(reply)) == NULL) {
		goto end;
	}

	unsigned int num_mod = xcb_get_modifier_mapping_keycodes_length(reply) / reply->keycodes_per_modifier;
	for (unsigned int i = 0; i < num_mod; i++) {
		for (unsigned int j = 0; j < reply->keycodes_per_modifier; j++) {
			xcb_keycode_t mk = mod_keycodes[i * reply->keycodes_per_modifier + j];
			if (mk == XCB_NO_SYMBOL) {
				continue;
			}
			for (xcb_keycode_t *k = keycodes; *k != XCB_NO_SYMBOL; k++) {
				if (*k == mk) {
					modfield |= (1 << i);
				}
			}
		}
	}

end:
	xcb_key_symbols_free(symbols);
	free(keycodes);
	free(reply);
	return modfield;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
movw $0x0, -0x6(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
leaq 0x20b58(%rip), %rax     # 0x356b8
movq (%rax), %rdi
callq 0x4580
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl -0x4(%rbp), %esi
callq 0x4040
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x14bdc
leaq 0x20b2f(%rip), %rax     # 0x356b8
movq (%rax), %rax
movq %rax, -0x50(%rbp)
leaq 0x20b21(%rip), %rax     # 0x356b8
movq (%rax), %rdi
callq 0x4a20
movq -0x50(%rbp), %rdi
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x4860
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x14bdc
movq -0x20(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x1, %eax
jl 0x14bdc
movq -0x20(%rbp), %rdi
callq 0x47e0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x14be1
jmp 0x14cba
movq -0x20(%rbp), %rdi
callq 0x4950
movq -0x20(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cltd
idivl %ecx
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0x14cb8
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x20(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jae 0x14ca8
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rdx
movzbl 0x1(%rdx), %edx
imull %edx, %ecx
addl -0x38(%rbp), %ecx
movl %ecx, %ecx
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpq $0x0, %rax
jne 0x14c4e
jmp 0x14c9a
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
cmpq $0x0, %rax
je 0x14c98
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
movzbl -0x39(%rbp), %ecx
cmpl %ecx, %eax
jne 0x14c88
movl -0x34(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movzwl -0x6(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x6(%rbp)
jmp 0x14c8a
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x14c56
jmp 0x14c9a
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x14c12
jmp 0x14caa
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x14bff
jmp 0x14cba
movq -0x28(%rbp), %rdi
callq 0x4760
movq -0x10(%rbp), %rdi
callq 0x4450
movq -0x20(%rbp), %rdi
callq 0x4450
movw -0x6(%rbp), %ax
addq $0x50, %rsp
popq %rbp
retq
nop