// File: ksherlock[P]wdc-utils/afp/src/finder_info.cpp
// Function: (anonymous namespace)::finder_info_to_filetype(unsigned char const*, unsigned short*, unsigned int*)
bool finder_info_to_filetype(const uint8_t *buffer, uint16_t *file_type, uint32_t *aux_type) {

		if (!memcmp("pdos", buffer + 4, 4))
		{
			if (buffer[0] == 'p') {
				*file_type = buffer[1];
				*aux_type = (buffer[2] << 8) | buffer[3];
				return true;
			}
			if (!memcmp("PSYS", buffer, 4)) {
				*file_type = 0xff;
				*aux_type = 0x0000;
				return true;
			}
			if (!memcmp("PS16", buffer, 4)) {
				*file_type = 0xb3;
				*aux_type = 0x0000;
				return true;
			}

			// old mpw method for encoding.
			if (!isxdigit(buffer[0]) && isxdigit(buffer[1]) && buffer[2] == ' ' && buffer[3] == ' ')
			{
				*file_type = (hex(buffer[0]) << 8) | hex(buffer[1]);
				*aux_type = 0;
				return true;
			}
		}
		if (!memcmp("TEXT", buffer, 4)) {
			*file_type = 0x04;
			*aux_type = 0x0000;
			return true;
		}
		if (!memcmp("BINA", buffer, 4)) {
			*file_type = 0x00;
			*aux_type = 0x0000;
			return true;
		}
		if (!memcmp("dImgdCpy", buffer, 8)) {
			*file_type = 0xe0;
			*aux_type = 0x0005;
			return true;
		}

		if (!memcmp("MIDI", buffer, 4)) {
			*file_type = 0xd7;
			*aux_type = 0x0000;
			return true;
		}

		if (!memcmp("AIFF", buffer, 4)) {
			*file_type = 0xd8;
			*aux_type = 0x0000;
			return true;
		}

		if (!memcmp("AIFC", buffer, 4)) {
			*file_type = 0xd8;
			*aux_type = 0x0001;
			return true;
		}

		return false;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movl (%rax), %eax
subl $0x736f6470, %eax       # imm = 0x736F6470
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2958a
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x70, %eax
jne 0x294a4
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %ecx
shll $0x8, %ecx
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
orl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x53595350, %eax       # imm = 0x53595350
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x294d6
movq -0x18(%rbp), %rax
movw $0xff, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x36315350, %eax       # imm = 0x36315350
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x29508
movq -0x18(%rbp), %rax
movw $0xb3, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movzbl (%rax), %edi
callq 0x3620
cmpl $0x0, %eax
jne 0x29588
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %edi
callq 0x3620
cmpl $0x0, %eax
je 0x29588
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x20, %eax
jne 0x29588
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
cmpl $0x20, %eax
jne 0x29588
movq -0x10(%rbp), %rax
movzbl (%rax), %edi
callq 0x29dd0
shll $0x8, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %edi
callq 0x29dd0
movl %eax, %ecx
movl -0x24(%rbp), %eax
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
jmp 0x2958a
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x54584554, %eax       # imm = 0x54584554
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x295bc
movq -0x18(%rbp), %rax
movw $0x4, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x414e4942, %eax       # imm = 0x414E4942
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x295ee
movq -0x18(%rbp), %rax
movw $0x0, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movq (%rax), %rax
movabsq $0x79704364676d4964, %rcx # imm = 0x79704364676D4964
subq %rcx, %rax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x29629
movq -0x18(%rbp), %rax
movw $0xe0, (%rax)
movq -0x20(%rbp), %rax
movl $0x5, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x4944494d, %eax       # imm = 0x4944494D
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x29658
movq -0x18(%rbp), %rax
movw $0xd7, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x46464941, %eax       # imm = 0x46464941
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x29687
movq -0x18(%rbp), %rax
movw $0xd8, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x43464941, %eax       # imm = 0x43464941
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x296b6
movq -0x18(%rbp), %rax
movw $0xd8, (%rax)
movq -0x20(%rbp), %rax
movl $0x1, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0x296ba
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)