+#ifndef __GNUC__
+
+#define __optmap_gen_type(_type, _field) -1
+
+#ifndef likely
+#define likely(_expr) !!(_expr)
+#endif
+
+#ifndef unlikely
+#define unlikely(_expr) !!(_expr)
+#endif
+
+#else /* __GNUC__ */
+
+#define __compatible(_type, _field, _newtype) \
+ __builtin_types_compatible_p(typeof(&(((_type *)0)->_field)), _newtype *)
+
+#define __list_compatible(_type, _field, __val, __else) \
+ __builtin_choose_expr(__compatible(_type, _field, struct ucimap_list *), __val, __else)
+
+#define __int_compatible(_type, _field, __val, __else) \
+ __builtin_choose_expr(__compatible(_type, _field, int), __val, \
+ __builtin_choose_expr(__compatible(_type, _field, unsigned int), __val, \
+ __else))
+
+#define __string_compatible(_type, _field, __val, __else) \
+ __builtin_choose_expr(__compatible(_type, _field, char *), __val, \
+ __builtin_choose_expr(__compatible(_type, _field, unsigned char *), __val, \
+ __builtin_choose_expr(__compatible(_type, _field, const char *), __val, \
+ __builtin_choose_expr(__compatible(_type, _field, const unsigned char *), __val, \
+ __else))))
+
+#define __bool_compatible(_type, _field, __val, __else) \
+ __builtin_choose_expr(__compatible(_type, _field, bool), __val, __else)
+
+
+#define __optmap_gen_type(_type, _field) \
+ __list_compatible(_type, _field, UCIMAP_LIST, \
+ __int_compatible(_type, _field, UCIMAP_INT, \
+ __string_compatible(_type, _field, UCIMAP_STRING, \
+ __bool_compatible(_type, _field, UCIMAP_BOOL, \
+ -1))))
+
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+
+#endif /* __GNUC__ */
+