// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/fmtutil-exe.c
// Function: detect_exesfx_lha
static void detect_exesfx_lha(deark *c,
	struct fmtutil_exe_info *ei, struct fmtutil_specialexe_detection_data *edd)
{
	u8 b[8];
	u8 x;
	int found;
	i64 foundpos = 0;
	i64 pos;
	i64 j;

	if(ei->regSS != -16) goto done;
	if(ei->regSP != 256) goto done;
	if(ei->regCS != -16) goto done;
	if(ei->regIP != 256) goto done;

	pos = 32;
	x = dbuf_getbyte_p(ei->f, &pos);
	if(x==0xeb) {
		j = (i64)dbuf_getbyte_p(ei->f, &pos);
	}
	else if(x==0xe9) {
		j = dbuf_getu16le_p(ei->f, &pos);
	}
	else {
		goto done;
	}
	pos += j;

	if((u32)dbuf_getu32be_p(ei->f, &pos) != (u32)0xfcbc0001U) {
		goto done;
	}

	dbuf_read(ei->f, b, pos, sizeof(b));
	if(de_memmatch(b, (const u8*)"\xbb?\x01\xe8??\x8c\xc8", 8, '?', 0)) {
		;
	}
	else if(de_memmatch(b, (const u8*)"\x8c\xc8\x05?\x00\x8e\xc0", 7, '?', 0)) {
		;
	}
	else {
		goto done;
	}

	found =
		is_lha_data_at(ei, ei->end_of_dos_code, &foundpos) ||
		is_lha_data_at(ei, ei->end_of_dos_code+1, &foundpos) ||
		is_lha_data_at(ei, ei->end_of_dos_code+3, &foundpos) ||
		is_lha_data_at(ei, ei->entry_point + 1292-32, &foundpos) ||
		is_lha_data_at(ei, ei->entry_point + 1295-32, &foundpos) ||
		is_lha_data_at(ei, ei->entry_point + 1322-32, &foundpos);
	if(!found) goto done;

	edd->payload_pos = foundpos;
	edd->payload_len = ei->f->len - edd->payload_pos;
	if(edd->payload_len<21) goto done;

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $-0x10, 0x10(%rax)
je 0x18a6ac
jmp 0x18a937
movq -0x10(%rbp), %rax
cmpq $0x100, 0x18(%rax)      # imm = 0x100
je 0x18a6bf
jmp 0x18a937
movq -0x10(%rbp), %rax
cmpq $-0x10, 0x20(%rax)
je 0x18a6cf
jmp 0x18a937
movq -0x10(%rbp), %rax
cmpq $0x100, 0x28(%rax)      # imm = 0x100
je 0x18a6e2
jmp 0x18a937
movq $0x20, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165170
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0xeb, %eax
jne 0x18a721
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165170
movzbl %al, %eax
movq %rax, -0x40(%rbp)
jmp 0x18a749
movzbl -0x21(%rbp), %eax
cmpl $0xe9, %eax
jne 0x18a742
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x40(%rbp)
jmp 0x18a747
jmp 0x18a937
jmp 0x18a749
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1654b0
cmpl $0xfcbc0001, %eax       # imm = 0xFCBC0001
je 0x18a771
jmp 0x18a937
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq -0x20(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x8, %ecx
callq 0x164d10
leaq -0x20(%rbp), %rdi
leaq 0x4d3b3(%rip), %rsi     # 0x1d7b48
movl $0x8, %edx
movl $0x3f, %ecx
xorl %r8d, %r8d
callq 0x15f6b0
cmpl $0x0, %eax
je 0x18a7ae
jmp 0x18a7d9
leaq -0x20(%rbp), %rdi
leaq 0x4d43d(%rip), %rsi     # 0x1d7bf6
movl $0x7, %edx
movl $0x3f, %ecx
xorl %r8d, %r8d
callq 0x15f6b0
cmpl $0x0, %eax
je 0x18a7d2
jmp 0x18a7d7
jmp 0x18a937
jmp 0x18a7d9
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x18b240
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
jne 0x18a8d1
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
addq $0x1, %rsi
leaq -0x30(%rbp), %rdx
callq 0x18b240
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
jne 0x18a8d1
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
addq $0x3, %rsi
leaq -0x30(%rbp), %rdx
callq 0x18b240
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
jne 0x18a8d1
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
addq $0x50c, %rsi            # imm = 0x50C
subq $0x20, %rsi
leaq -0x30(%rbp), %rdx
callq 0x18b240
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
jne 0x18a8d1
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
addq $0x50f, %rsi            # imm = 0x50F
subq $0x20, %rsi
leaq -0x30(%rbp), %rdx
callq 0x18b240
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x41(%rbp)
jne 0x18a8d1
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rsi
addq $0x52a, %rsi            # imm = 0x52A
subq $0x20, %rsi
leaq -0x30(%rbp), %rdx
callq 0x18b240
cmpl $0x0, %eax
setne %al
movb %al, -0x41(%rbp)
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x18a8e4
jmp 0x18a937
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
subq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
cmpq $0x15, 0x18(%rax)
jge 0x18a918
jmp 0x18a937
movq -0x18(%rbp), %rax
movb $0x64, 0x1(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x3(%rax)
movq -0x18(%rbp), %rax
leaq 0x4626f(%rip), %rcx     # 0x1d0ba2
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x64, %eax
jne 0x18a95d
movq -0x18(%rbp), %rdi
addq $0x50, %rdi
leaq 0x2ce89(%rip), %rsi     # 0x1b77dc
movl $0x28, %edx
callq 0x15aa30
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)