// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x80(%rax), %eax
cmpl $0x33, %eax
je 0x1158e8
movq -0x10(%rbp), %rax
movzbl 0x80(%rax), %eax
cmpl $0x32, %eax
jne 0x1158fd
movq -0x10(%rbp), %rax
movb $0x1, 0x1a(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x19(%rax)
jmp 0x115a2c
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdx
subq $0x3c, %rdx
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xaefa6(%rip), %r8      # 0x1c48ce
movl $0x15, %r9d
xorl %eax, %eax
leaq -0x18(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x1159a7
cmpq $0x0, -0x18(%rbp)
jle 0x1159a7
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
movb 0x10c(%rax,%rcx), %al
movb %al, -0x1d(%rbp)
movzbl -0x1d(%rbp), %eax
cmpl $0x9, %eax
jne 0x115986
movq -0x10(%rbp), %rax
movb $0x0, 0x19(%rax)
jmp 0x1159a2
movzbl -0x1d(%rbp), %eax
cmpl $0x18, %eax
jne 0x115999
movq -0x10(%rbp), %rax
movb $0x1, 0x19(%rax)
jmp 0x1159a0
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x1159a2
jmp 0x115a2c
movq -0x10(%rbp), %rax
cmpb $0x0, 0x18(%rax)
jne 0x1159ba
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x115a2c
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rdx
subq $0x32, %rdx
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xae8ed(%rip), %r8      # 0x1c42d2
movl $0xd, %r9d
xorl %eax, %eax
leaq -0x18(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x115a25
movq -0x10(%rbp), %rax
movb $0x1, 0x1a(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x19(%rax)
jmp 0x115a2c
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x115a69
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x19(%rax), %edx
leaq 0xae898(%rip), %rsi     # 0x1c42e0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x1a(%rax), %edx
leaq 0xae88d(%rip), %rsi     # 0x1c42ef
movb $0x0, %al
callq 0x15b0d0
addq $0x40, %rsp
popq %rbp
retq
nop