static int old_codec47(SANMVideoContext *ctx, int top,
                       int left, int width, int height)
{
    int i, j, seq, compr, new_rot, tbl_pos, skip;
    int stride     = ctx->pitch;
    uint8_t *dst   = ((uint8_t*)ctx->frm0) + left + top * stride;
    uint8_t *prev1 = (uint8_t*)ctx->frm1;
    uint8_t *prev2 = (uint8_t*)ctx->frm2;
    uint32_t decoded_size;
    tbl_pos = bytestream2_tell(&ctx->gb);
    seq     = bytestream2_get_le16(&ctx->gb);
    compr   = bytestream2_get_byte(&ctx->gb);
    new_rot = bytestream2_get_byte(&ctx->gb);
    skip    = bytestream2_get_byte(&ctx->gb);
    bytestream2_skip(&ctx->gb, 9);
    decoded_size = bytestream2_get_le32(&ctx->gb);
    bytestream2_skip(&ctx->gb, 8);
    if (skip & 1)
        bytestream2_skip(&ctx->gb, 0x8080);
    if (!seq) {
        ctx->prev_seq = -1;
        memset(prev1, 0, ctx->height * stride);
        memset(prev2, 0, ctx->height * stride);
    av_dlog(ctx->avctx, "compression %d\n", compr);
    switch (compr) {
    case 0:
        if (bytestream2_get_bytes_left(&ctx->gb) < width * height)
            return AVERROR_INVALIDDATA;
        for (j = 0; j < height; j++) {
            bytestream2_get_bufferu(&ctx->gb, dst, width);
            dst += stride;
        break;
    case 1:
        if (bytestream2_get_bytes_left(&ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
            return AVERROR_INVALIDDATA;
        for (j = 0; j < height; j += 2) {
            for (i = 0; i < width; i += 2) {
                dst[i] = dst[i + 1] =
                dst[stride + i] = dst[stride + i + 1] = bytestream2_get_byteu(&ctx->gb);
            dst += stride * 2;
        break;
    case 2:
        if (seq == ctx->prev_seq + 1) {
            for (j = 0; j < height; j += 8) {
                for (i = 0; i < width; i += 8) {
                    if (process_block(ctx, dst + i, prev1 + i, prev2 + i, stride,
                                      tbl_pos + 8, 8))
                        return AVERROR_INVALIDDATA;
                dst   += stride * 8;
                prev1 += stride * 8;
                prev2 += stride * 8;
        break;
    case 3:
        memcpy(ctx->frm0, ctx->frm2, ctx->pitch * ctx->height);
        break;
    case 4:
        memcpy(ctx->frm0, ctx->frm1, ctx->pitch * ctx->height);
        break;
    case 5:
        if (rle_decode(ctx, dst, decoded_size))
            return AVERROR_INVALIDDATA;
        break;
    default:
        av_log(ctx->avctx, AV_LOG_ERROR,
               "subcodec 47 compression %d not implemented\n", compr);
        return AVERROR_PATCHWELCOME;
    if (seq == ctx->prev_seq + 1)
        ctx->rotate_code = new_rot;
    else
        ctx->rotate_code = 0;
    ctx->prev_seq = seq;
    return 0;
static int old_codec47(SANMVideoContext *ctx, int top,
                       int left, int width, int height)
{
    int i, j, seq, compr, new_rot, tbl_pos, skip;
    int stride     = ctx->pitch;
    uint8_t *dst   = ((uint8_t*)ctx->frm0) + left + top * stride;
    uint8_t *prev1 = (uint8_t*)ctx->frm1;
    uint8_t *prev2 = (uint8_t*)ctx->frm2;
    uint32_t decoded_size;
    tbl_pos = bytestream2_tell(&ctx->gb);
    seq     = bytestream2_get_le16(&ctx->gb);
    compr   = bytestream2_get_byte(&ctx->gb);
    new_rot = bytestream2_get_byte(&ctx->gb);
    skip    = bytestream2_get_byte(&ctx->gb);
    bytestream2_skip(&ctx->gb, 9);
    decoded_size = bytestream2_get_le32(&ctx->gb);
    bytestream2_skip(&ctx->gb, 8);
    if (skip & 1)
        bytestream2_skip(&ctx->gb, 0x8080);
    if (!seq) {
        ctx->prev_seq = -1;
        memset(prev1, 0, ctx->height * stride);
        memset(prev2, 0, ctx->height * stride);
    av_dlog(ctx->avctx, "compression %d\n", compr);
    switch (compr) {
    case 0:
        if (bytestream2_get_bytes_left(&ctx->gb) < width * height)
            return AVERROR_INVALIDDATA;
        for (j = 0; j < height; j++) {
            bytestream2_get_bufferu(&ctx->gb, dst, width);
            dst += stride;
        break;
    case 1:
        if (bytestream2_get_bytes_left(&ctx->gb) < ((width + 1) >> 1) * ((height + 1) >> 1))
            return AVERROR_INVALIDDATA;
        for (j = 0; j < height; j += 2) {
            for (i = 0; i < width; i += 2) {
                dst[i] = dst[i + 1] =
                dst[stride + i] = dst[stride + i + 1] = bytestream2_get_byteu(&ctx->gb);
            dst += stride * 2;
        break;
    case 2:
        if (seq == ctx->prev_seq + 1) {
            for (j = 0; j < height; j += 8) {
                for (i = 0; i < width; i += 8) {
                    if (process_block(ctx, dst + i, prev1 + i, prev2 + i, stride,
                                      tbl_pos + 8, 8))
                        return AVERROR_INVALIDDATA;
                dst   += stride * 8;
                prev1 += stride * 8;
                prev2 += stride * 8;
        break;
    case 3:
        memcpy(ctx->frm0, ctx->frm2, ctx->pitch * ctx->height);
        break;
    case 4:
        memcpy(ctx->frm0, ctx->frm1, ctx->pitch * ctx->height);
        break;
    case 5:
        if (rle_decode(ctx, dst, decoded_size))
            return AVERROR_INVALIDDATA;
        break;
    default:
        av_log(ctx->avctx, AV_LOG_ERROR,
               "subcodec 47 compression %d not implemented\n", compr);
        return AVERROR_PATCHWELCOME;
    if (seq == ctx->prev_seq + 1)
        ctx->rotate_code = new_rot;
    else
        ctx->rotate_code = 0;
    ctx->prev_seq = seq;
    return 0;
static int FUNC_0(SANMVideoContext *VAR_0, int VAR_1,
                       int VAR_2, int VAR_3, int VAR_4)
{
    int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11;
    int VAR_12     = VAR_0->pitch;
    uint8_t *dst   = ((uint8_t*)VAR_0->frm0) + VAR_2 + VAR_1 * VAR_12;
    uint8_t *prev1 = (uint8_t*)VAR_0->frm1;
    uint8_t *prev2 = (uint8_t*)VAR_0->frm2;
    uint32_t decoded_size;
    VAR_10 = bytestream2_tell(&VAR_0->gb);
    VAR_7     = bytestream2_get_le16(&VAR_0->gb);
    VAR_8   = bytestream2_get_byte(&VAR_0->gb);
    VAR_9 = bytestream2_get_byte(&VAR_0->gb);
    VAR_11    = bytestream2_get_byte(&VAR_0->gb);
    bytestream2_skip(&VAR_0->gb, 9);
    decoded_size = bytestream2_get_le32(&VAR_0->gb);
    bytestream2_skip(&VAR_0->gb, 8);
    if (VAR_11 & 1)
        bytestream2_skip(&VAR_0->gb, 0x8080);
    if (!VAR_7) {
        VAR_0->prev_seq = -1;
        memset(prev1, 0, VAR_0->VAR_4 * VAR_12);
        memset(prev2, 0, VAR_0->VAR_4 * VAR_12);
    av_dlog(VAR_0->avctx, "compression %d\n", VAR_8);
    switch (VAR_8) {
    case 0:
        if (bytestream2_get_bytes_left(&VAR_0->gb) < VAR_3 * VAR_4)
            return AVERROR_INVALIDDATA;
        for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6++) {
            bytestream2_get_bufferu(&VAR_0->gb, dst, VAR_3);
            dst += VAR_12;
        break;
    case 1:
        if (bytestream2_get_bytes_left(&VAR_0->gb) < ((VAR_3 + 1) >> 1) * ((VAR_4 + 1) >> 1))
            return AVERROR_INVALIDDATA;
        for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6 += 2) {
            for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += 2) {
                dst[VAR_5] = dst[VAR_5 + 1] =
                dst[VAR_12 + VAR_5] = dst[VAR_12 + VAR_5 + 1] = bytestream2_get_byteu(&VAR_0->gb);
            dst += VAR_12 * 2;
        break;
    case 2:
        if (VAR_7 == VAR_0->prev_seq + 1) {
            for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6 += 8) {
                for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += 8) {
                    if (process_block(VAR_0, dst + VAR_5, prev1 + VAR_5, prev2 + VAR_5, VAR_12,
                                      VAR_10 + 8, 8))
                        return AVERROR_INVALIDDATA;
                dst   += VAR_12 * 8;
                prev1 += VAR_12 * 8;
                prev2 += VAR_12 * 8;
        break;
    case 3:
        memcpy(VAR_0->frm0, VAR_0->frm2, VAR_0->pitch * VAR_0->VAR_4);
        break;
    case 4:
        memcpy(VAR_0->frm0, VAR_0->frm1, VAR_0->pitch * VAR_0->VAR_4);
        break;
    case 5:
        if (rle_decode(VAR_0, dst, decoded_size))
            return AVERROR_INVALIDDATA;
        break;
    default:
        av_log(VAR_0->avctx, AV_LOG_ERROR,
               "subcodec 47 compression %d not implemented\n", VAR_8);
        return AVERROR_PATCHWELCOME;
    if (VAR_7 == VAR_0->prev_seq + 1)
        VAR_0->rotate_code = VAR_9;
    else
        VAR_0->rotate_code = 0;
    VAR_0->prev_seq = VAR_7;
    return 0;
static int FUNC_0(SANMVideoContext *VAR_0, int VAR_1,
int VAR_2, int VAR_3, int VAR_4)
{ int VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10, VAR_11; int VAR_12     = VAR_0->pitch; uint8_t *dst   = ((uint8_t*)VAR_0->frm0) + VAR_2 + VAR_1 * VAR_12; uint8_t *prev1 = (uint8_t*)VAR_0->frm1; uint8_t *prev2 = (uint8_t*)VAR_0->frm2; uint32_t decoded_size; VAR_10 = bytestream2_tell(&VAR_0->gb); VAR_7     = bytestream2_get_le16(&VAR_0->gb); VAR_8   = bytestream2_get_byte(&VAR_0->gb); VAR_9 = bytestream2_get_byte(&VAR_0->gb); VAR_11    = bytestream2_get_byte(&VAR_0->gb); bytestream2_skip(&VAR_0->gb, 9); decoded_size = bytestream2_get_le32(&VAR_0->gb); bytestream2_skip(&VAR_0->gb, 8); if (VAR_11 & 1)
bytestream2_skip(&VAR_0->gb, 0x8080); if (!VAR_7) { VAR_0->prev_seq = -1; memset(prev1, 0, VAR_0->VAR_4 * VAR_12); memset(prev2, 0, VAR_0->VAR_4 * VAR_12); av_dlog(VAR_0->avctx, "compression %d\n", VAR_8); switch (VAR_8) { case 0:
if (bytestream2_get_bytes_left(&VAR_0->gb) < VAR_3 * VAR_4)
return AVERROR_INVALIDDATA; for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6++) { bytestream2_get_bufferu(&VAR_0->gb, dst, VAR_3); dst += VAR_12; break; case 1:
if (bytestream2_get_bytes_left(&VAR_0->gb) < ((VAR_3 + 1) >> 1) * ((VAR_4 + 1) >> 1))
return AVERROR_INVALIDDATA; for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6 += 2) { for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += 2) { dst[VAR_5] = dst[VAR_5 + 1] =
dst[VAR_12 + VAR_5] = dst[VAR_12 + VAR_5 + 1] = bytestream2_get_byteu(&VAR_0->gb); dst += VAR_12 * 2; break; case 2:
if (VAR_7 == VAR_0->prev_seq + 1) { for (VAR_6 = 0; VAR_6 < VAR_4; VAR_6 += 8) { for (VAR_5 = 0; VAR_5 < VAR_3; VAR_5 += 8) { if (process_block(VAR_0, dst + VAR_5, prev1 + VAR_5, prev2 + VAR_5, VAR_12,
VAR_10 + 8, 8))
return AVERROR_INVALIDDATA; dst   += VAR_12 * 8; prev1 += VAR_12 * 8; prev2 += VAR_12 * 8; break; case 3:
memcpy(VAR_0->frm0, VAR_0->frm2, VAR_0->pitch * VAR_0->VAR_4); break; case 4:
memcpy(VAR_0->frm0, VAR_0->frm1, VAR_0->pitch * VAR_0->VAR_4); break; case 5:
if (rle_decode(VAR_0, dst, decoded_size))
return AVERROR_INVALIDDATA; break; default:
av_log(VAR_0->avctx, AV_LOG_ERROR,
"subcodec 47 compression %d not implemented\n", VAR_8); return AVERROR_PATCHWELCOME; if (VAR_7 == VAR_0->prev_seq + 1)
VAR_0->rotate_code = VAR_9; else
VAR_0->rotate_code = 0; VAR_0->prev_seq = VAR_7; return 0;