private ArrayList<DalvInsn> performExpansion(Dop[] opcodes) {
    int size = insns.size();
    ArrayList<DalvInsn> result = new ArrayList<DalvInsn>(size * 2);

    ArrayList<CodeAddress> closelyBoundAddresses = new ArrayList<CodeAddress>();

    for (int i = 0; i < size; i++) {
      DalvInsn insn = insns.get(i);
      Dop originalOpcode = insn.getOpcode();
      Dop currentOpcode = opcodes[i];
      DalvInsn prefix;
      DalvInsn suffix;

      if (currentOpcode != null) {
        // No expansion is necessary.
        prefix = null;
        suffix = null;
      } else {
        // Expansion is required.
        currentOpcode = findExpandedOpcodeForInsn(insn);
        BitSet compatRegs = currentOpcode.getFormat().compatibleRegs(insn);
        prefix = insn.expandedPrefix(compatRegs);
        suffix = insn.expandedSuffix(compatRegs);

        // Expand necessary registers to fit the new format
        insn = insn.expandedVersion(compatRegs);
      }

      if (insn instanceof CodeAddress) {
        // If we have a closely bound address, don't add it yet,
        // because we need to add it after the prefix for the
        // instruction it is bound to.
        if (((CodeAddress) insn).getBindsClosely()) {
          closelyBoundAddresses.add((CodeAddress) insn);
          continue;
        }
      }

      if (prefix != null) {
        result.add(prefix);
      }

      // Add any pending closely bound addresses
      if (!(insn instanceof ZeroSizeInsn) && closelyBoundAddresses.size() > 0) {
        for (CodeAddress codeAddress : closelyBoundAddresses) {
          result.add(codeAddress);
        }
        closelyBoundAddresses.clear();
      }

      if (currentOpcode != originalOpcode) {
        insn = insn.withOpcode(currentOpcode);
      }
      result.add(insn);

      if (suffix != null) {
        result.add(suffix);
      }
    }

    return result;
  }
Helper for {@link #massageInstructions}, which constructs a replacement list, where each {link
DalvInsn} instance that couldn't be represented simply (due to register representation
problems) is expanded into a series of instances that together perform the proper function.

@param opcodes {@code non-null;} array of per-instruction opcode selections
@return {@code non-null;} the replacement list
android/android_framework/dex-maker/src/main/java/com/android/dx/dex/code/OutputFinisher.java