@staticmethod
def update_program(program, encoding, gbias, lbias_arr, fdidx):
    """
        Applies the provided `encoding` to the provided `program`. I.e., all
        specified subroutines are actually called in the program. This mutates
        the input program and also returns it.

        Arguments:
        program -- the program to update
        encoding -- the encoding to use. a list of (idx, cand_subr) tuples
        gbias -- bias into the global subrs INDEX
        lbias_arr -- bias into each of the lsubrs INDEXes
        fdidx -- the FD that this `program` belongs to, or None if global
        """
    offset = 0
    for item in encoding:
        subr = item[1]
        s = slice(item[0] - offset, item[0] + subr.length - offset)
        if subr._flatten:
            program[s] = subr._program
            offset += subr.length - len(subr._program)
        else:
            assert hasattr(subr, '_position'
                ), 'CandidateSubr without position in Subrs encountered'
            if subr._global:
                operator = 'callgsubr'
                bias = gbias
            else:
                assert len(subr._fdidx) == 1
                assert fdidx == None or subr._fdidx[0] == fdidx
                operator = 'callsubr'
                bias = lbias_arr[subr._fdidx[0]]
            program[s] = [subr._position - bias, operator]
            offset += subr.length - 2
    return program
