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

	read_exe_testbytes(ei);
	if(de_memcmp(ei->ovl64b, "FBIN", 4)) goto done;
	n = de_getu32le_direct(&ei->ovl64b[4]);

	pos = ei->end_of_dos_code + 8 + n;
	if(pos+40 > ei->f->len) goto done;
	if(dbuf_memcmp(ei->f, pos, "FBEX", 4)) goto done;
	pos += 4;
	edd->payload_len = dbuf_getu32le_p(ei->f, &pos);
	edd->payload_pos = pos;
	if(edd->payload_len<32) goto done;
	if(edd->payload_pos+edd->payload_len > ei->f->len) goto done;
	// If there's other stuff after this item, fail completely instead
	// of partially.
	if(edd->payload_pos+edd->payload_len+32 < ei->f->len) goto done;
	if(dbuf_memcmp(ei->f, edd->payload_pos, "MZ", 2)) goto done;

	edd->payload_valid = 1;
	edd->detected_fmt = DE_SPECIALEXEFMT_SFX;
	edd->payload_file_ext = "exe";

done:
	if(edd->detected_fmt==DE_SPECIALEXEFMT_SFX) {
		de_strlcpy(edd->detected_fmt_name, "FBEX overlay",
			sizeof(edd->detected_fmt_name));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x189f70
movq -0x10(%rbp), %rax
addq $0xb0, %rax
movl (%rax), %eax
subl $0x4e494246, %eax       # imm = 0x4E494246
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x18b0ce
jmp 0x18b205
movq -0x10(%rbp), %rdi
addq $0xb0, %rdi
addq $0x4, %rdi
callq 0x165500
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
addq $0x8, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
addq $0x28, %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x18b114
jmp 0x18b205
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
leaq 0x4ca58(%rip), %rdx     # 0x1d7b7e
movl $0x4, %ecx
callq 0x166ab0
cmpl $0x0, %eax
je 0x18b13a
jmp 0x18b205
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
cmpq $0x20, 0x18(%rax)
jge 0x18b17d
jmp 0x18b205
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x18b19c
jmp 0x18b205
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
addq $0x20, %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x18b1bf
jmp 0x18b205
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
leaq 0x4c9ae(%rip), %rdx     # 0x1d7b83
movl $0x2, %ecx
callq 0x166ab0
cmpl $0x0, %eax
je 0x18b1e6
jmp 0x18b205
movq -0x18(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x18(%rbp), %rax
movb $0x64, 0x1(%rax)
movq -0x18(%rbp), %rax
leaq 0x24065(%rip), %rcx     # 0x1af266
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x64, %eax
jne 0x18b22b
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
leaq 0x4c965(%rip), %rsi     # 0x1d7b86
movl $0x28, %edx
callq 0x15aa30
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)