// File: /workspace/github_c_makefile_star2_O3/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 $0xa8, %rsp
movq %rdi, %rbx
movl $0x80, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0xd5f33(%rip), %rsi     # 0x11daa3
movq %rbx, %rdi
callq 0xe9b74
testq %rax, %rax
je 0x47b8b
movq %rax, %rdi
callq 0xe9c2a
movl %eax, 0x8(%r14)
jmp 0x47b8f
movl 0x8(%r14), %eax
cmpl $0x200, %eax            # imm = 0x200
je 0x47b9e
movl $0x10, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %rax, 0x38(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %rax, 0x40(%r14)
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x104f96
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r15
movaps %xmm0, (%r15)
movaps %xmm0, 0x60(%r15)
movaps %xmm0, 0x50(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movq $0x0, 0x70(%r15)
movb $0x3, (%r15)
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r15, %rdx
callq 0x105185
cmpb $0x3, 0x1(%r15)
jne 0x47e02
leaq 0xd5e57(%rip), %rsi     # 0x11da8c
movq %rbx, %rdi
callq 0xeb125
movq 0x50(%rsp), %rdx
movq %rdx, 0x28(%r14)
leaq 0xd5e83(%rip), %rsi     # 0x11dad0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x10, %esi
callq 0xeb499
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 0xeb944
movq %r15, %rdi
callq 0xeb865
movl %eax, 0x30(%r14)
movq %r15, %rdi
callq 0xeb858
leaq 0x14(%rsp), %rsi
movq %rbx, %rdi
callq 0xe8a1c
movq 0x10(%r14), %rax
movq 0x20(%rax), %rdx
shlq $0x4, %rdx
addq 0x38(%rax), %rdx
movq %rdx, 0x18(%r14)
movq 0x28(%rax), %r15
leaq 0xd5e37(%rip), %rsi     # 0x11dafd
movq %rbx, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0xe8617
movq %r15, %rax
andq $-0x3, %rax
cmpq $0x10, %rax
jne 0x47e22
movq 0x18(%r14), %rax
leaq 0x8(%rsp), %r12
movq %rax, (%r12)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, 0x60(%r14)
leaq 0x103772(%rip), %rsi    # 0x14b487
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeecce
movq %rax, 0x58(%r14)
leaq 0xf1fc0(%rip), %rsi     # 0x139cf8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
addq $0x2, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, 0x68(%r14)
leaq 0xd5dbb(%rip), %rsi     # 0x11db1b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, 0x50(%r14)
leaq 0xd5da9(%rip), %rsi     # 0x11db2c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeecce
movq %rax, 0x48(%r14)
leaq 0xd5d8d(%rip), %rsi     # 0x11db33
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, 0x70(%r14)
leaq 0xd5d71(%rip), %rsi     # 0x11db3a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpq $0x12, %r15
jb 0x47e2b
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeebeb
movq %rax, 0x78(%r14)
leaq 0xd5d53(%rip), %rsi     # 0x11db47
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
jmp 0x47e33
leaq 0xd5ca8(%rip), %rsi     # 0x11dab1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
cmpl $0x0, (%r14)
jne 0x47ef3
jmp 0x47f0b
movl $0x1, (%r14)
jmp 0x47e33
movq $0x1, 0x78(%r14)
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpl $0x0, (%r14)
jne 0x47ef3
leaq 0x8(%rsp), %r9
movq $0x0, (%r9)
movq 0x10(%r14), %rax
movq 0x40(%rax), %rcx
addq $0x64, %rcx
movq 0x18(%rbx), %rdi
leaq 0xd5ecc(%rip), %rsi     # 0x11dd38
movl $0x8, %edx
movl $0x64, %r8d
callq 0xf149c
movq 0x18(%rbx), %rdi
testl %eax, %eax
je 0x47e99
movq 0x8(%rsp), %rsi
addq $-0x2, %rsi
callq 0xeebc8
movl $0x1, %ecx
jmp 0x47eaf
movq 0x28(%r14), %rsi
addq $-0x2, %rsi
callq 0xeebc8
addq $0x16, %rax
movl $0x2, %ecx
movq 0x10(%r14), %rdx
subq 0x28(%rdx), %rax
movq %rax, 0x20(%r14)
je 0x47ed5
leaq -0x191(%rax), %rdx
cmpq $-0xde, %rdx
ja 0x47f46
movq $0x0, 0x20(%r14)
leaq 0xd5c9e(%rip), %rsi     # 0x11db7a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%r14)
cmpl $0x0, 0x4(%r14)
jne 0x47f0b
leaq 0xd5bdf(%rip), %rsi     # 0x11dae0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq 0x38(%r14), %rdi
callq 0xf052b
movq 0x40(%r14), %rdi
callq 0xf052b
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xe8be2
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd5c07(%rip), %rsi     # 0x11db54
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, (%r14)
jne 0x47ef3
movl 0x30(%r14), %edx
leaq 0xe41e6(%rip), %r15     # 0x12c151
cmpl $0x1797940b, %edx       # imm = 0x1797940B
jle 0x47f94
cmpl $0x1797940c, %edx       # imm = 0x1797940C
je 0x47fad
cmpl $0x7b0bb610, %edx       # imm = 0x7B0BB610
je 0x47fb6
cmpl $0x77dc4e4a, %edx       # imm = 0x77DC4E4A
jne 0x47fc6
leaq 0xd5c08(%rip), %r15     # 0x11db9a
jmp 0x47fc6
cmpl $0xa6a446ac, %edx       # imm = 0xA6A446AC
je 0x47fbf
cmpl $0xae58e006, %edx       # imm = 0xAE58E006
jne 0x47fc6
leaq 0xd5c2d(%rip), %r15     # 0x11dbd8
jmp 0x47fc6
leaq 0xd5c5b(%rip), %r15     # 0x11dc0f
jmp 0x47fc6
leaq 0xd5c00(%rip), %r15     # 0x11dbbd
jmp 0x47fc6
leaq 0xd5c2b(%rip), %r15     # 0x11dbf1
leaq 0xd5c5d(%rip), %rsi     # 0x11dc2a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
leaq 0xe7171(%rip), %rsi     # 0x12f14f
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
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 0xfb90a
testl %eax, %eax
je 0x480a5
cmpl $0x0, (%r14)
jne 0x47ef3
movq 0x78(%r14), %rax
movq 0x10(%r14), %rcx
movq 0x70(%r14), %rbp
movq 0x20(%rcx), %r12
movq 0x38(%rcx), %rdx
subq %rax, %r12
shlq $0x4, %r12
subq %rax, %rbp
shlq $0x4, %rbp
addq $0x10, %rbp
leaq (%r12,%rdx), %r8
addq $0x10, %r8
addq $0x10, %r12
leaq 0xd5bf0(%rip), %rsi     # 0x11dc46
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xe8617
leaq 0xd5c07(%rip), %rsi     # 0x11dc71
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe8617
testq %r12, %r12
js 0x48096
testq %rbp, %rbp
js 0x48096
movq 0x10(%r14), %rax
movq 0x38(%rax), %rax
addq %r12, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x480b1
movl $0x1, (%r14)
xorl %r8d, %r8d
jmp 0x481e5
movl $0x1, (%r14)
jmp 0x47ef3
movq %r12, %rdi
movq %rbp, %rsi
callq 0xe9c46
movq %rbx, %rdi
movq %rax, %rsi
callq 0xe8b2b
movq %rax, %r15
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rax
movq 0x38(%rax), %rdx
movq %r15, %rsi
movq %r12, %rcx
callq 0xee8d4
movq %r15, %r8
testq %r12, %r12
je 0x481de
movq %r8, %rax
decq %rax
movq %rax, 0x18(%rsp)
movq %rbp, %r15
movq %r8, 0x20(%rsp)
movb -0x1(%r8,%r12), %r13b
movl %r13d, %eax
andb $-0x4, %al
cmpb $-0x50, %al
jne 0x48188
cmpq $0x2, %r12
jbe 0x481de
movzbl -0x2(%r8,%r12), %ecx
shll $0x8, %ecx
movzbl -0x3(%r8,%r12), %edx
leal (%rcx,%rdx), %eax
cmpq %rax, %r15
jl 0x481de
movl %r13d, %esi
andb $-0x4e, %sil
cmpb $-0x50, %sil
jne 0x4819b
cmpq $0x3, %r12
je 0x481de
addq $-0x4, %r12
testq %rax, %rax
je 0x481cc
leal (%rcx,%rdx), %eax
decl %eax
movq %rax, 0x28(%rsp)
movq %r15, %rdi
subq %rax, %rdi
addq 0x18(%rsp), %rdi
leaq 0x1(%rax), %rdx
movzbl (%r8,%r12), %esi
callq 0x18140
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %rax
notq %rax
addq %rax, %r15
jmp 0x481cc
cmpb $-0x1, %r13b
jne 0x481de
cmpq %rbp, %r15
jne 0x481de
decq %r12
movq %rbp, %r15
jmp 0x481d5
leaq -0x3(%r12), %rcx
cmpq %rax, %rcx
jb 0x481de
testq %rax, %rax
je 0x481c9
movq %r8, %rsi
xorl %edx, %edx
movb -0x4(%rsi,%r12), %dil
movb %dil, -0x1(%rsi,%r15)
incq %rdx
decq %rsi
cmpl %edx, %eax
jne 0x481af
subq %rdx, %rcx
subq %rdx, %r15
movq %rcx, %r12
notb %r13b
testb $-0x4f, %r13b
je 0x4820a
testq %r12, %r12
jg 0x48100
movl $0x1, (%r14)
movq %rbx, %rdi
movq %r8, %rsi
callq 0xe8be2
cmpl $0x0, (%r14)
jne 0x47ef3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4822f
jmp 0x47e13
movq 0x40(%r14), %rdi
movq %r8, %rsi
movq %rbp, %rdx
movq %r8, %r15
callq 0xef547
movq %r15, %r8
jmp 0x481e5