protected final RegisterSpec insertMoveBefore(SsaInsn insn, RegisterSpec reg) {
    SsaBasicBlock block = insn.getBlock();
    ArrayList<SsaInsn> insns = block.getInsns();
    int insnIndex = insns.indexOf(insn);

    if (insnIndex < 0) {
      throw new IllegalArgumentException("specified insn is not in this block");
    }

    if (insnIndex != insns.size() - 1) {
      /*
       * Presently, the interference updater only works when
       * adding before the last insn, and the last insn must have no
       * result
       */
      throw new IllegalArgumentException("Adding move here not supported:" + insn.toHuman());
    }

    /*
     * Get new register and make new move instruction.
     */

    // The new result must not have an associated local variable.
    RegisterSpec newRegSpec = RegisterSpec.make(ssaMeth.makeNewSsaReg(), reg.getTypeBearer());

    SsaInsn toAdd =
        SsaInsn.makeFromRop(
            new PlainInsn(
                Rops.opMove(newRegSpec.getType()),
                SourcePosition.NO_INFO,
                newRegSpec,
                RegisterSpecList.make(reg)),
            block);

    insns.add(insnIndex, toAdd);

    int newReg = newRegSpec.getReg();

    /*
     * Adjust interference graph based on what's live out of the current
     * block and what's used by the final instruction.
     */

    IntSet liveOut = block.getLiveOutRegs();
    IntIterator liveOutIter = liveOut.iterator();

    while (liveOutIter.hasNext()) {
      interference.add(newReg, liveOutIter.next());
    }

    // Everything that's a source in the last insn interferes.
    RegisterSpecList sources = insn.getSources();
    int szSources = sources.size();

    for (int i = 0; i < szSources; i++) {
      interference.add(newReg, sources.get(i).getReg());
    }

    ssaMeth.onInsnsChanged();

    return newRegSpec;
  }
Inserts a move instruction for a specified SSA register before a specified instruction,
creating a new SSA register and adjusting the interference graph in the process. The insn
currently must be the last insn in a block.

@param insn {@code non-null;} insn to insert move before, must be last insn in block
@param reg {@code non-null;} SSA register to duplicate
@return {@code non-null;} spec of new SSA register created by move
android/android_framework/dex-maker/src/main/java/com/android/dx/ssa/back/RegisterAllocator.java