/* Returns a list organized in an intermediate format suited to chaining of merge() calls: null-terminated, no reserved or sentinel head node, "prev" links not maintained.  */
static struct list_head* merge(void *priv, int(*cmp)(void *priv, struct list_head *a, struct list_head *b), struct list_head *a, struct list_head *b)
/* Returns a list organized in an intermediate format suited to chaining of merge() calls: null-terminated, no reserved or sentinel head node, "prev" links not maintained.  */
static struct list_head* merge(void *priv, int(*cmp)(void *priv, struct list_head *a, struct list_head *b), struct list_head *a, struct list_head *b)
{
	struct list_head head, *tail = &head;
	while (a && b) {
		if ((*cmp)(priv, a, b) <= 0) {
			tail->next = a;
			a = a->next;
		} else {
			tail->next = b;
			b = b->next;
		}
		tail = tail->next;
	}
	tail->next = a?:b;
	return head.next;
}