public static void writeSignedLeb128(ByteOutput out, int value) {
    int remaining = value >> 7;
    boolean hasMore = true;
    int end = ((value & Integer.MIN_VALUE) == 0) ? 0 : -1;

    while (hasMore) {
      hasMore = (remaining != end) || ((remaining & 1) != ((value >> 6) & 1));

      out.writeByte((byte) ((value & 0x7f) | (hasMore ? 0x80 : 0)));
      value = remaining;
      remaining >>= 7;
    }
  }
Writes {@code value} as a signed integer to {@code out}, starting at {@code offset}. Returns
the number of bytes written.
android/android_framework/dex-maker/src/main/java/com/android/dex/Leb128.java