// File: /workspace/github_c_makefile_star2_O3/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 0xd5ec7(%rip), %rax     # 0x11cb75
leaq 0xd5d18(%rip), %rdx     # 0x11c9cd
cmoveq %rax, %rdx
leaq 0xd62ae(%rip), %rsi     # 0x11cf6e
movq %r15, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xeead3
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq 0x3(%r15), %rsi
callq 0xeead3
movzbl %bpl, %ebp
movzbl %al, %r12d
leaq 0xd628a(%rip), %rsi     # 0x11cf7f
movq %rbx, %rdi
movl %ebp, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe8617
orb %bpl, %r12b
je 0x46d22
leaq 0xd628e(%rip), %rsi     # 0x11cf9e
movq %rbx, %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xe9295
movb (%r14), %bpl
movq 0x18(%rbx), %rdi
leaq 0x2c(%r15), %rsi
callq 0xeed61
cmpb $0x6, %bpl
jne 0x46d41
leaq 0xd6277(%rip), %rsi     # 0x11cfb6
jmp 0x46d4f
movq %rax, 0x98(%r14)
leaq 0xd627e(%rip), %rsi     # 0x11cfcd
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x40(%r15), %rsi
callq 0xeed61
addq %r15, %rax
movq %rax, 0xa0(%r14)
movq 0x18(%rbx), %rdi
leaq 0x44(%r15), %rsi
callq 0xeed61
movq %rax, 0xa8(%r14)
movq 0xa0(%r14), %rdx
leaq 0xd624f(%rip), %rsi     # 0x11cfe3
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x48(%r15), %rsi
callq 0xeed61
leaq (%rax,%r15), %rdx
movq %rdx, 0xb0(%r14)
leaq 0xd6248(%rip), %rsi     # 0x11d007
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x50(%r15), %rsi
callq 0xeed61
addq %r15, %rax
movq %rax, 0xb8(%r14)
movq 0x18(%rbx), %rdi
leaq 0x54(%r15), %rsi
callq 0xeed61
movq %rax, 0xc0(%r14)
movq 0xb8(%r14), %rdx
leaq 0xd6222(%rip), %rsi     # 0x11d024
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
subq $-0x80, %r15
movq %r15, %rsi
callq 0xeed61
movq %rax, 0xc8(%r14)
leaq 0xd621d(%rip), %rsi     # 0x11d049
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xe8617