#include <climits>
#include <cstdint>
#include <cstdio>

template <uint8_t d, typename int_type>
int_type get_matches(int_type b)
{
    int_type ret = 0;
    for (size_t i = 0; i < sizeof(int_type); i++)
        if (((b >> i * CHAR_BIT) & 0xff) == d)
            ret |= (int_type)0x80 << i * CHAR_BIT;
    return ret;
}

void print_testcase(uint64_t a)
{
	printf("find_matches(0x%016llx) -> 0x%016llx\n", a, get_matches<0x20>(a));
}

int main()
{
	print_testcase(0x1312202000200212ULL);
	print_testcase(0x0001020304050607ULL);
	print_testcase(0x0010203040506070ULL);
	return 0;
}