// File: /workspace/github_c_makefile_star2_O3/calmopyrin[P]tedplay/tedplay.cpp
// Function: tedPlayGetInfo(void*, PsidHeader&)
void tedPlayGetInfo(void *file, PsidHeader &hdr)
{
	unsigned char buf[256];
	FILE *fp = reinterpret_cast<FILE *>(file);

	memset(hdr.title, 0, sizeof(hdr.title));
	strcpy(hdr.title, "Unknown");
	memset(hdr.author, 0, sizeof(hdr.author));
	strcpy(hdr.author, "Unknown");
	memset(hdr.copyright, 0, sizeof(hdr.copyright));
	strcpy(hdr.copyright, "Unknown");

	if (fread(buf, 1, 256, fp) >= 64) {
		if (!strncmp((const char*)buf + 1, "SID", 3)) {
			parsePsid(buf, hdr);
			hdr.loadAddress = buf[PSID_START + 1] + (buf[PSID_START] << 8);
			if (!hdr.loadAddress)
				hdr.loadAddress = buf[PSID_MAX_HEADER_LENGTH] + (buf[PSID_MAX_HEADER_LENGTH + 1] << 8);
			if (buf[0] == 'P') {
				hdr.typeName = "PSID";
			}
			else {
				hdr.typeName = "RSID";
			}
			return;
		}
		else if (!strncmp((const char*)buf + 17, "TEDMUSIC", 8)) {
			hdr.typeName = "TMF";
			hdr.loadAddress = buf[28] + (buf[29] << 8);
			copyPetsciiToAsc(hdr.title, trimTrailingSpace((char*)buf + 65, 32), 32);
			copyPetsciiToAsc(hdr.author, trimTrailingSpace((char*)buf + 97, 32), 32);
			copyPetsciiToAsc(hdr.copyright, trimTrailingSpace((char*)buf + 129, 32), 32);
			return;
		}
		else if (!strncmp((const char*)buf, "CBM8M", 5)) {
			CbmTune tune;
			//tune.parse(
			hdr.typeName = "CBM8M";
			return;
		}
	}
	hdr.typeName = "PRG";
	hdr.loadAddress = buf[0] + (buf[1] << 8);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x3c(%rsi), %rdi
movl $0x1f8, %edx            # imm = 0x1F8
xorl %esi, %esi
callq 0x3130
movabsq $0x6e776f6e6b6e55, %r15 # imm = 0x6E776F6E6B6E55
movq %r15, 0x34(%rbx)
leaq 0x23c(%rbx), %rdi
movl $0x1f8, %edx            # imm = 0x1F8
xorl %esi, %esi
callq 0x3130
movq %r15, 0x234(%rbx)
leaq 0x43c(%rbx), %rdi
movl $0x1f8, %edx            # imm = 0x1F8
xorl %esi, %esi
callq 0x3130
movq %r15, 0x434(%rbx)
movq %rsp, %rdi
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
movq %r14, %rcx
callq 0x32e0
cmpq $0x40, %rax
jb 0xdc43
movzwl 0x1(%rsp), %eax
xorl $0x4953, %eax           # imm = 0x4953
movzbl 0x3(%rsp), %ecx
xorl $0x44, %ecx
orw %ax, %cx
je 0xdc71
movabsq $0x434953554d444554, %rax # imm = 0x434953554D444554
cmpq %rax, 0x11(%rsp)
je 0xdcbf
movl $0x384d4243, %eax       # imm = 0x384D4243
xorl (%rsp), %eax
movzbl 0x4(%rsp), %ecx
xorl $0x4d, %ecx
orl %eax, %ecx
je 0xdd6d
leaq 0x658(%rbx), %rdi
movq 0x660(%rbx), %rdx
leaq 0x3031(%rip), %rcx      # 0x10c89
movl $0x3, %r8d
xorl %esi, %esi
callq 0x3300
movzwl (%rsp), %eax
movl %eax, 0x2c(%rbx)
jmp 0xddac
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd1e8
movzwl 0x8(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x2c(%rbx)
testw %ax, %ax
jne 0xdc9b
movzwl 0x7c(%rsp), %eax
movl %eax, 0x2c(%rbx)
leaq 0x658(%rbx), %rdi
cmpb $0x50, (%rsp)
movq 0x660(%rbx), %rdx
jne 0xdd57
leaq 0x2ed4(%rip), %rcx      # 0x10b8e
jmp 0xdd5e
leaq 0x34(%rbx), %r12
leaq 0x234(%rbx), %r15
leaq 0x434(%rbx), %r14
leaq 0x658(%rbx), %rdi
movq 0x660(%rbx), %rdx
leaq 0x2eb2(%rip), %rcx      # 0x10b98
movl $0x3, %r8d
xorl %esi, %esi
callq 0x3300
leaq 0x41(%rsp), %r13
movzwl -0x25(%r13), %eax
movl %eax, 0x2c(%rbx)
movq %r13, %rdi
movl $0x20, %esi
callq 0xd1a5
movq %r12, %rdi
movq %r13, %rsi
callq 0xddd5
leaq 0x61(%rsp), %rbx
movq %rbx, %rdi
movl $0x20, %esi
callq 0xd1a5
movq %r15, %rdi
movq %rbx, %rsi
callq 0xddd5
leaq 0x81(%rsp), %rbx
movq %rbx, %rdi
movl $0x20, %esi
callq 0xd1a5
movq %r14, %rdi
movq %rbx, %rsi
callq 0xddd5
jmp 0xddac
leaq 0x2e35(%rip), %rcx      # 0x10b93
movl $0x4, %r8d
xorl %esi, %esi
callq 0x3300
jmp 0xddac
leaq 0x100(%rsp), %rdi
callq 0x3dc4
movq 0x660(%rbx), %rdx
addq $0x658, %rbx            # imm = 0x658
leaq 0x139f(%rip), %rcx      # 0xf12e
movl $0x5, %r8d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3300
leaq 0x100(%rsp), %rdi
callq 0x3dde
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x3dde
movq %rbx, %rdi
callq 0x3360