def unflatten(processed, merge_rules):
    unflattened = OrderedDict()
    for key in processed:
        current_node = unflattened
        for end, part in enumerate(key, 1):
            if isinstance(part, IdValue):
                for node in current_node:
                    if isinstance(node, IdDict) and node.identifier == part.identifier:
                        current_node = node
                        break
                else:
                    new_node = IdDict()
                    new_node.identifier = part.identifier
                    if part.original_value is not None:
                        new_node['id'] = part.original_value
                    current_node.append(new_node)
                    current_node = new_node
                continue
            node = current_node.get(part)
            if node is not None:
                current_node = node
                continue
            if len(key) == end:
                if processed[key] is not None:
                    current_node[part] = processed[key]
                continue
            if isinstance(key[end], IdValue):
                new_node = []
            else:
                new_node = OrderedDict()
            current_node[part] = new_node
            current_node = new_node
    return unflattened