package Nm6q_10;

import androidx.recyclerview.widget.RecyclerView;
/* compiled from: Segment.kt */
/* loaded from: classes.dex */
public final class BVpCZyH_19 {
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public BVpCZyH_19 f318KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public boolean f319KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final byte[] f320KQgRr5e_0;
    public int QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public BVpCZyH_19 f321QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public boolean f322QxJ9d_1;

    /* compiled from: Segment.kt */
    /* loaded from: classes.dex */
    public static final class KQgRr5e_0 {
        public KQgRr5e_0() {
        }

        public /* synthetic */ KQgRr5e_0(FSaI4_7.Xgtqvk_8.QxJ9d_1.Mqv2r_3 mqv2r_3) {
            this();
        }
    }

    static {
        new KQgRr5e_0(null);
    }

    public BVpCZyH_19() {
        this.f320KQgRr5e_0 = new byte[RecyclerView.WGk6X_27.FLAG_BOUNCED_FROM_HIDDEN_LIST];
        this.f322QxJ9d_1 = true;
        this.f319KQgRr5e_0 = false;
    }

    public final BVpCZyH_19 KQgRr5e_0() {
        BVpCZyH_19 bVpCZyH_19 = this.f318KQgRr5e_0;
        if (bVpCZyH_19 == this) {
            bVpCZyH_19 = null;
        }
        BVpCZyH_19 bVpCZyH_192 = this.f321QxJ9d_1;
        if (bVpCZyH_192 != null) {
            bVpCZyH_192.f318KQgRr5e_0 = this.f318KQgRr5e_0;
            BVpCZyH_19 bVpCZyH_193 = this.f318KQgRr5e_0;
            if (bVpCZyH_193 != null) {
                bVpCZyH_193.f321QxJ9d_1 = bVpCZyH_192;
                this.f318KQgRr5e_0 = null;
                this.f321QxJ9d_1 = null;
                return bVpCZyH_19;
            }
            FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
            throw null;
        }
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
        throw null;
    }

    public final BVpCZyH_19 QxJ9d_1() {
        this.f319KQgRr5e_0 = true;
        return new BVpCZyH_19(this.f320KQgRr5e_0, this.KQgRr5e_0, this.QxJ9d_1, true, false);
    }

    public BVpCZyH_19(byte[] bArr, int i, int i2, boolean z, boolean z2) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bArr, "data");
        this.f320KQgRr5e_0 = bArr;
        this.KQgRr5e_0 = i;
        this.QxJ9d_1 = i2;
        this.f319KQgRr5e_0 = z;
        this.f322QxJ9d_1 = z2;
    }

    public final BVpCZyH_19 KQgRr5e_0(BVpCZyH_19 bVpCZyH_19) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bVpCZyH_19, "segment");
        bVpCZyH_19.f321QxJ9d_1 = this;
        bVpCZyH_19.f318KQgRr5e_0 = this.f318KQgRr5e_0;
        BVpCZyH_19 bVpCZyH_192 = this.f318KQgRr5e_0;
        if (bVpCZyH_192 != null) {
            bVpCZyH_192.f321QxJ9d_1 = bVpCZyH_19;
            this.f318KQgRr5e_0 = bVpCZyH_19;
            return bVpCZyH_19;
        }
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
        throw null;
    }

    public final BVpCZyH_19 KQgRr5e_0(int i) {
        BVpCZyH_19 bVpCZyH_19;
        if (i > 0 && i <= this.QxJ9d_1 - this.KQgRr5e_0) {
            if (i >= 1024) {
                bVpCZyH_19 = QxJ9d_1();
            } else {
                BVpCZyH_19 KQgRr5e_02 = ZzDuCHW_20.KQgRr5e_0();
                QxJ9d_1.KQgRr5e_0(this.f320KQgRr5e_0, this.KQgRr5e_0, KQgRr5e_02.f320KQgRr5e_0, 0, i);
                bVpCZyH_19 = KQgRr5e_02;
            }
            bVpCZyH_19.QxJ9d_1 = bVpCZyH_19.KQgRr5e_0 + i;
            this.KQgRr5e_0 += i;
            BVpCZyH_19 bVpCZyH_192 = this.f321QxJ9d_1;
            if (bVpCZyH_192 != null) {
                bVpCZyH_192.KQgRr5e_0(bVpCZyH_19);
                return bVpCZyH_19;
            }
            FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
            throw null;
        }
        throw new IllegalArgumentException("byteCount out of range".toString());
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final void m156KQgRr5e_0() {
        int i = 0;
        if (this.f321QxJ9d_1 != this) {
            BVpCZyH_19 bVpCZyH_19 = this.f321QxJ9d_1;
            if (bVpCZyH_19 == null) {
                FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
                throw null;
            } else if (bVpCZyH_19.f322QxJ9d_1) {
                int i2 = this.QxJ9d_1 - this.KQgRr5e_0;
                if (bVpCZyH_19 == null) {
                    FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
                    throw null;
                }
                int i3 = 8192 - bVpCZyH_19.QxJ9d_1;
                if (bVpCZyH_19 == null) {
                    FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
                    throw null;
                }
                if (!bVpCZyH_19.f319KQgRr5e_0) {
                    if (bVpCZyH_19 == null) {
                        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
                        throw null;
                    }
                    i = bVpCZyH_19.KQgRr5e_0;
                }
                if (i2 > i3 + i) {
                    return;
                }
                BVpCZyH_19 bVpCZyH_192 = this.f321QxJ9d_1;
                if (bVpCZyH_192 != null) {
                    KQgRr5e_0(bVpCZyH_192, i2);
                    KQgRr5e_0();
                    ZzDuCHW_20.KQgRr5e_0(this);
                    return;
                }
                FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
                throw null;
            } else {
                return;
            }
        }
        throw new IllegalStateException("cannot compact".toString());
    }

    public final void KQgRr5e_0(BVpCZyH_19 bVpCZyH_19, int i) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bVpCZyH_19, "sink");
        if (bVpCZyH_19.f322QxJ9d_1) {
            int i2 = bVpCZyH_19.QxJ9d_1;
            if (i2 + i > 8192) {
                if (!bVpCZyH_19.f319KQgRr5e_0) {
                    int i3 = bVpCZyH_19.KQgRr5e_0;
                    if ((i2 + i) - i3 <= 8192) {
                        byte[] bArr = bVpCZyH_19.f320KQgRr5e_0;
                        QxJ9d_1.KQgRr5e_0(bArr, i3, bArr, 0, i2 - i3);
                        bVpCZyH_19.QxJ9d_1 -= bVpCZyH_19.KQgRr5e_0;
                        bVpCZyH_19.KQgRr5e_0 = 0;
                    } else {
                        throw new IllegalArgumentException();
                    }
                } else {
                    throw new IllegalArgumentException();
                }
            }
            QxJ9d_1.KQgRr5e_0(this.f320KQgRr5e_0, this.KQgRr5e_0, bVpCZyH_19.f320KQgRr5e_0, bVpCZyH_19.QxJ9d_1, i);
            bVpCZyH_19.QxJ9d_1 += i;
            this.KQgRr5e_0 += i;
            return;
        }
        throw new IllegalStateException("only owner can write".toString());
    }
}
