// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rdi, %rbx
movb 0x80(%rsi), %al
andb $-0x2, %al
cmpb $0x32, %al
jne 0xbd6c6
movw $0x100, 0x19(%r14)      # imm = 0x100
jmp 0xbd7b0
movq 0x78(%r14), %rax
cmpq $0x3d, %rax
movl $0x3c, %r12d
cmovgeq %rax, %r12
leaq 0x10c(%r14), %r15
addq $-0x3c, %r12
movl $0x3e8, %esi            # imm = 0x3E8
cmpq %rsi, %rax
cmovlq %rax, %rsi
subq %r12, %rsi
cmpq $0x15, %rsi
jl 0xbd722
leaq (%r15,%r12), %rdi
leaq 0x7ac03(%rip), %rdx     # 0x138306
movq %rsp, %r9
movl $0x15, %ecx
movl $0x3f, %r8d
callq 0xec044
testl %eax, %eax
je 0xbd722
addq (%rsp), %r12
movb $0x1, %al
jmp 0xbd727
xorl %r12d, %r12d
xorl %eax, %eax
testb %al, %al
je 0xbd747
testq %r12, %r12
jle 0xbd747
movzbl -0x1(%r12,%r15), %eax
cmpl $0x18, %eax
je 0xbd7ab
cmpl $0x9, %eax
jne 0xbd7a5
movb $0x0, 0x19(%r14)
jmp 0xbd7b0
cmpb $0x0, 0x18(%r14)
je 0xbd7a5
movq 0x78(%r14), %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 0xbd7a5
addq %rax, %r15
leaq 0x7b167(%rip), %rdx     # 0x1388e9
movq %rsp, %r9
movl $0xd, %ecx
movq %r15, %rdi
movl $0x3f, %r8d
callq 0xec044
testl %eax, %eax
je 0xbd7a5
movw $0x101, 0x19(%r14)      # imm = 0x101
jmp 0xbd7b0
movb $0x1, (%r14)
jmp 0xbd7b0
movb $0x1, 0x19(%r14)
cmpb $0x0, (%r14)
jne 0xbd7e2
movzbl 0x19(%r14), %edx
leaq 0x7b135(%rip), %rsi     # 0x1388f7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movzbl 0x1a(%r14), %edx
leaq 0x7b12e(%rip), %rsi     # 0x138906
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq