for(i= h->ref_count[list]-1; i>=index; i--){ if(h->ref_list[list][i].pic_id == pic_id && h->ref_list[list][i].long_ref==1)
for(i= h->ref_count[list]-1; i>=0; i--){ if(h->ref_list[list][i].pic_id == pic_id && h->ref_list[list][i].long_ref==1)
static int decode_ref_pic_list_reordering(H264Context *h){    MpegEncContext * const s = &h->s;    int list;        print_short_term(h);    print_long_term(h);    if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move beofre func        for(list=0; list<2; list++){        memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]);        if(get_bits1(&s->gb)){            int pred= h->curr_pic_num;            int index;            for(index=0; ; index++){                int reordering_of_pic_nums_idc= get_ue_golomb(&s->gb);                int pic_id;                int i;                                if(reordering_of_pic_nums_idc==3)                     break;                                if(index >= h->ref_count[list]){                    av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n");                    return -1;                }                                if(reordering_of_pic_nums_idc<3){                    if(reordering_of_pic_nums_idc<2){                        const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1;                        if(abs_diff_pic_num >= h->max_pic_num){                            av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n");                            return -1;                        }                        if(reordering_of_pic_nums_idc == 0) pred-= abs_diff_pic_num;                        else                                pred+= abs_diff_pic_num;                        pred &= h->max_pic_num - 1;                                            for(i= h->ref_count[list]-1; i>=index; i--){                            if(h->ref_list[list][i].pic_id == pred && h->ref_list[list][i].long_ref==0)                                break;                        }                    }else{                        pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx                        for(i= h->ref_count[list]-1; i>=index; i--){                            if(h->ref_list[list][i].pic_id == pic_id && h->ref_list[list][i].long_ref==1)                                break;                        }                    }                    if(i < index){                        av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n");                        memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME                    }else if(i > index){                        Picture tmp= h->ref_list[list][i];                        for(; i>index; i--){                            h->ref_list[list][i]= h->ref_list[list][i-1];                        }                        h->ref_list[list][index]= tmp;                    }                }else{                    av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n");                    return -1;                }            }        }        if(h->slice_type!=B_TYPE) break;    }        if(h->slice_type==B_TYPE && !h->direct_spatial_mv_pred)        direct_dist_scale_factor(h);    return 0;    }