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

	de_dbg_indent_save(c, &saved_indent_level);
	if(pos<0 || pos+100>EPBYTES_LEN) goto done;

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

	if(pkl_memmatch(&d->epbytes[pos],
		(const u8*)"\x8b\xc4\x2d??\x25\xf0\xff\x8b\xf8\xb9??\xbe", 14, '?', 0))
	{
		d->copier_class = COPIER_CLASS_COM_100;
		pos_of_decompr_pos_field = pos+14;
	}
	else if(pkl_memmatch(&d->epbytes[pos],
		(const u8*)"\x8b\xc4\x2d??\x90\x25\xf0\xff\x8b\xf8\xb9??\x90\xbe", 16, '?', 0))
	{
		d->copier_class = COPIER_CLASS_COM_115;
		pos_of_decompr_pos_field = pos+16;
	}
	else if(pkl_memmatch(&d->epbytes[pos],
		(const u8*)"\xfa\xbc\x00\x02\x8e\xd0\xfb", 7, '?', 0))
	{
		d->copier_class = COPIER_CLASS_COM_BETA;
		d->decompr_pos = pos+24;
	}

	if(pos_of_decompr_pos_field) {
		d->decompr_pos = de_getu16le_direct(&d->epbytes[pos_of_decompr_pos_field]) - 0x100;
	}

done:
	if(!d->decompr_pos) {
		d->errflag = 1;
	}
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x14(%rbp), %rsi
callq 0x15b580
cmpq $0x0, -0x20(%rbp)
jl 0x1173a8
movq -0x20(%rbp), %rax
addq $0x64, %rax
cmpq $0x3e8, %rax            # imm = 0x3E8
jle 0x1173ad
jmp 0x1174d4
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xad34f(%rip), %rsi     # 0x1c470d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
addq -0x20(%rbp), %rdi
leaq 0xad331(%rip), %rsi     # 0x1c471a
movl $0xe, %edx
movl $0x3f, %ecx
xorl %r8d, %r8d
callq 0x15f6b0
cmpl $0x0, %eax
je 0x117419
movq -0x10(%rbp), %rax
movb $-0xf, 0x68(%rax)
movq -0x20(%rbp), %rax
addq $0xe, %rax
movq %rax, -0x28(%rbp)
jmp 0x1174a5
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
addq -0x20(%rbp), %rdi
leaq 0xad2fa(%rip), %rsi     # 0x1c4729
movl $0x10, %edx
movl $0x3f, %ecx
xorl %r8d, %r8d
callq 0x15f6b0
cmpl $0x0, %eax
je 0x11745c
movq -0x10(%rbp), %rax
movb $-0xe, 0x68(%rax)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x28(%rbp)
jmp 0x1174a3
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
addq -0x20(%rbp), %rdi
leaq 0xad5c1(%rip), %rsi     # 0x1c4a33
movl $0x7, %edx
movl $0x3f, %ecx
xorl %r8d, %r8d
callq 0x15f6b0
cmpl $0x0, %eax
je 0x1174a1
movq -0x10(%rbp), %rax
movb $-0x10, 0x68(%rax)
movq -0x20(%rbp), %rcx
addq $0x18, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x1174a3
jmp 0x1174a5
cmpq $0x0, -0x28(%rbp)
je 0x1174d2
movq -0x10(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
addq -0x28(%rbp), %rdi
callq 0x165260
movq %rax, %rcx
subq $0x100, %rcx            # imm = 0x100
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x1174d4
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
jne 0x1174e6
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x15b5a0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)