// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
callq 0x165280
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
andq $0x7ff, %rax            # imm = 0x7FF
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movl $0x6, %esi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x165280
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
shlq $0x4, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rdi
movl $0xe, %esi
callq 0x165360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movl $0x10, %esi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movl $0x14, %esi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rdi
movl $0x16, %esi
callq 0x165360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
movl $0x18, %esi
callq 0x165280
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x20(%rax), %rcx
shlq $0x4, %rcx
movq -0x18(%rbp), %rax
addq 0x28(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x10(%rbp), %rdi
movl $0x3c, %esi
callq 0x165540
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rcx
shlq $0x9, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
cmpq $0x1, -0x28(%rbp)
jl 0x188aa7
cmpq $0x1ff, -0x28(%rbp)     # imm = 0x1FF
jg 0x188aa7
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
subq $0x200, %rcx            # imm = 0x200
addq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
subq 0x48(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jge 0x188ad6
movq -0x18(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x188af0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)