static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){

    MpegEncContext * const s = &h->s;

    Picture * const ref1 = &h->ref_list[1][0];

    int j, old_ref, rfield;

    int start= mbafi ? 16                      : 0;

    int end  = mbafi ? 16+2*h->ref_count[0]    : h->ref_count[0];

    int interl= mbafi || s->picture_structure != PICT_FRAME;



    /* bogus; fills in for missing frames */

    memset(map[list], 0, sizeof(map[list]));



    for(rfield=0; rfield<2; rfield++){

        for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){

            int poc = ref1->ref_poc[colfield][list][old_ref];



            if     (!interl)

                poc |= 3;

            else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed

                poc= (poc&~3) + rfield + 1;



            for(j=start; j<end; j++){

                if (4 * h->ref_list[0][j].frame_num + (h->ref_list[0][j].f.reference & 3) == poc) {

                    int cur_ref= mbafi ? (j-16)^field : j;

                    map[list][2*old_ref + (rfield^field) + 16] = cur_ref;

                    if(rfield == field || !interl)

                        map[list][old_ref] = cur_ref;

                    break;

                }

            }

        }

    }

}

static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){

    MpegEncContext * const s = &h->s;

    Picture * const ref1 = &h->ref_list[1][0];

    int j, old_ref, rfield;

    int start= mbafi ? 16                      : 0;

    int end  = mbafi ? 16+2*h->ref_count[0]    : h->ref_count[0];

    int interl= mbafi || s->picture_structure != PICT_FRAME;



    

    memset(map[list], 0, sizeof(map[list]));



    for(rfield=0; rfield<2; rfield++){

        for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){

            int poc = ref1->ref_poc[colfield][list][old_ref];



            if     (!interl)

                poc |= 3;

            else if( interl && (poc&3) == 3) 

                poc= (poc&~3) + rfield + 1;



            for(j=start; j<end; j++){

                if (4 * h->ref_list[0][j].frame_num + (h->ref_list[0][j].f.reference & 3) == poc) {

                    int cur_ref= mbafi ? (j-16)^field : j;

                    map[list][2*old_ref + (rfield^field) + 16] = cur_ref;

                    if(rfield == field || !interl)

                        map[list][old_ref] = cur_ref;

                    break;

                }

            }

        }

    }

}

static void FUNC_0(H264Context *VAR_0, int VAR_1[2][16+32], int VAR_2, int VAR_3, int VAR_4, int VAR_5){

    MpegEncContext * const s = &VAR_0->s;

    Picture * const ref1 = &VAR_0->ref_list[1][0];

    int VAR_6, VAR_7, VAR_8;

    int VAR_9= VAR_5 ? 16                      : 0;

    int VAR_10  = VAR_5 ? 16+2*VAR_0->ref_count[0]    : VAR_0->ref_count[0];

    int VAR_11= VAR_5 || s->picture_structure != PICT_FRAME;



    

    memset(VAR_1[VAR_2], 0, sizeof(VAR_1[VAR_2]));



    for(VAR_8=0; VAR_8<2; VAR_8++){

        for(VAR_7=0; VAR_7<ref1->ref_count[VAR_4][VAR_2]; VAR_7++){

            int poc = ref1->ref_poc[VAR_4][VAR_2][VAR_7];



            if     (!VAR_11)

                poc |= 3;

            else if( VAR_11 && (poc&3) == 3) 

                poc= (poc&~3) + VAR_8 + 1;



            for(VAR_6=VAR_9; VAR_6<VAR_10; VAR_6++){

                if (4 * VAR_0->ref_list[0][VAR_6].frame_num + (VAR_0->ref_list[0][VAR_6].f.reference & 3) == poc) {

                    int cur_ref= VAR_5 ? (VAR_6-16)^VAR_3 : VAR_6;

                    VAR_1[VAR_2][2*VAR_7 + (VAR_8^VAR_3) + 16] = cur_ref;

                    if(VAR_8 == VAR_3 || !VAR_11)

                        VAR_1[VAR_2][VAR_7] = cur_ref;

                    break;

                }

            }

        }

    }

}

static void FUNC_0(H264Context *VAR_0, int VAR_1[2][16+32], int VAR_2, int VAR_3, int VAR_4, int VAR_5){ MpegEncContext * const s = &VAR_0->s; Picture * const ref1 = &VAR_0->ref_list[1][0]; int VAR_6, VAR_7, VAR_8; int VAR_9= VAR_5 ? 16                      : 0; int VAR_10  = VAR_5 ? 16+2*VAR_0->ref_count[0]    : VAR_0->ref_count[0]; int VAR_11= VAR_5 || s->picture_structure != PICT_FRAME; memset(VAR_1[VAR_2], 0, sizeof(VAR_1[VAR_2])); for(VAR_8=0; VAR_8<2; VAR_8++){ for(VAR_7=0; VAR_7<ref1->ref_count[VAR_4][VAR_2]; VAR_7++){ int poc = ref1->ref_poc[VAR_4][VAR_2][VAR_7]; if     (!VAR_11)
poc |= 3; else if( VAR_11 && (poc&3) == 3)
poc= (poc&~3) + VAR_8 + 1; for(VAR_6=VAR_9; VAR_6<VAR_10; VAR_6++){ if (4 * VAR_0->ref_list[0][VAR_6].frame_num + (VAR_0->ref_list[0][VAR_6].f.reference & 3) == poc) { int cur_ref= VAR_5 ? (VAR_6-16)^VAR_3 : VAR_6; VAR_1[VAR_2][2*VAR_7 + (VAR_8^VAR_3) + 16] = cur_ref; if(VAR_8 == VAR_3 || !VAR_11)
VAR_1[VAR_2][VAR_7] = cur_ref; break; } } } } }