// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-exe.c
// Function: check_for_ext_fmt
static void check_for_ext_fmt(deark *c, struct fmtutil_exe_info *ei,
	i64 maybe_ext_hdr_pos)
{
	i64 reloc_tbl_endpos;
	i64 n;

	if(maybe_ext_hdr_pos<64 || maybe_ext_hdr_pos>=ei->f->len) {
		goto done;
	}
	if(ei->start_of_dos_code<=60 && ei->end_of_dos_code>60) {
		goto done;
	}
	if(ei->reloc_table_pos>=61 && ei->reloc_table_pos<=63) {
		goto done;
	}
	reloc_tbl_endpos = ei->reloc_table_pos + 4*ei->num_relocs;
	if(ei->num_relocs>0 && ei->reloc_table_pos<64 && reloc_tbl_endpos>60) {
		goto done;
	}

	n = dbuf_getu32be(ei->f, maybe_ext_hdr_pos);
	if(n==0x50450000U) {
		ei->is_extended = 1;
		ei->is_pe = 1;
	}
	else if((n&0xffff0000)==0x4e450000) {
		ei->is_extended = 1;
		ei->is_ne = 1;
	}
	else if((n&0xffff0000)==0x4c580000 || // LX
		(n&0xffff0000)==0x4c450000) // LE
	{
		ei->is_extended = 1;
	}

	if(ei->is_extended) {
		ei->ext_hdr_pos = maybe_ext_hdr_pos;

		if(ei->is_pe) {
			check_for_pe_dll(c, ei);
		}
		else if(ei->is_ne) {
			check_for_ne_dll(c, ei);
		}
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x40, -0x18(%rbp)
jl 0x188b1c
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x188b21
jmp 0x188c70
movq -0x10(%rbp), %rax
cmpq $0x3c, 0x38(%rax)
jg 0x188b3c
movq -0x10(%rbp), %rax
cmpq $0x3c, 0x48(%rax)
jle 0x188b3c
jmp 0x188c70
movq -0x10(%rbp), %rax
cmpq $0x3d, 0x30(%rax)
jl 0x188b57
movq -0x10(%rbp), %rax
cmpq $0x3f, 0x30(%rax)
jg 0x188b57
jmp 0x188c70
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jle 0x188b94
movq -0x10(%rbp), %rax
cmpq $0x40, 0x30(%rax)
jge 0x188b94
cmpq $0x3c, -0x20(%rbp)
jle 0x188b94
jmp 0x188c70
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165470
movq %rax, -0x28(%rbp)
cmpq $0x50450000, -0x28(%rbp) # imm = 0x50450000
jne 0x188bc4
movq -0x10(%rbp), %rax
movb $0x1, 0x60(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x62(%rax)
jmp 0x188c24
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq -0x28(%rbp), %rax
cmpq $0x4e450000, %rax       # imm = 0x4E450000
jne 0x188bec
movq -0x10(%rbp), %rax
movb $0x1, 0x60(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x61(%rax)
jmp 0x188c22
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq -0x28(%rbp), %rax
cmpq $0x4c580000, %rax       # imm = 0x4C580000
je 0x188c18
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq -0x28(%rbp), %rax
cmpq $0x4c450000, %rax       # imm = 0x4C450000
jne 0x188c20
movq -0x10(%rbp), %rax
movb $0x1, 0x60(%rax)
jmp 0x188c22
jmp 0x188c24
movq -0x10(%rbp), %rax
cmpb $0x0, 0x60(%rax)
je 0x188c6e
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x62(%rax)
je 0x188c53
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x189ed0
jmp 0x188c6c
movq -0x10(%rbp), %rax
cmpb $0x0, 0x61(%rax)
je 0x188c6a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x189f20
jmp 0x188c6c
jmp 0x188c6e
jmp 0x188c70
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)