// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/pklite.c
// Function: acquire_new_exe_header
static void acquire_new_exe_header(deark *c, lctx *d)
{
	int ret;

	d->guest_ei = de_malloc(c, sizeof(struct fmtutil_exe_info));
	d->hdr_for_dcmpr_file =  dbuf_create_membuf(c, 0, 0);
	dbuf_writeu16le(d->hdr_for_dcmpr_file, 0x5a4d); // "MZ"

	ret = read_orig_header(c, d);
	if(ret) goto done; // If success, we're done. Otherwise try other method.

	dbuf_truncate(d->hdr_for_dcmpr_file, 2);
	reconstruct_header(c, d);
done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl $0xf0, %esi
callq 0xe969b
movq %rax, 0x28(%rbx)
xorl %ebp, %ebp
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %rax, 0xc8(%rbx)
movl $0x5a4d, %esi           # imm = 0x5A4D
movq %rax, %rdi
callq 0xf1598
movb $0x1, %r12b
xorl %r13d, %r13d
cmpb $0x0, 0x18(%rbx)
jne 0xbd16f
movq 0x20(%rbx), %rax
movq 0x8(%rax), %r15
movq 0x38(%rax), %r13
shlq $0x2, %r15
addq 0x30(%rax), %r15
subq %r15, %r13
cmpq $0x1a, %r13
jge 0xbd039
movl $0x1, %ebp
xorl %r13d, %r13d
jmp 0xbd16f
movq 0x18(%r14), %rdi
leaq 0x16(%r15), %rsi
callq 0xef1ca
leaq 0x2(%r13), %rcx
leaq -0x2(%rax), %r12
cmpq %rcx, %rax
cmovgeq %r13, %r12
cmpq $0x1c, %rax
cmovlq %r13, %r12
leaq 0x7bae8(%rip), %rsi     # 0x138b4c
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%r14), %rdi
movq %r15, %rsi
callq 0xef1ca
movq %rax, (%rsp)
movq 0x18(%r14), %rdi
leaq 0x2(%r15), %rsi
callq 0xef1ca
movl $0x3, %ebp
movb $0x1, %r13b
cmpq $0x1ff, (%rsp)          # imm = 0x1FF
jg 0xbd16c
testq %rax, %rax
je 0xbd16c
movq 0x18(%r14), %rdi
movq 0xc8(%rbx), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0xefabc
movq 0x28(%rbx), %rdx
movq 0xc8(%rbx), %rsi
movq %r14, %rdi
callq 0x1053ee
movq 0x28(%rbx), %rax
cmpq $0x1b, 0x30(%rax)
jg 0xbd0ec
movq $0x1c, 0x30(%rax)
movq 0x10(%rax), %rcx
cmpq 0xa8(%rbx), %rcx
jne 0xbd16c
movq 0x18(%rax), %rcx
cmpq 0xb0(%rbx), %rcx
jne 0xbd16c
movq 0x20(%rax), %rcx
cmpq 0xb8(%rbx), %rcx
jne 0xbd16c
movq 0x28(%rax), %rcx
cmpq 0xc0(%rbx), %rcx
jne 0xbd16c
movq 0xd0(%rbx), %rcx
movq 0x18(%rcx), %rcx
leaq 0x3(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x2, %rdx
movb $0x1, %r12b
cmpq %rdx, 0x8(%rax)
jne 0xbd16f
movq 0x48(%rax), %rdx
subq 0x38(%rax), %rdx
movq 0xd8(%rbx), %rax
movq 0x18(%rax), %rcx
movl $0x2, %ebp
cmpq %rdx, %rcx
jne 0xbd3f2
xorl %r13d, %r13d
jmp 0xbd418
movb $0x1, %r12b
leaq 0x7b2ee(%rip), %rax     # 0x138464
movslq (%rax,%rbp,4), %rdx
addq %rax, %rdx
leaq 0x7ba75(%rip), %rsi     # 0x138bf9
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9226
testb %r13b, %r13b
je 0xbd1a4
leaq 0x7ba74(%rip), %rsi     # 0x138c0e
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9b27
testb %r12b, %r12b
je 0xbd3e3
movq 0xc8(%rbx), %rdi
movl $0x2, %esi
callq 0xf152a
movq 0xc8(%rbx), %rax
cmpq $0x2, 0x18(%rax)
jne 0xbd3e0
cmpq $0x0, 0xa0(%rbx)
je 0xbd3e0
movq 0x18(%r14), %rdi
movl $0xa, %esi
callq 0xef1ca
movq %rax, %r12
movq 0x18(%r14), %rdi
movl $0xc, %esi
callq 0xef1ca
testq %rax, %rax
movl $0xffff, %r15d          # imm = 0xFFFF
cmovneq %rax, %r15
cmpb $0x0, 0x6(%rbx)
jne 0xbd26f
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
movq 0x18(%r14), %rdi
callq 0xef14d
cmpb $0x50, %al
jne 0xbd23b
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef14d
cmpb $-0x48, %al
jne 0xbd26f
movq 0x18(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef1ed
shlq $0x4, %rax
movq 0xd8(%rbx), %rcx
subq 0x18(%rcx), %rax
addq $0x100, %rax            # imm = 0x100
js 0xbd26f
addq $0xf, %rax
shrq $0x4, %rax
movq %rax, %r12
movq %r12, 0x10(%rsp)
cmpq %r12, %r15
cmovleq %r12, %r15
movq %r15, (%rsp)
movq 0xd0(%rbx), %rax
movq 0x18(%rax), %rax
leaq 0x3(%rax), %rdi
testq %rax, %rax
cmovnsq %rax, %rdi
movq %rdi, %r13
sarq $0x2, %r13
andq $-0x4, %rdi
addq $0x1c, %rdi
movslq 0xc(%rbx), %rsi
callq 0xea80b
movq %rax, %rbp
movq 0xc8(%rbx), %rdi
movq 0xd8(%rbx), %rax
movq 0x18(%rax), %r12
movq %r12, %rsi
addq %rbp, %rsi
leaq 0x1ff(%r12,%rbp), %r15
movq %rsi, %rax
cmovsq %r15, %rax
andq $-0x200, %rax           # imm = 0xFE00
subq %rax, %rsi
callq 0xf1598
movq 0xc8(%rbx), %rdi
leaq (%r12,%rbp), %rsi
addq $0x3fe, %rsi            # imm = 0x3FE
testq %r15, %r15
cmovnsq %r15, %rsi
sarq $0x9, %rsi
callq 0xf1598
movq 0xc8(%rbx), %rdi
movq %r13, %rsi
callq 0xf1598
movq 0xc8(%rbx), %rdi
leaq 0xf(%rbp), %rsi
testq %rbp, %rbp
cmovnsq %rbp, %rsi
sarq $0x4, %rsi
callq 0xf1598
movq 0xc8(%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0xf1598
movq 0xc8(%rbx), %rdi
movq (%rsp), %rsi
callq 0xf1598
movq 0xa8(%rbx), %rsi
movq 0xc8(%rbx), %rdi
callq 0xf15cc
movq 0xb0(%rbx), %rsi
movq 0xc8(%rbx), %rdi
callq 0xf1598
movq 0xc8(%rbx), %rdi
xorl %esi, %esi
callq 0xf1598
movq 0xc0(%rbx), %rsi
movq 0xc8(%rbx), %rdi
callq 0xf1598
movq 0xb8(%rbx), %rsi
movq 0xc8(%rbx), %rdi
callq 0xf15cc
movq 0xc8(%rbx), %rdi
movl $0x1c, %esi
callq 0xf1598
movq 0xc8(%rbx), %rdi
xorl %esi, %esi
callq 0xf1598
movq 0x28(%rbx), %rdx
movq 0xc8(%rbx), %rsi
movq %r14, %rdi
callq 0x1053ee
jmp 0xbd3e3
movb $0x1, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7b772(%rip), %rax     # 0x138b6b
leaq 0x877d0(%rip), %r8      # 0x144bd0
cmovlq %rax, %r8
leaq 0x7b7bb(%rip), %rsi     # 0x138bc6
xorl %r13d, %r13d
movq %r14, %rdi
xorl %eax, %eax
callq 0xe9b27
xorl %r12d, %r12d
jmp 0xbd16f