def num_bytes(byte_tmpl):
    """Given a list of raw bytes and template strings, calculate the total number
    of bytes that the final output will have.

    Assumes all template strings are replaced by 8 bytes.

    >>> num_bytes([0x127, "prog_bytes"])
    9

    """
    total = 0
    for b in byte_tmpl:
        if isinstance(b, int):
            total += 1
        elif isinstance(b, list) and b:
            tmpl_key = b[0]
            if tmpl_key == "string_lit":
                total += 8
            elif tmpl_key == "fun_offset":
                total += 4
            else:
                assert False, "tmpl key: {!r}".format(tmpl_key)
        elif b in ("prog_entry", "prog_length"):
            total += 8
        else:
            assert False, "tmpl: {!r}".format(b)

    return total