// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x34(%rsi), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
xorl %esi, %esi
callq 0x3130
movabsq $0x6e776f6e6b6e55, %rbp # imm = 0x6E776F6E6B6E55
movq %rbp, 0x34(%rbx)
leaq 0x234(%rbx), %r12
movl $0x200, %edx            # imm = 0x200
movq %r12, %rdi
xorl %esi, %esi
callq 0x3130
movq %rbp, 0x234(%rbx)
leaq 0x434(%rbx), %r15
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x3130
movq %rbp, 0x434(%rbx)
movq %rsp, %rdi
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
movq %r13, %rcx
callq 0x32e0
cmpq $0x40, %rax
jb 0xd765
movzwl 0x1(%rsp), %eax
xorl $0x4953, %eax           # imm = 0x4953
movzbl 0x3(%rsp), %ecx
xorl $0x44, %ecx
orw %ax, %cx
je 0xd793
movabsq $0x434953554d444554, %rax # imm = 0x434953554D444554
cmpq %rax, 0x11(%rsp)
je 0xd7e1
movl $0x384d4243, %eax       # imm = 0x384D4243
xorl (%rsp), %eax
movzbl 0x4(%rsp), %ecx
xorl $0x4d, %ecx
orl %eax, %ecx
je 0xd87d
leaq 0x658(%rbx), %rdi
movq 0x660(%rbx), %rdx
leaq 0x32e7(%rip), %rcx      # 0x10a61
movl $0x3, %r8d
xorl %esi, %esi
callq 0x3300
movzwl (%rsp), %eax
movl %eax, 0x2c(%rbx)
jmp 0xd8bc
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xccf8
movzwl 0x8(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x2c(%rbx)
testw %ax, %ax
jne 0xd7bd
movzwl 0x7c(%rsp), %eax
movl %eax, 0x2c(%rbx)
leaq 0x658(%rbx), %rdi
cmpb $0x50, (%rsp)
movq 0x660(%rbx), %rdx
jne 0xd867
leaq 0x318a(%rip), %rcx      # 0x10966
jmp 0xd86e
leaq 0x658(%rbx), %rdi
movq 0x660(%rbx), %rdx
leaq 0x317a(%rip), %rcx      # 0x10970
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 0xccb5
movq %r14, %rdi
movq %r13, %rsi
callq 0xd8e6
leaq 0x61(%rsp), %rbx
movq %rbx, %rdi
movl $0x20, %esi
callq 0xccb5
movq %r12, %rdi
movq %rbx, %rsi
callq 0xd8e6
leaq 0x81(%rsp), %rbx
movq %rbx, %rdi
movl $0x20, %esi
callq 0xccb5
movq %r15, %rdi
movq %rbx, %rsi
callq 0xd8e6
jmp 0xd8bc
leaq 0x30fd(%rip), %rcx      # 0x1096b
movl $0x4, %r8d
xorl %esi, %esi
callq 0x3300
jmp 0xd8bc
leaq 0x108(%rsp), %rdi
callq 0x3df0
movq 0x660(%rbx), %rdx
addq $0x658, %rbx            # imm = 0x658
leaq 0x188f(%rip), %rcx      # 0xf12e
movl $0x5, %r8d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3300
leaq 0x108(%rsp), %rdi
callq 0x3e0a
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x3e0a
movq %rbx, %rdi
callq 0x3360