// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/pklite.c
// Function: analyze_detect_large_and_v120_cmpr
static void analyze_detect_large_and_v120_cmpr(deark *c, lctx *d)
{
	i64 foundpos = 0;
	int ret;

	if(d->decompr_class==DECOMPR_CLASS_120SMALL ||
		d->decompr_class==DECOMPR_CLASS_120SMALL_OLD)
	{
		d->dparams.v120_cmpr = 1;
		d->dparams.large_cmpr = 0;
		goto done;
	}

	// TODO?: A better search function to use when there are no wildcards.
	ret = pkl_search_match(d->epbytes, EPBYTES_LEN,
		d->approx_end_of_decompressor-60, d->approx_end_of_decompressor,
		(const u8*)"\x01\x02\x00\x00\x03\x04\x05\x06"
		"\x00\x00\x00\x00\x00\x00\x00\x00\x07\x08\x09\x0a\x0b", 21, 0x3f,
		0, &foundpos);
	if(ret && foundpos>0) {
		u8 prec_b;

		prec_b = d->epbytes[foundpos-1];
		if(prec_b==0x09) {
			d->dparams.large_cmpr = 0;
		}
		else if(prec_b==0x18) {
			d->dparams.large_cmpr = 1;
		}
		else {
			d->errflag = 1;
		}
		goto done;
	}

	// The only thing left should be v1.20 w/ large cmpr, which always uses extra cmpr
	if(!d->dparams.extra_cmpr) {
		d->errflag = 1;
		goto done;
	}

	// Files w/o the above pattern, but with the below pattern, are presumed
	// to be v1.20.
	ret = pkl_search_match(d->epbytes, EPBYTES_LEN,
		d->approx_end_of_decompressor-50, d->approx_end_of_decompressor,
		(const u8*)"\x33\xc0\x8b\xd8\x8b\xc8\x8b\xd0\x8b\xe8\x8b\xf0\x8b", 13, 0x3f,
		0, &foundpos);
	if(ret) {
		d->dparams.v120_cmpr = 1;
		d->dparams.large_cmpr = 1;
		goto done;
	}

	d->errflag = 1;

done:
	if(!d->errflag) {
		de_dbg(c, "large cmpr: %u", (UI)d->dparams.large_cmpr);
		de_dbg(c, "v1.20 cmpr: %u", (UI)d->dparams.v120_cmpr);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movb 0x80(%rsi), %al
andb $-0x2, %al
cmpb $0x32, %al
jne 0xbca51
movb $0x1, 0x1a(%rbx)
xorl %eax, %eax
xorl %edx, %edx
movb %al, 0x19(%rbx)
cmpb $0x0, (%rbx)
jne 0xbcb28
leaq 0x7bfff(%rip), %rsi     # 0x138a2c
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
movzbl 0x1a(%rbx), %edx
leaq 0x7bff9(%rip), %rsi     # 0x138a3b
movq %r14, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0xbcb28
movq 0x78(%rbx), %rax
cmpq $0x3d, %rax
movl $0x3c, %r12d
cmovgeq %rax, %r12
leaq 0x10c(%rbx), %r15
addq $-0x3c, %r12
movl $0x3e8, %esi            # imm = 0x3E8
cmpq %rsi, %rax
cmovlq %rax, %rsi
subq %r12, %rsi
cmpq $0x15, %rsi
jl 0xbcac1
leaq (%r15,%r12), %rdi
leaq 0x7c590(%rip), %rdx     # 0x13901e
movq %rsp, %r9
movl $0x15, %ecx
movl $0x3f, %r8d
callq 0xeba66
testl %eax, %eax
je 0xbcac1
addq (%rsp), %r12
jle 0xbcac1
movzbl -0x1(%r12,%r15), %eax
cmpl $0x9, %eax
je 0xbca16
cmpl $0x18, %eax
je 0xbcb19
jmp 0xbcb25
cmpb $0x0, 0x18(%rbx)
je 0xbcb25
movq 0x78(%rbx), %rcx
cmpq $0x33, %rcx
movl $0x32, %eax
cmovgeq %rcx, %rax
addq $-0x32, %rax
movl $0x3e8, %esi            # imm = 0x3E8
cmpq %rsi, %rcx
cmovlq %rcx, %rsi
subq %rax, %rsi
cmpq $0xd, %rsi
jl 0xbcb25
addq %rax, %r15
leaq 0x7bf23(%rip), %rdx     # 0x138a1e
movq %rsp, %r9
movl $0xd, %ecx
movq %r15, %rdi
movl $0x3f, %r8d
callq 0xeba66
testl %eax, %eax
je 0xbcb25
movb $0x1, 0x1a(%rbx)
movl $0x1, %edx
movb $0x1, %al
jmp 0xbca1a
movb $0x1, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq