/* Do a final pass over the code of a function, doing small peephole optimizations and adjustments.  */
void luaK_finish(FuncState *fs)
/* Do a final pass over the code of a function, doing small peephole optimizations and adjustments.  */
void luaK_finish(FuncState *fs)
{
    Instruction *pc = &p->code[i];
    lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
    switch (GET_OPCODE(*pc)) {
      case OP_RETURN0: case OP_RETURN1: {
        if (!(fs->needclose || p->is_vararg))
          break;
        SET_OPCODE(*pc, OP_RETURN);
      }
      case OP_RETURN: case OP_TAILCALL: {
        if (fs->needclose)
          SETARG_k(*pc, 1);
        if (p->is_vararg)
          SETARG_C(*pc, p->numparams + 1);
        break;
      }
      case OP_JMP: {
        int target = finaltarget(p->code, i);
        fixjump(fs, i, target);
        break;
      }
      default: break;
    }
  }
}