// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/src/fmtutil-exe.c
// Function: fmtutil_collect_exe_info
void fmtutil_collect_exe_info(deark *c, dbuf *f, struct fmtutil_exe_info *ei)
{
	i64 hdrsize; // in 16-byte units
	i64 lfb, nblocks;
	i64 maybe_ext_hdr_pos;

	ei->f = f;
	lfb = dbuf_getu16le(f, 2);
	nblocks = dbuf_getu16le(f, 4);
	nblocks &= 0x7ff;
	ei->num_relocs = dbuf_getu16le(f, 6);
	hdrsize = dbuf_getu16le(f, 8);
	ei->start_of_dos_code = hdrsize*16;
	ei->regSS = dbuf_geti16le(f, 14);
	ei->regSP = dbuf_getu16le(f, 16);
	ei->regIP = dbuf_getu16le(f, 20);
	ei->regCS = dbuf_geti16le(f, 22);
	ei->reloc_table_pos = dbuf_getu16le(f, 24);
	ei->entry_point = (hdrsize + ei->regCS)*16 + ei->regIP;
	maybe_ext_hdr_pos = dbuf_getu32le(f, 60);

	ei->end_of_dos_code = nblocks*512;
	if(lfb>=1 && lfb<=511) {
		ei->end_of_dos_code = ei->end_of_dos_code - 512 + lfb;
	}
	ei->overlay_len = f->len - ei->end_of_dos_code;
	if(ei->overlay_len<0) ei->overlay_len = 0;

	check_for_ext_fmt(c, ei, maybe_ext_hdr_pos);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r15
movq %rsi, (%rdx)
movl $0x2, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, %r12
movl $0x4, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, %r13
movl $0x6, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, 0x8(%rbx)
movl $0x8, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, %r14
shlq $0x4, %rax
movq %rax, 0x38(%rbx)
movl $0xe, %esi
movq %r15, %rdi
callq 0xef257
movq %rax, 0x10(%rbx)
movl $0x10, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, 0x18(%rbx)
movl $0x14, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, 0x28(%rbx)
movl $0x16, %esi
movq %r15, %rdi
callq 0xef257
movq %rax, 0x20(%rbx)
movl $0x18, %esi
movq %r15, %rdi
callq 0xef1ca
movq %rax, 0x30(%rbx)
addq 0x20(%rbx), %r14
shlq $0x4, %r14
addq 0x28(%rbx), %r14
movq %r14, 0x40(%rbx)
movl $0x3c, %esi
movq %r15, %rdi
callq 0xef37e
movq %rax, %r14
shll $0x9, %r13d
andl $0xffe00, %r13d         # imm = 0xFFE00
leaq -0x1(%r12), %rax
cmpq $0x1ff, %rax            # imm = 0x1FF
leaq -0x200(%r13,%r12), %rax
cmovaeq %r13, %rax
movq %rax, 0x48(%rbx)
movq 0x18(%r15), %rcx
subq %rax, %rcx
xorl %edx, %edx
testq %rcx, %rcx
cmovgq %rcx, %rdx
movq %rdx, 0x50(%rbx)
cmpq $0x40, %r14
jl 0x1055d1
movq (%rbx), %rdi
cmpq %r14, 0x18(%rdi)
jle 0x1055d1
cmpq $0x3c, 0x38(%rbx)
jg 0x105520
cmpq $0x3c, %rax
jg 0x1055d1
movq 0x30(%rbx), %rax
leaq -0x3d(%rax), %rcx
cmpq $0x3, %rcx
jb 0x1055d1
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
jle 0x10554f
cmpq $0x3f, %rax
jg 0x10554f
leaq (%rax,%rcx,4), %rax
cmpq $0x3c, %rax
jg 0x1055d1
movq %r14, %rsi
callq 0xef32a
cmpq $0x50450000, %rax       # imm = 0x50450000
jne 0x105569
movb $0x1, %al
movb %al, 0x60(%rbx)
movb %al, 0x62(%rbx)
jmp 0x10558f
andl $0xffff0000, %eax       # imm = 0xFFFF0000
cmpl $0x4c450000, %eax       # imm = 0x4C450000
je 0x10558b
cmpl $0x4c580000, %eax       # imm = 0x4C580000
je 0x10558b
cmpl $0x4e450000, %eax       # imm = 0x4E450000
jne 0x10558f
movw $0x101, 0x60(%rbx)      # imm = 0x101
jmp 0x10558f
movb $0x1, 0x60(%rbx)
cmpb $0x0, 0x60(%rbx)
je 0x1055d1
movq %r14, 0x58(%rbx)
cmpb $0x0, 0x62(%rbx)
je 0x1055b4
movq (%rbx), %rdi
addq $0x17, %r14
movq %r14, %rsi
callq 0xef0d5
testb $0x20, %al
jne 0x1055cd
jmp 0x1055d1
cmpb $0x0, 0x61(%rbx)
je 0x1055d1
movq (%rbx), %rdi
addq $0xd, %r14
movq %r14, %rsi
callq 0xef0d5
testb %al, %al
jns 0x1055d1
movb $0x1, 0x63(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq