// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/exe.c
// Function: do_lx_or_le_ext_header
static void do_lx_or_le_ext_header(deark *c, lctx *d, i64 pos)
{
	i64 x1, x2;

	de_dbg(c, "%s header at %"I64_FMT, d->fmt==EXE_FMT_LE?"LE":"LX", pos);
	x1 = (u8)de_getbyte(pos+2);
	x2 = (u8)de_getbyte(pos+3);
	de_dbg(c, "byte order, word order: %d, %d", (int)x1, (int)x2);
	if(x1!=0 || x2!=0) {
		de_err(c, "Unsupported byte order.");
		return;
	}

	if(d->fmt==EXE_FMT_LE) {
		x1 = de_getu32le(pos+0x2c);
		de_dbg(c, "bytes on last page: %d", (int)x1);
	}
	else {
		d->lx_page_offset_shift = de_getu32le(pos+0x2c);
		de_dbg(c, "page offset shift: %d", (int)d->lx_page_offset_shift);
	}

	x1 = de_getu32le(pos+0x40);
	d->lx_object_tbl_offset = pos + x1;
	d->lx_object_tbl_entries = de_getu32le(pos+0x44);
	de_dbg(c, "object table offset=%"I64_FMT", entries=%d", d->lx_object_tbl_offset,
		(int)d->lx_object_tbl_entries);

	x1 = de_getu32le(pos+0x48);
	d->lx_object_page_tbl_offset = pos + x1;
	de_dbg(c, "object page table offset=%"I64_FMT, d->lx_object_page_tbl_offset);

	x1 = de_getu32le(pos+0x50);
	d->lx_rsrc_tbl_offset = pos + x1;
	d->lx_rsrc_tbl_entries = de_getu32le(pos+0x54);
	de_dbg(c, "resource table offset=%"I64_FMT" entries=%d", d->lx_rsrc_tbl_offset,
		(int)d->lx_rsrc_tbl_entries);

	d->lx_data_pages_offset = de_getu32le(pos+0x80);
	de_dbg(c, "data pages offset=%"I64_FMT, d->lx_data_pages_offset);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x6, (%rsi)
leaq 0xcaf4b(%rip), %rax     # 0x10fa85
leaq 0xcad9c(%rip), %rdx     # 0x10f8dd
cmoveq %rax, %rdx
leaq 0xcb332(%rip), %rsi     # 0x10fe7e
movq %r15, %rcx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xe3eb4
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq 0x3(%r15), %rsi
callq 0xe3eb4
movzbl %bpl, %ebp
movzbl %al, %r12d
leaq 0xcb30e(%rip), %rsi     # 0x10fe8f
movq %rbx, %rdi
movl %ebp, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xde896
orb %bpl, %r12b
je 0x44bae
leaq 0xcb312(%rip), %rsi     # 0x10feae
movq %rbx, %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xdf2a5
movb (%r14), %bpl
movq 0x18(%rbx), %rdi
leaq 0x2c(%r15), %rsi
callq 0xe409f
cmpb $0x6, %bpl
jne 0x44bcd
leaq 0xcb2fb(%rip), %rsi     # 0x10fec6
jmp 0x44bdb
movq %rax, 0x98(%r14)
leaq 0xcb302(%rip), %rsi     # 0x10fedd
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x40(%r15), %rsi
callq 0xe409f
addq %r15, %rax
movq %rax, 0xa0(%r14)
movq 0x18(%rbx), %rdi
leaq 0x44(%r15), %rsi
callq 0xe409f
movq %rax, 0xa8(%r14)
movq 0xa0(%r14), %rdx
leaq 0xcb2d3(%rip), %rsi     # 0x10fef3
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x48(%r15), %rsi
callq 0xe409f
leaq (%rax,%r15), %rdx
movq %rdx, 0xb0(%r14)
leaq 0xcb2cc(%rip), %rsi     # 0x10ff17
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0x50(%r15), %rsi
callq 0xe409f
addq %r15, %rax
movq %rax, 0xb8(%r14)
movq 0x18(%rbx), %rdi
leaq 0x54(%r15), %rsi
callq 0xe409f
movq %rax, 0xc0(%r14)
movq 0xb8(%r14), %rdx
leaq 0xcb2a6(%rip), %rsi     # 0x10ff34
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
subq $-0x80, %r15
movq %r15, %rsi
callq 0xe409f
movq %rax, 0xc8(%r14)
leaq 0xcb2a1(%rip), %rsi     # 0x10ff59
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xde896