public void addAtEndBeforeBranch(Instruction i) throws Exception {
        if(!instructions.isEmpty() &&
           instructions.getLast() instanceof BranchInstruction) {
            ListIterator<Instruction> iter =
                instructions.listIterator(instructions.size() - 1);
            iter.next();        // returns last instruction
            // also returns the last instructions, but we are now 'going backwards'
            Instruction cursor = iter.previous();
            // need to put the instruction before the compare and
            // branch, a compare instruction may not be present though
            assert(cursor instanceof BranchInstruction); // we just tested this

            // if the basic block has no other instructions, then we
            // can insert the instruction immediatly, otherwise we
            // need to see if there is also a Cmp
            if(iter.hasPrevious()) {
                cursor = iter.previous();

                // if we did not get a cmp, we went too far
                if(!(cursor instanceof Cmp)) {
                    // will return the same instruction as cursor, but now instructions will be added after it
                    iter.next();
                }
                // but if we did get a Cmp, we went just the right amount
            }
            i.setDominating(cursor.getDominating());
            cursor.setDominating(i);
            i.setContainingBB(this);
            iter.add(i);
        } else {
            addInstruction(i);
        }
    }