// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r14
leaq 0xd5e77(%rip), %rsi     # 0x11d993
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
je 0x47b35
movq %rax, %rdi
callq 0xea781
movl %eax, 0x8(%r14)
cmpl $0x200, 0x8(%r14)       # imm = 0x200
je 0x47b47
movl $0x10, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x38(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0x40(%r14)
movl $0xf0, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, 0x10(%r14)
movq 0x18(%rbx), %rsi
movq %rbx, %rdi
movq %rax, %rdx
callq 0x1053ee
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 0x1055db
cmpb $0x3, 0x1(%r15)
jne 0x47da7
leaq 0xd5d9e(%rip), %rsi     # 0x11d97c
movq %rbx, %rdi
callq 0xeb6d6
movq 0x50(%rsp), %rdx
movq %rdx, 0x28(%r14)
leaq 0xd5dca(%rip), %rsi     # 0x11d9c0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x10, %esi
callq 0xeba56
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 0xebf09
movq %r15, %rdi
callq 0xebe2a
movl %eax, 0x30(%r14)
movq %r15, %rdi
callq 0xebe1d
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0xe958c
movq 0x10(%r14), %rax
movq 0x20(%rax), %rdx
shlq $0x4, %rdx
addq 0x38(%rax), %rdx
movq %rdx, 0x18(%r14)
movq 0x28(%rax), %r15
leaq 0xd5d7e(%rip), %rsi     # 0x11d9ed
movq %rbx, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0xe9226
movq %r15, %rax
andq $-0x3, %rax
cmpq $0x10, %rax
jne 0x47dbd
movq 0x18(%r14), %rax
movq %rsp, %r12
movq %rax, (%r12)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movq %rax, 0x60(%r14)
leaq 0x1031d4(%rip), %rsi    # 0x14ae90
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef2dd
movq %rax, 0x58(%r14)
leaq 0xf1c79(%rip), %rsi     # 0x139958
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
addq $0x2, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movq %rax, 0x68(%r14)
leaq 0xd5d04(%rip), %rsi     # 0x11da0b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movq %rax, 0x50(%r14)
leaq 0xd5cf2(%rip), %rsi     # 0x11da1c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef2dd
movq %rax, 0x48(%r14)
leaq 0xd5cd6(%rip), %rsi     # 0x11da23
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movq %rax, 0x70(%r14)
leaq 0xd5cba(%rip), %rsi     # 0x11da2a
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpq $0x12, %r15
jl 0x47dc6
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xef1ed
movq %rax, 0x78(%r14)
leaq 0xd5c9e(%rip), %rsi     # 0x11da37
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
jmp 0x47dce
leaq 0xd5bf3(%rip), %rsi     # 0x11d9a1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x48012
movl $0x1, (%r14)
jmp 0x47dce
movq $0x1, 0x78(%r14)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpl $0x0, (%r14)
jne 0x48012
movq %rsp, %r9
movq $0x0, (%r9)
movq 0x10(%r14), %rax
movq 0x40(%rax), %rcx
addq $0x64, %rcx
movq 0x18(%rbx), %rdi
leaq 0xd5e23(%rip), %rsi     # 0x11dc28
movl $0x8, %edx
movl $0x64, %r8d
callq 0xf1a9c
movq 0x18(%rbx), %rdi
testl %eax, %eax
je 0x47e31
movq (%rsp), %rsi
addq $-0x2, %rsi
callq 0xef1ca
movl $0x1, %ecx
jmp 0x47e47
movq 0x28(%r14), %rsi
addq $-0x2, %rsi
callq 0xef1ca
addq $0x16, %rax
movl $0x2, %ecx
movq 0x10(%r14), %rdx
subq 0x28(%rdx), %rax
movq %rax, 0x20(%r14)
je 0x47e6b
addq $-0x191, %rax           # imm = 0xFE6F
cmpq $-0xde, %rax
ja 0x47e6b
movq $0x0, 0x20(%r14)
movq 0x20(%r14), %rdx
testq %rdx, %rdx
je 0x47e87
leaq 0xd5bc9(%rip), %rsi     # 0x11da44
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0x47ea5
leaq 0xd5bdc(%rip), %rsi     # 0x11da6a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%r14)
cmpl $0x0, (%r14)
jne 0x48012
movl 0x30(%r14), %edx
leaq 0xe3faf(%rip), %r15     # 0x12be69
cmpl $0x1797940b, %edx       # imm = 0x1797940B
jle 0x47ee3
cmpl $0x1797940c, %edx       # imm = 0x1797940C
je 0x47efc
cmpl $0x7b0bb610, %edx       # imm = 0x7B0BB610
je 0x47f05
cmpl $0x77dc4e4a, %edx       # imm = 0x77DC4E4A
jne 0x47f15
leaq 0xd5ba9(%rip), %r15     # 0x11da8a
jmp 0x47f15
cmpl $0xa6a446ac, %edx       # imm = 0xA6A446AC
je 0x47f0e
cmpl $0xae58e006, %edx       # imm = 0xAE58E006
jne 0x47f15
leaq 0xd5bce(%rip), %r15     # 0x11dac8
jmp 0x47f15
leaq 0xd5bfc(%rip), %r15     # 0x11daff
jmp 0x47f15
leaq 0xd5ba1(%rip), %r15     # 0x11daad
jmp 0x47f15
leaq 0xd5bcc(%rip), %r15     # 0x11dae1
leaq 0xd5bfe(%rip), %rsi     # 0x11db1a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
leaq 0xe6f3f(%rip), %rsi     # 0x12ee6c
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
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 0xfbe66
testl %eax, %eax
jne 0x47f65
movl $0x1, (%r14)
cmpl $0x0, (%r14)
jne 0x48012
movq 0x78(%r14), %rax
movq 0x10(%r14), %rcx
movq 0x70(%r14), %r15
movq 0x20(%rcx), %r13
movq 0x38(%rcx), %rdx
subq %rax, %r13
shlq $0x4, %r13
subq %rax, %r15
shlq $0x4, %r15
addq $0x10, %r15
leaq (%rdx,%r13), %r8
addq $0x10, %r8
addq $0x10, %r13
leaq 0xd5b8e(%rip), %rsi     # 0x11db36
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
leaq 0xd5ba5(%rip), %rsi     # 0x11db61
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
testq %r13, %r13
js 0x47fec
testq %r15, %r15
js 0x47fec
movq 0x10(%r14), %rax
movq 0x38(%rax), %rax
addq %r13, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x48070
movl $0x1, (%r14)
xorl %r8d, %r8d
movq %rbx, %rdi
movq %r8, %rsi
callq 0xe9752
cmpl $0x0, (%r14)
jne 0x48012
movq %rbx, %rdi
movq %r14, %rsi
callq 0x48248
testq %r14, %r14
je 0x4805e
cmpl $0x0, (%r14)
je 0x48035
cmpl $0x0, 0x4(%r14)
jne 0x48035
leaq 0xd59a5(%rip), %rsi     # 0x11d9d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq 0x38(%r14), %rdi
callq 0xf0b13
movq 0x40(%r14), %rdi
callq 0xf0b13
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xe9752
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
movq %r15, %rsi
callq 0xea79d
movq %rbx, %rdi
movq %rax, %rsi
callq 0xe969b
movq %rax, %r12
movq 0x18(%rbx), %rdi
movq 0x10(%r14), %rax
movq 0x38(%rax), %rdx
movq %r12, %rsi
movq %r13, %rcx
callq 0xeeee8
movq %r12, %r8
movq %r12, %r9
decq %r9
movq %r15, %r10
testq %r13, %r13
jle 0x480fc
leaq -0x1(%r13), %rax
movb -0x1(%r8,%r13), %bpl
movl %ebp, %ecx
andb $-0x4, %cl
cmpb $-0x50, %cl
jne 0x4810e
cmpq $0x2, %r13
jle 0x480e5
movzbl -0x2(%r8,%r13), %edx
shll $0x8, %edx
leaq -0x3(%r13), %rax
movzbl -0x3(%r8,%r13), %esi
leal (%rdx,%rsi), %ecx
cmpq %rcx, %r10
jge 0x4814c
movl $0x1, (%r14)
movl $0x2, %r12d
xorl %r11d, %r11d
testb %r11b, %r11b
jne 0x48119
jmp 0x4813b
movl $0x1, (%r14)
movl $0x2, %r12d
movq %r13, %rax
jmp 0x4813b
cmpb $-0x1, %bpl
jne 0x4812e
cmpq %r15, %r10
jne 0x4812e
andb $-0x3, %bpl
xorl %r12d, %r12d
cmpb $-0x4f, %bpl
sete %r12b
shll $0x2, %r12d
jmp 0x4813b
movl $0x1, (%r14)
movl $0x2, %r12d
movq %rax, %r13
testl %r12d, %r12d
je 0x480ac
jmp 0x48216
movl %ebp, %edi
andb $-0x4e, %dil
cmpb $-0x50, %dil
jne 0x481c6
cmpq $0x3, %r13
je 0x48202
addq $-0x4, %r13
xorl %r12d, %r12d
movb $0x1, %r11b
testq %rcx, %rcx
je 0x481be
leal (%rdx,%rsi), %eax
decl %eax
movq %rax, 0x10(%rsp)
movq %r10, %rdi
subq %rax, %rdi
addq %r9, %rdi
leaq 0x1(%rax), %rdx
movzbl (%r8,%r13), %esi
movq %r8, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq %r10, 0x18(%rsp)
callq 0x18140
movb $0x1, %r11b
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r9
movq 0x28(%rsp), %r8
movq 0x10(%rsp), %rax
notq %rax
addq %rax, %r10
movq %r13, %rax
jmp 0x480f5
cmpq %rcx, %rax
jl 0x480e5
xorl %r12d, %r12d
movb $0x1, %r11b
testq %rcx, %rcx
je 0x480f5
movq %r8, %rsi
xorl %edx, %edx
movb -0x4(%rsi,%r13), %dil
movb %dil, -0x1(%rsi,%r10)
incq %rdx
decq %rsi
cmpl %edx, %ecx
jne 0x481e3
subq %rdx, %rax
subq %rdx, %r10
jmp 0x480f5
movl $0x1, (%r14)
movl $0x2, %r12d
xorl %eax, %eax
jmp 0x480f2
cmpl $0x2, %r12d
je 0x47ff6
movq 0x40(%r14), %rdi
movq %r8, %rsi
movq %r15, %rdx
movq %r8, %r15
callq 0xefb82
movq %r15, %r8
jmp 0x47ff6