package com.applovin.impl; import com.applovin.impl.ij; import com.applovin.impl.w8; import com.applovin.impl.x8; /* loaded from: classes.dex */ public final class v8 implements k8 { public static final o8 o = new o8() { // from class: com.applovin.impl.v8$$ExternalSyntheticLambda0 @Override // com.applovin.impl.o8 public final k8[] a() { k8[] b; b = v8.b(); return b; } }; private final byte[] a; private final bh b; private final boolean c; private final w8.a d; private m8 e; private qo f; private int g; private bf h; private a9 i; private int j; private int k; private u8 l; private int m; private long n; @Override // com.applovin.impl.k8 public void a() { } public v8() { this(0); } private void d(l8 l8Var) { this.h = x8.b(l8Var, !this.c); this.g = 1; } private void c(l8 l8Var) { byte[] bArr = this.a; l8Var.c(bArr, 0, bArr.length); l8Var.b(); this.g = 2; } private void f(l8 l8Var) { x8.d(l8Var); this.g = 3; } private void e(l8 l8Var) { x8.a aVar = new x8.a(this.i); boolean z = false; while (!z) { z = x8.a(l8Var, aVar); this.i = (a9) xp.a(aVar.a); } b1.a(this.i); this.j = Math.max(this.i.c, 6); ((qo) xp.a(this.f)).a(this.i.a(this.a, this.h)); this.g = 4; } private void b(l8 l8Var) { this.k = x8.b(l8Var); ((m8) xp.a(this.e)).a(b(l8Var.f(), l8Var.a())); this.g = 5; } public v8(int i) { this.a = new byte[42]; this.b = new bh(new byte[32768], 0); this.c = (i & 1) != 0; this.d = new w8.a(); this.g = 0; } private long a(bh bhVar, boolean z) { boolean z2; b1.a(this.i); int d = bhVar.d(); while (d <= bhVar.e() - 16) { bhVar.f(d); if (w8.a(bhVar, this.i, this.k, this.d)) { bhVar.f(d); return this.d.a; } d++; } if (z) { while (d <= bhVar.e() - this.j) { bhVar.f(d); try { z2 = w8.a(bhVar, this.i, this.k, this.d); } catch (IndexOutOfBoundsException unused) { z2 = false; } if (bhVar.d() <= bhVar.e() && z2) { bhVar.f(d); return this.d.a; } d++; } bhVar.f(bhVar.e()); return -1L; } bhVar.f(d); return -1L; } @Override // com.applovin.impl.k8 public void a(m8 m8Var) { this.e = m8Var; this.f = m8Var.a(0, 1); m8Var.c(); } private ij b(long j, long j2) { b1.a(this.i); a9 a9Var = this.i; if (a9Var.k != null) { return new z8(a9Var, j); } if (j2 != -1 && a9Var.j > 0) { u8 u8Var = new u8(a9Var, this.k, j, j2); this.l = u8Var; return u8Var.a(); } return new ij.b(a9Var.b()); } private void c() { ((qo) xp.a(this.f)).a((this.n * 1000000) / ((a9) xp.a(this.i)).e, 1, this.m, 0, null); } @Override // com.applovin.impl.k8 public int a(l8 l8Var, th thVar) { int i = this.g; if (i == 0) { d(l8Var); return 0; } if (i == 1) { c(l8Var); return 0; } if (i == 2) { f(l8Var); return 0; } if (i == 3) { e(l8Var); return 0; } if (i == 4) { b(l8Var); return 0; } if (i != 5) { throw new IllegalStateException(); } return b(l8Var, thVar); } private int b(l8 l8Var, th thVar) { boolean z; b1.a(this.f); b1.a(this.i); u8 u8Var = this.l; if (u8Var != null && u8Var.b()) { return this.l.a(l8Var, thVar); } if (this.n == -1) { this.n = w8.a(l8Var, this.i); return 0; } int e = this.b.e(); if (e < 32768) { int a = l8Var.a(this.b.c(), e, 32768 - e); z = a == -1; if (!z) { this.b.e(e + a); } else if (this.b.a() == 0) { c(); return -1; } } else { z = false; } int d = this.b.d(); int i = this.m; int i2 = this.j; if (i < i2) { bh bhVar = this.b; bhVar.g(Math.min(i2 - i, bhVar.a())); } long a2 = a(this.b, z); int d2 = this.b.d() - d; this.b.f(d); this.f.a(this.b, d2); this.m += d2; if (a2 != -1) { c(); this.m = 0; this.n = a2; } if (this.b.a() < 16) { int a3 = this.b.a(); System.arraycopy(this.b.c(), this.b.d(), this.b.c(), 0, a3); this.b.f(0); this.b.e(a3); } return 0; } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ k8[] b() { return new k8[]{new v8()}; } @Override // com.applovin.impl.k8 public void a(long j, long j2) { if (j == 0) { this.g = 0; } else { u8 u8Var = this.l; if (u8Var != null) { u8Var.b(j2); } } this.n = j2 != 0 ? -1L : 0L; this.m = 0; this.b.d(0); } @Override // com.applovin.impl.k8 public boolean a(l8 l8Var) { x8.a(l8Var, false); return x8.a(l8Var); } }