// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movl $0xf0, %esi
callq 0xe8b2b
movq %rax, 0x28(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %rax, 0xc8(%r14)
movl $0x5a4d, %esi           # imm = 0x5A4D
movq %rax, %rdi
callq 0xf0f95
cmpb $0x0, 0x18(%r14)
je 0xbc373
leaq 0x5d96a(%rip), %rdx     # 0x119cdb
jmp 0xbc39b
movq 0x20(%r14), %rax
movq 0x8(%rax), %r15
movq 0x38(%rax), %r13
shlq $0x2, %r15
addq 0x30(%rax), %r15
subq %r15, %r13
cmpq $0x1a, %r13
jge 0xbc5ef
leaq 0x7c98b(%rip), %rdx     # 0x138d26
leaq 0x7c98c(%rip), %rsi     # 0x138d2e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0xc8(%r14), %rdi
movl $0x2, %esi
callq 0xf0f27
movq 0xc8(%r14), %rax
cmpq $0x2, 0x18(%rax)
jne 0xbc5dc
cmpq $0x0, 0xa0(%r14)
je 0xbc5dc
movq 0x18(%rbx), %rdi
movl $0xa, %esi
callq 0xeebc8
movq %rax, %r12
movq 0x18(%rbx), %rdi
movl $0xc, %esi
callq 0xeebc8
testq %rax, %rax
movl $0xffff, %r15d          # imm = 0xFFFF
cmovneq %rax, %r15
cmpb $0x0, 0x6(%r14)
jne 0xbc469
movq 0x20(%r14), %rax
movq 0x40(%rax), %rax
movq %rsp, %rsi
movq %rax, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeeb4b
cmpb $0x50, %al
jne 0xbc437
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xeeb4b
cmpb $-0x48, %al
jne 0xbc469
movq 0x18(%rbx), %rdi
movq %rsp, %rsi
callq 0xeebeb
shlq $0x4, %rax
movq 0xd8(%r14), %rcx
subq 0x18(%rcx), %rax
addq $0x100, %rax            # imm = 0x100
js 0xbc469
addq $0xf, %rax
shrq $0x4, %rax
movq %rax, %r12
movq %r12, 0x8(%rsp)
cmpq %r12, %r15
cmovleq %r12, %r15
movq %r15, 0x10(%rsp)
movq 0xd0(%r14), %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(%r14), %rsi
callq 0xe9cb4
movq %rax, %rbp
movq 0xc8(%r14), %rdi
movq 0xd8(%r14), %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 0xf0f95
movq 0xc8(%r14), %rdi
leaq (%r12,%rbp), %rsi
addq $0x3fe, %rsi            # imm = 0x3FE
testq %r15, %r15
cmovnsq %r15, %rsi
sarq $0x9, %rsi
callq 0xf0f95
movq 0xc8(%r14), %rdi
movq %r13, %rsi
callq 0xf0f95
movq 0xc8(%r14), %rdi
leaq 0xf(%rbp), %rsi
testq %rbp, %rbp
cmovnsq %rbp, %rsi
sarq $0x4, %rsi
callq 0xf0f95
movq 0xc8(%r14), %rdi
movq 0x8(%rsp), %rsi
callq 0xf0f95
movq 0xc8(%r14), %rdi
movq 0x10(%rsp), %rsi
callq 0xf0f95
movq 0xa8(%r14), %rsi
movq 0xc8(%r14), %rdi
callq 0xf0fc9
movq 0xb0(%r14), %rsi
movq 0xc8(%r14), %rdi
callq 0xf0f95
movq 0xc8(%r14), %rdi
xorl %esi, %esi
callq 0xf0f95
movq 0xc0(%r14), %rsi
movq 0xc8(%r14), %rdi
callq 0xf0f95
movq 0xb8(%r14), %rsi
movq 0xc8(%r14), %rdi
callq 0xf0fc9
movq 0xc8(%r14), %rdi
movl $0x1c, %esi
callq 0xf0f95
movq 0xc8(%r14), %rdi
xorl %esi, %esi
callq 0xf0f95
movq 0x28(%r14), %rdx
movq 0xc8(%r14), %rsi
movq %rbx, %rdi
callq 0x104f96
jmp 0xbc5e0
movb $0x1, (%r14)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
leaq 0x16(%r15), %rsi
callq 0xeebc8
leaq 0x2(%r13), %rcx
leaq -0x2(%rax), %r12
cmpq %rcx, %rax
cmovgeq %r13, %r12
cmpq $0x1c, %rax
cmovlq %r13, %r12
leaq 0x7c667(%rip), %rsi     # 0x138c81
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebc8
movq %rax, %r13
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xeebc8
cmpq $0x1ff, %r13            # imm = 0x1FF
jg 0xbc75d
testq %rax, %rax
je 0xbc75d
movq 0x18(%rbx), %rdi
movq 0xc8(%r14), %rcx
movq %r15, %rsi
movq %r12, %rdx
callq 0xef481
movq 0x28(%r14), %rdx
movq 0xc8(%r14), %rsi
movq %rbx, %rdi
callq 0x104f96
movq 0x28(%r14), %rax
cmpq $0x1b, 0x30(%rax)
jg 0xbc698
movq $0x1c, 0x30(%rax)
movq 0x10(%rax), %rcx
cmpq 0xa8(%r14), %rcx
jne 0xbc75d
movq 0x18(%rax), %rcx
cmpq 0xb0(%r14), %rcx
jne 0xbc75d
movq 0x20(%rax), %rcx
cmpq 0xb8(%r14), %rcx
jne 0xbc75d
movq 0x28(%rax), %rcx
cmpq 0xc0(%r14), %rcx
jne 0xbc75d
movq 0xd0(%r14), %rcx
movq 0x18(%rcx), %rcx
leaq 0x3(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x2, %rdx
cmpq %rdx, 0x8(%rax)
jne 0xbc75d
movq 0x48(%rax), %rdx
subq 0x38(%rax), %rdx
movq 0xd8(%r14), %rax
movq 0x18(%rax), %rcx
cmpq %rdx, %rcx
je 0xbc737
leaq 0x7c585(%rip), %rax     # 0x138ca0
leaq 0x8898e(%rip), %r8      # 0x1450b0
cmovlq %rax, %r8
leaq 0x7c5ce(%rip), %rsi     # 0x138cfb
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
leaq 0x7c5f0(%rip), %rsi     # 0x138d2e
leaq 0x616ef(%rip), %rdx     # 0x11de34
movq %rbx, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8617
leaq 0x7c5ca(%rip), %rsi     # 0x138d2e
leaq 0x73fc8(%rip), %rdx     # 0x130733
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
leaq 0x7c5c7(%rip), %rsi     # 0x138d43
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
jmp 0xbc3ac