// File: /workspace/github_c_makefile_star2_O1/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 0xd5e16(%rip), %rax     # 0x11ca65
leaq 0xd5c67(%rip), %rdx     # 0x11c8bd
cmoveq %rax, %rdx
leaq 0xd61fd(%rip), %rsi     # 0x11ce5e
movq %r15, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x2(%r15), %rsi
callq 0xef0d5
movl %eax, %ebp
movq 0x18(%rbx), %rdi
leaq 0x3(%r15), %rsi
callq 0xef0d5
movzbl %bpl, %ebp
movzbl %al, %r12d
leaq 0xd61d9(%rip), %rsi     # 0x11ce6f
movq %rbx, %rdi
movl %ebp, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe9226
orb %bpl, %r12b
je 0x46cc3
leaq 0xd61dd(%rip), %rsi     # 0x11ce8e
movq %rbx, %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xe9df7
movb (%r14), %bpl
movq 0x18(%rbx), %rdi
leaq 0x2c(%r15), %rsi
callq 0xef37e
cmpb $0x6, %bpl
jne 0x46ce2
leaq 0xd61c6(%rip), %rsi     # 0x11cea6
jmp 0x46cf0
movq %rax, 0x98(%r14)
leaq 0xd61cd(%rip), %rsi     # 0x11cebd
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x40(%r15), %rsi
callq 0xef37e
addq %r15, %rax
movq %rax, 0xa0(%r14)
movq 0x18(%rbx), %rdi
leaq 0x44(%r15), %rsi
callq 0xef37e
movq %rax, 0xa8(%r14)
movq 0xa0(%r14), %rdx
leaq 0xd619e(%rip), %rsi     # 0x11ced3
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x48(%r15), %rsi
callq 0xef37e
leaq (%rax,%r15), %rdx
movq %rdx, 0xb0(%r14)
leaq 0xd6197(%rip), %rsi     # 0x11cef7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x50(%r15), %rsi
callq 0xef37e
addq %r15, %rax
movq %rax, 0xb8(%r14)
movq 0x18(%rbx), %rdi
leaq 0x54(%r15), %rsi
callq 0xef37e
movq %rax, 0xc0(%r14)
movq 0xb8(%r14), %rdx
leaq 0xd6171(%rip), %rsi     # 0x11cf14
movq %rbx, %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
subq $-0x80, %r15
movq %r15, %rsi
callq 0xef37e
movq %rax, 0xc8(%r14)
leaq 0xd616c(%rip), %rsi     # 0x11cf39
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xe9226