// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pklite.c
// Function: analyze_copier
static void analyze_copier(deark *c, lctx *d)
{
	i64 pos_of_decompr_pos_field = 0;
	i64 foundpos = 0;
	i64 pos = d->copier_pos;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	if(d->data_before_decoder) goto done;
	if(!pos) {
		d->errflag = 1;
		goto done;
	}
	if(pos+200 > EPBYTES_LEN) {
		d->errflag = 1;
		goto done;
	}

	de_dbg(c, "copier at ep+%u", (UI)pos);
	de_dbg_indent(c, 1);

	if(pkl_search_match(d->epbytes, EPBYTES_LEN,
		pos, pos+75,
		(const u8*)"\xb9??\x33\xff\x57\xbe??\xfc\xf3\xa5", 12, '?', 0, &foundpos))
	{
		if(d->epbytes[foundpos+12]==0xcb) {
			d->copier_class = COPIER_CLASS_COMMON;
		}
		else if(d->epbytes[foundpos+12]==0xca) {
			d->copier_class = COPIER_CLASS_150SCR;
		}
		else {
			d->copier_class = COPIER_CLASS_OTHER;
		}
		pos_of_decompr_pos_field = foundpos+7;
	}

	else if(pkl_search_match(d->epbytes, EPBYTES_LEN,
		pos, pos+75,
		(const u8*)"\xb9??\x33\xff\x57\xfc\xbe??\xf3\xa5\xcb", 13, '?', 0, &foundpos))
	{
		d->copier_class = COPIER_CLASS_PKLITE201LIKE;
		pos_of_decompr_pos_field = foundpos+8;
	}

	else if(pkl_search_match(d->epbytes, EPBYTES_LEN,
		pos, pos+75,
		(const u8*)"\x57\xb9??\xbe??\xfc\xf3\xa5\xc3", 11, '?', 0, &foundpos))
	{
		d->copier_class = COPIER_CLASS_120VAR1SMALL;
		pos_of_decompr_pos_field = foundpos+5;
	}
	else if(pkl_search_match(d->epbytes, EPBYTES_LEN,
		pos, pos+75,
		(const u8*)"\xb9??\x33\xff\x56\xbe??\xfc\xf2\xa5\xca", 13, '?', 0, &foundpos))
	{
		d->copier_class = COPIER_CLASS_MEGALITE;
		pos_of_decompr_pos_field = foundpos+7;
	}
	else if(pkl_search_match(d->epbytes, EPBYTES_LEN,
		pos, pos+75,
		(const u8*)"\xb9??\x2b\xff\x57\xbe??\xfc\xf3\xa5\xcb", 13, '?', 0, &foundpos))
	{
		d->copier_class = COPIER_CLASS_UN2PACK;
		pos_of_decompr_pos_field = foundpos+7;
	}

	if(!d->copier_class) {
		d->errflag = 1;
		goto done;
	}

	de_dbg(c, "copier class: %u", (UI)d->copier_class);
	de_dbg(c, "copier subclass: %"I64_FMT, pos_of_decompr_pos_field-pos);
	d->decompr_pos = ip_to_eprel(d, de_getu16le_direct(&d->epbytes[pos_of_decompr_pos_field]));

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
cmpb $0x0, 0x6(%rax)
je 0x115068
jmp 0x11537b
cmpq $0x0, -0x28(%rbp)
jne 0x11507b
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11537b
movq -0x28(%rbp), %rax
addq $0xc8, %rax
cmpq $0x3e8, %rax            # imm = 0x3E8
jle 0x115099
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11537b
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0xaf0ec(%rip), %rsi     # 0x1c4196
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x4b, %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xaf0c4(%rip), %r8      # 0x1c41a6
movl $0xc, %r9d
xorl %eax, %eax
leaq -0x20(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
cmpl $0x0, %eax
je 0x115169
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movzbl 0x118(%rax,%rcx), %eax
cmpl $0xcb, %eax
jne 0x11512d
movq -0x10(%rbp), %rax
movb $0x1, 0x68(%rax)
jmp 0x115158
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movzbl 0x118(%rax,%rcx), %eax
cmpl $0xca, %eax
jne 0x11514e
movq -0x10(%rbp), %rax
movb $0x2, 0x68(%rax)
jmp 0x115156
movq -0x10(%rbp), %rax
movb $-0x38, 0x68(%rax)
jmp 0x115158
movq -0x20(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x18(%rbp)
jmp 0x115301
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x4b, %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xaf027(%rip), %r8      # 0x1c41b3
movl $0xd, %r9d
xorl %eax, %eax
leaq -0x20(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
cmpl $0x0, %eax
je 0x1151cf
movq -0x10(%rbp), %rax
movb $0x14, 0x68(%rax)
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
jmp 0x1152ff
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x4b, %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xaefcf(%rip), %r8      # 0x1c41c1
movl $0xb, %r9d
xorl %eax, %eax
leaq -0x20(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
cmpl $0x0, %eax
je 0x115235
movq -0x10(%rbp), %rax
movb $0xa, 0x68(%rax)
movq -0x20(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x18(%rbp)
jmp 0x1152fd
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x4b, %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xaef75(%rip), %r8      # 0x1c41cd
movl $0xd, %r9d
xorl %eax, %eax
leaq -0x20(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
cmpl $0x0, %eax
je 0x115298
movq -0x10(%rbp), %rax
movb $0x65, 0x68(%rax)
movq -0x20(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x18(%rbp)
jmp 0x1152fb
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
movq -0x28(%rbp), %rdx
movq -0x28(%rbp), %rcx
addq $0x4b, %rcx
movl $0x3e8, %esi            # imm = 0x3E8
leaq 0xaef20(%rip), %r8      # 0x1c41db
movl $0xd, %r9d
xorl %eax, %eax
leaq -0x20(%rbp), %rax
movl $0x3f, (%rsp)
movl $0x0, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x115d30
cmpl $0x0, %eax
je 0x1152f9
movq -0x10(%rbp), %rax
movb $0x64, 0x68(%rax)
movq -0x20(%rbp), %rax
addq $0x7, %rax
movq %rax, -0x18(%rbp)
jmp 0x1152fb
jmp 0x1152fd
jmp 0x1152ff
jmp 0x115301
movq -0x10(%rbp), %rax
cmpb $0x0, 0x68(%rax)
jne 0x115314
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11537b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x68(%rax), %edx
leaq 0xaeec2(%rip), %rsi     # 0x1c41e9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
subq -0x28(%rbp), %rdx
leaq 0xaeeb9(%rip), %rsi     # 0x1c41fa
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
addq -0x18(%rbp), %rdi
callq 0x165260
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x115ce0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)