// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/exepack.c
// Function: de_run_exepack
static void de_run_exepack(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	const char *s;
	struct fmtutil_specialexe_detection_data edd;

	d = de_malloc(c, sizeof(lctx));

	s = de_get_ext_option(c, "execomp:align");
	if(s) {
		d->default_code_alignment = de_atoi(s);
	}
	if(d->default_code_alignment != 512) {
		d->default_code_alignment = 16;
	}

	d->guest_reloc_table = dbuf_create_membuf(c, 0, 0);
	d->dcmpr_code = dbuf_create_membuf(c, 0, 0);
	d->host_ei = de_malloc(c, sizeof(struct fmtutil_exe_info));
	fmtutil_collect_exe_info(c, c->infile, d->host_ei);

	de_zeromem(&edd, sizeof(struct fmtutil_specialexe_detection_data));
	edd.restrict_to_fmt = DE_SPECIALEXEFMT_EXEPACK;
	fmtutil_detect_execomp(c, d->host_ei, &edd);
	if(edd.detected_fmt != DE_SPECIALEXEFMT_EXEPACK) {
		de_err(c, "Not an EXEPACK-compressed file");
		goto done;
	}
	de_declare_fmt(c, "EXEPACK-compressed EXE");

	d->epilog_pos = edd.special_pos_1;
	de_dbg(c, "epilog pos: %"I64_FMT, d->epilog_pos);

	calc_decoder_fingerprint(c, d);

	do_read_header(c, d);
	if(d->errflag) goto done;
	find_decoder_len(c, d);
	if(d->errflag) goto done;

	report_exepack_version(c, d);

	do_read_reloc_tbl(c, d);
	if(d->errflag) goto done;

	do_decompress_code(c, d);
	if(d->errflag) goto done;

	do_write_dcmpr(c, d);

done:
	if(d) {
		if(d->errflag && !d->errmsg_handled) {
			de_err(c, "EXEPACK decompression failed");
		}
		dbuf_close(d->guest_reloc_table);
		dbuf_close(d->dcmpr_code);
		de_free(c, d->host_ei);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
movl $0x80, %esi
callq 0xdecaf
movq %rax, %r14
leaq 0xcafdf(%rip), %rsi     # 0x1109b3
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
je 0x459ef
movq %rax, %rdi
callq 0xdfb36
movl %eax, 0x8(%r14)
jmp 0x459f3
movl 0x8(%r14), %eax
cmpl $0x200, %eax            # imm = 0x200
je 0x45a02
movl $0x10, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %rax, 0x38(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %rax, 0x40(%r14)
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0xf8849
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm0, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
andq $0x0, 0x70(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movb $0x3, (%r15)
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0xf8a24
cmpb $0x3, 0x1(%r15)
jne 0x45c5f
leaq 0xcaf06(%rip), %rsi     # 0x11099c
movq %rbx, %rdi
callq 0xe07f7
movq 0x60(%rsp), %rdx
movq %rdx, 0x28(%r14)
leaq 0xcaf32(%rip), %rsi     # 0x1109e0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, %r15
movq 0x10(%r14), %rax
movq 0x28(%r14), %rcx
movq 0x40(%rax), %rdx
subq %rdx, %rcx
addq $-0xf, %rcx
movq 0x18(%rbx), %rsi
movq %r15, %rdi
callq 0xe0f33
movq %r15, %rdi
callq 0xe0e95
movl %eax, 0x30(%r14)
movq %r15, %rdi
callq 0xe0e8d
leaq 0x1c(%rsp), %rsi
movq %rbx, %rdi
callq 0xdebae
movq 0x10(%r14), %rax
movq 0x20(%rax), %rdx
shlq $0x4, %rdx
addq 0x38(%rax), %rdx
movq %rdx, 0x18(%r14)
movq 0x28(%rax), %r15
leaq 0xcaee8(%rip), %rsi     # 0x110a0d
movq %rbx, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0xde896
movq %r15, %rax
andq $-0x3, %rax
cmpq $0x10, %rax
jne 0x45c7f
movq 0x18(%r14), %rax
leaq 0x10(%rsp), %r12
movq %rax, (%r12)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, 0x60(%r14)
leaq 0xf8445(%rip), %rsi     # 0x13dfb7
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe4038
movq %rax, 0x58(%r14)
leaq 0xe6e53(%rip), %rsi     # 0x12c9e8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
addq $0x2, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, 0x68(%r14)
leaq 0xcae6e(%rip), %rsi     # 0x110a2b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, 0x50(%r14)
leaq 0xcae5c(%rip), %rsi     # 0x110a3c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe4038
movq %rax, 0x48(%r14)
leaq 0xcae40(%rip), %rsi     # 0x110a43
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, 0x70(%r14)
leaq 0xcae24(%rip), %rsi     # 0x110a4a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
cmpq $0x12, %r15
jb 0x45c88
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xe3fc4
movq %rax, 0x78(%r14)
leaq 0xcae06(%rip), %rsi     # 0x110a57
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
jmp 0x45c90
leaq 0xcad5b(%rip), %rsi     # 0x1109c1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
cmpl $0x0, (%r14)
jne 0x45d41
jmp 0x45d59
movl $0x1, (%r14)
jmp 0x45c90
movq $0x1, 0x78(%r14)
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpl $0x0, (%r14)
jne 0x45d41
leaq 0x10(%rsp), %r9
andq $0x0, (%r9)
movq 0x10(%r14), %rax
movq 0x40(%rax), %rcx
addq $0x64, %rcx
movq 0x18(%rbx), %rdi
leaq 0xcaf82(%rip), %rsi     # 0x110c48
pushq $0x8
popq %rdx
pushq $0x64
popq %r8
callq 0xe62f1
movq 0x18(%rbx), %rdi
testl %eax, %eax
je 0x45cec
movq 0x10(%rsp), %rsi
addq $-0x2, %rsi
callq 0xe3fa3
pushq $0x1
jmp 0x45cff
movq 0x28(%r14), %rsi
addq $-0x2, %rsi
callq 0xe3fa3
addq $0x16, %rax
pushq $0x2
popq %rcx
movq 0x10(%r14), %rdx
subq 0x28(%rdx), %rax
movq %rax, 0x20(%r14)
je 0x45d23
leaq -0x191(%rax), %rdx
cmpq $-0xde, %rdx
ja 0x45d94
andq $0x0, 0x20(%r14)
leaq 0xcad60(%rip), %rsi     # 0x110a8a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%r14)
cmpl $0x0, 0x4(%r14)
jne 0x45d59
leaq 0xcaca1(%rip), %rsi     # 0x1109f0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq 0x38(%r14), %rdi
callq 0xe5591
movq 0x40(%r14), %rdi
callq 0xe5591
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xded32
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcacc9(%rip), %rsi     # 0x110a64
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
cmpl $0x0, (%r14)
jne 0x45d41
movl 0x30(%r14), %edx
cmpl $0xa6a446ac, %edx       # imm = 0xA6A446AC
je 0x45e07
cmpl $0xae58e006, %edx       # imm = 0xAE58E006
je 0x45de3
cmpl $0x1797940c, %edx       # imm = 0x1797940C
je 0x45df5
cmpl $0x7b0bb610, %edx       # imm = 0x7B0BB610
je 0x45dec
cmpl $0x77dc4e4a, %edx       # imm = 0x77DC4E4A
jne 0x45dfe
leaq 0xcacc9(%rip), %r15     # 0x110aaa
jmp 0x45e0e
leaq 0xcacfe(%rip), %r15     # 0x110ae8
jmp 0x45e0e
leaq 0xcacda(%rip), %r15     # 0x110acd
jmp 0x45e0e
leaq 0xcad23(%rip), %r15     # 0x110b1f
jmp 0x45e0e
leaq 0xd90dc(%rip), %r15     # 0x11eee1
jmp 0x45e0e
leaq 0xcacf3(%rip), %r15     # 0x110b01
leaq 0xcad25(%rip), %rsi     # 0x110b3a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
leaq 0xdc0a1(%rip), %rsi     # 0x121ec7
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x10(%r14), %rax
movq 0x20(%r14), %rsi
addq 0x40(%rax), %rsi
movq 0x68(%r14), %rdx
addq 0x18(%r14), %rdx
movq 0x38(%r14), %rcx
movq %rbx, %rdi
callq 0xefc86
testl %eax, %eax
je 0x45eed
cmpl $0x0, (%r14)
jne 0x45d41
movq 0x78(%r14), %rax
movq 0x10(%r14), %rcx
movq 0x70(%r14), %r15
movq 0x20(%rcx), %r12
movq 0x38(%rcx), %rdx
subq %rax, %r12
shlq $0x4, %r12
subq %rax, %r15
shlq $0x4, %r15
addq $0x10, %r15
leaq (%r12,%rdx), %r8
addq $0x10, %r8
addq $0x10, %r12
leaq 0xcacb8(%rip), %rsi     # 0x110b56
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xde896
leaq 0xcaccf(%rip), %rsi     # 0x110b81
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
testq %r12, %r12
js 0x45ede
testq %r15, %r15
js 0x45ede
movq 0x10(%r14), %rax
movq 0x38(%rax), %rax
addq %r12, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x45ef9
movl $0x1, (%r14)
xorl %r13d, %r13d
jmp 0x45feb
movl $0x1, (%r14)
jmp 0x45d41
movq %r12, %rdi
movq %r15, %rsi
callq 0xdfb50
movq %rbx, %rdi
movq %rax, %rsi
callq 0xdecaf
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rax
movq 0x38(%rax), %rdx
movq %r13, %rsi
movq %r12, %rcx
callq 0xe3cb7
movq %r15, %rax
testq %r12, %r12
jle 0x45fe4
movb -0x1(%r13,%r12), %cl
movl %ecx, %edx
andb $-0x4, %dl
cmpb $-0x50, %dl
jne 0x45f87
cmpq $0x2, %r12
jbe 0x45fe4
movzwl -0x3(%r13,%r12), %edx
cmpq %rdx, %rax
jl 0x45fe4
movl %ecx, %esi
andb $-0x4e, %sil
cmpb $-0x50, %sil
jne 0x45f99
cmpq $0x3, %r12
je 0x45fe4
movb -0x4(%r13,%r12), %sil
addq $-0x4, %r12
subl $0x1, %edx
jb 0x45fc8
movb %sil, -0x1(%r13,%rax)
decq %rax
jmp 0x45f78
cmpb $-0x1, %cl
jne 0x45fe4
decq %r12
cmpq %r15, %rax
movq %r15, %rax
je 0x45f2c
jmp 0x45fe4
leaq -0x3(%r12), %rsi
cmpq %rdx, %rsi
jb 0x45fe4
movq %r13, %rdi
xorl %esi, %esi
cmpl %esi, %edx
je 0x45fbe
movb -0x4(%rdi,%r12), %r8b
movb %r8b, -0x1(%rdi,%rax)
incq %rsi
decq %rdi
jmp 0x45fa8
subq %rsi, %rax
subq %rsi, %r12
addq $-0x3, %r12
notb %cl
testb $-0x4f, %cl
jne 0x45f2c
movq 0x40(%r14), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0xe46ba
jmp 0x45feb
movl $0x1, (%r14)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
cmpl $0x0, (%r14)
jne 0x45d41
movslq 0x8(%r14), %r13
movq 0x10(%r14), %rcx
movq 0x38(%r14), %rax
movq 0x18(%rax), %rax
movq 0x30(%rcx), %rdx
pushq $0x1c
popq %r15
testq %rax, %rax
je 0x46023
cmpq $0x1c, %rdx
jl 0x4602c
movq 0x38(%rcx), %rcx
cmpq %rcx, %rdx
jle 0x46035
xorl %edx, %edx
movq %r15, 0x8(%rsp)
jmp 0x4609f
cmpq $0x1d, %rdx
movq %rdx, 0x8(%rsp)
cmovgeq %rdx, %r15
pushq $0x10
popq %r12
cqto
idivq %r12
addq %r15, %rdx
subq %rdx, %rcx
xorl %edx, %edx
testq %rcx, %rcx
cmovgq %rcx, %rdx
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %rdx, %rbp
callq 0xe66d2
movq 0x10(%r14), %rcx
movq 0x38(%rcx), %rcx
cmpq $0x201, %rcx            # imm = 0x201
jl 0x46086
testl %eax, %eax
jne 0x46086
movq %r12, %r13
movq %rbp, %rdx
jmp 0x4609f
xorl %edx, %edx
testl %eax, %eax
cmovneq %rdx, %rbp
movq %rbp, %rdx
cmpq $0x201, %rcx            # imm = 0x201
pushq $0x10
popq %rax
cmovgeq %rax, %r13
movq 0x38(%r14), %rax
movq %rdx, 0x38(%rsp)
leaq (%rdx,%r15), %rdi
addq 0x18(%rax), %rdi
movq %r13, %rsi
callq 0xdfbb6
movq %rax, %r13
movq 0x40(%r14), %rax
movq %r13, 0x30(%rsp)
addq 0x18(%rax), %r13
leaq 0xd06a6(%rip), %rsi     # 0x116775
movq $0x0, 0x20(%rsp)
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, %rbp
movq 0x18(%rbx), %rdi
pushq $0xa
popq %rsi
callq 0xe3fa3
movq %rax, %r12
movq 0x18(%rbx), %rdi
pushq $0xc
popq %rsi
callq 0xe3fa3
movq %rax, 0x28(%rsp)
movq 0x10(%r14), %rax
shlq $0x4, %r12
addq 0x48(%rax), %r12
subq 0x38(%rax), %r12
pushq $0x10
popq %rsi
movq %r12, %rdi
callq 0xdfbb6
movq 0x40(%r14), %rcx
subq 0x18(%rcx), %rax
jl 0x46145
movq %rax, %rdi
pushq $0x10
popq %r12
movq %r12, %rsi
callq 0xdfbb6
cqto
idivq %r12
movq %rax, 0x20(%rsp)
movl $0x5a4d, %esi           # imm = 0x5A4D
movq %rbp, %rdi
callq 0xe5f08
movl $0x200, %r12d           # imm = 0x200
movq %r13, %rax
cqto
idivq %r12
movq %rbp, %rdi
movq %rdx, %rsi
callq 0xe5f08
addq $0x1ff, %r13            # imm = 0x1FF
movq %r13, %rax
cqto
idivq %r12
movq %rbp, %rdi
movq %rax, %rsi
callq 0xe5f08
movq 0x38(%r14), %rax
movq 0x18(%rax), %rax
pushq $0x4
popq %rcx
cqto
idivq %rcx
movq %rbp, %rdi
movq %rax, %rsi
callq 0xe5f08
movq 0x30(%rsp), %r12
movq %r12, %rax
cqto
pushq $0x10
popq %rcx
idivq %rcx
movq %rbp, %rdi
movq %rax, %rsi
callq 0xe5f08
movq %rbp, %rdi
movq 0x20(%rsp), %rsi
callq 0xe5f08
movq %rbp, %rdi
movq 0x28(%rsp), %rsi
callq 0xe5f08
movq 0x48(%r14), %rsi
movq %rbp, %rdi
callq 0xe5f38
movq 0x50(%r14), %rsi
movq %rbp, %rdi
callq 0xe5f08
movq %rbp, %rdi
xorl %esi, %esi
callq 0xe5f08
movq 0x60(%r14), %rsi
movq %rbp, %rdi
callq 0xe5f08
movq 0x58(%r14), %rsi
movq %rbp, %rdi
callq 0xe5f38
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
callq 0xe5f08
movq %rbp, %rdi
xorl %esi, %esi
callq 0xe5f08
movq 0x18(%rbx), %rdi
leaq -0x1c(%r15), %rdx
pushq $0x1c
popq %rsi
movq %rbp, %rcx
callq 0xe45f4
movq %rbp, %rdi
movq %r15, %rsi
callq 0xe5eb2
movq 0x38(%r14), %rdi
movq 0x18(%rdi), %rdx
xorl %esi, %esi
movq %rbp, %rcx
callq 0xe45f4
movq 0x38(%rsp), %rdx
testq %rdx, %rdx
je 0x4626f
movq 0x18(%rbx), %rdi
movq %r15, %rsi
movq %rbp, %rcx
callq 0xe45f4
movq %rbp, %rdi
movq %r12, %rsi
callq 0xe5eb2
movq 0x40(%r14), %rdi
movq 0x18(%rdi), %rdx
xorl %esi, %esi
movq %rbp, %rcx
callq 0xe45f4
movq 0x10(%r14), %rax
movq 0x50(%rax), %rcx
testq %rcx, %rcx
jle 0x462c6
movq 0x48(%rax), %rdx
leaq 0xca8f3(%rip), %rsi     # 0x110b97
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rax
movq 0x48(%rax), %rsi
movq 0x50(%rax), %rdx
movq %rbp, %rcx
callq 0xe45f4
movq %rbp, %rdi
callq 0xe5591
movq 0x10(%r14), %rax
cmpb $0x0, 0x60(%rax)
je 0x462e9
leaq 0xca8d5(%rip), %rsi     # 0x110bb4
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
cmpl $0x0, (%r14)
jne 0x45d41
movq %rbx, %rdi
callq 0xdf04c
jmp 0x45c70