package p5;

import x4.AbstractC3250p;

/* JADX INFO: loaded from: classes3.dex */
public final class K {

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

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

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

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

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

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

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

    public K() {
        this.f23061a = new byte[8192];
        this.f23065e = true;
        this.f23064d = false;
    }

    public final K a() {
        K k6 = this.f23066f;
        if (k6 == this) {
            k6 = null;
        }
        K k7 = this.f23067g;
        kotlin.jvm.internal.o.e(k7);
        k7.f23066f = this.f23066f;
        K k8 = this.f23066f;
        kotlin.jvm.internal.o.e(k8);
        k8.f23067g = this.f23067g;
        this.f23066f = null;
        this.f23067g = null;
        return k6;
    }

    public final void b(K segment) {
        kotlin.jvm.internal.o.h(segment, "segment");
        segment.f23067g = this;
        segment.f23066f = this.f23066f;
        K k6 = this.f23066f;
        kotlin.jvm.internal.o.e(k6);
        k6.f23067g = segment;
        this.f23066f = segment;
    }

    public final K c() {
        this.f23064d = true;
        return new K(this.f23061a, this.f23062b, this.f23063c, true, false);
    }

    public final void d(K sink, int i6) {
        kotlin.jvm.internal.o.h(sink, "sink");
        if (!sink.f23065e) {
            throw new IllegalStateException("only owner can write");
        }
        int i7 = sink.f23063c;
        int i8 = i7 + i6;
        byte[] bArr = sink.f23061a;
        if (i8 > 8192) {
            if (sink.f23064d) {
                throw new IllegalArgumentException();
            }
            int i9 = sink.f23062b;
            if (i8 - i9 > 8192) {
                throw new IllegalArgumentException();
            }
            AbstractC3250p.y(bArr, 0, i9, bArr, i7);
            sink.f23063c -= sink.f23062b;
            sink.f23062b = 0;
        }
        int i10 = sink.f23063c;
        int i11 = this.f23062b;
        AbstractC3250p.y(this.f23061a, i10, i11, bArr, i11 + i6);
        sink.f23063c += i6;
        this.f23062b += i6;
    }

    public K(byte[] data, int i6, int i7, boolean z6, boolean z7) {
        kotlin.jvm.internal.o.h(data, "data");
        this.f23061a = data;
        this.f23062b = i6;
        this.f23063c = i7;
        this.f23064d = z6;
        this.f23065e = z7;
    }
}
