package x7;

/* JADX INFO: loaded from: classes.dex */
public final class C {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final byte[] f18727a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f18728b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f18729c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f18730d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final boolean f18731e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public C f18732f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public C f18733g;

    public C() {
        this.f18727a = new byte[8192];
        this.f18731e = true;
        this.f18730d = false;
    }

    public final C a() {
        C c3 = this.f18732f;
        if (c3 == this) {
            c3 = null;
        }
        C c8 = this.f18733g;
        P6.g.b(c8);
        c8.f18732f = this.f18732f;
        C c9 = this.f18732f;
        P6.g.b(c9);
        c9.f18733g = this.f18733g;
        this.f18732f = null;
        this.f18733g = null;
        return c3;
    }

    public final void b(C c3) {
        P6.g.e(c3, "segment");
        c3.f18733g = this;
        c3.f18732f = this.f18732f;
        C c8 = this.f18732f;
        P6.g.b(c8);
        c8.f18733g = c3;
        this.f18732f = c3;
    }

    public final C c() {
        this.f18730d = true;
        return new C(this.f18727a, this.f18728b, this.f18729c, true);
    }

    public final void d(C c3, int i) {
        P6.g.e(c3, "sink");
        if (!c3.f18731e) {
            throw new IllegalStateException("only owner can write");
        }
        int i5 = c3.f18729c;
        int i8 = i5 + i;
        byte[] bArr = c3.f18727a;
        if (i8 > 8192) {
            if (c3.f18730d) {
                throw new IllegalArgumentException();
            }
            int i9 = c3.f18728b;
            if (i8 - i9 > 8192) {
                throw new IllegalArgumentException();
            }
            B6.j.F(0, i9, i5, bArr, bArr);
            c3.f18729c -= c3.f18728b;
            c3.f18728b = 0;
        }
        int i10 = c3.f18729c;
        int i11 = this.f18728b;
        B6.j.F(i10, i11, i11 + i, this.f18727a, bArr);
        c3.f18729c += i;
        this.f18728b += i;
    }

    public C(byte[] bArr, int i, int i5, boolean z8) {
        P6.g.e(bArr, "data");
        this.f18727a = bArr;
        this.f18728b = i;
        this.f18729c = i5;
        this.f18730d = z8;
        this.f18731e = false;
    }
}
