def struct_size(items):
    """ Computes the total size of a given (potentially nested) struct.
    items -- A list like this:
        items := [ [elem, elem-alignment] + ]
        elem := elem-size | items
        elem-size:= integer
        elem-alignment:= integer
    Returns a 2-element list whose first element is the total size of the
    struct and the second element is the alignment of the most aligned member.
    """

    member_sum = 0
    pad = 0
    most_aligned = 1
    for item in items:
        elem = item[0]
        # If nested struct.
        if isinstance(elem, list):
            elem, align = struct_size(item)
        else:
            align = item[1]
        most_aligned = max(most_aligned, align)
        pad = (align - member_sum % align) % align
        member_sum = member_sum + pad + elem
    pad = (most_aligned - member_sum % most_aligned) % most_aligned
    member_sum += pad
    return [member_sum, most_aligned]