// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
addq $0x34, %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x3130
movq -0x10(%rbp), %rdi
addq $0x34, %rdi
leaq 0x3ce6(%rip), %rsi      # 0x1fcf7
callq 0x3230
movq -0x10(%rbp), %rdi
addq $0x234, %rdi            # imm = 0x234
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x3130
movq -0x10(%rbp), %rdi
addq $0x234, %rdi            # imm = 0x234
leaq 0x3cb8(%rip), %rsi      # 0x1fcf7
callq 0x3230
movq -0x10(%rbp), %rdi
addq $0x434, %rdi            # imm = 0x434
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x3130
movq -0x10(%rbp), %rdi
addq $0x434, %rdi            # imm = 0x434
leaq 0x3c8a(%rip), %rsi      # 0x1fcf7
callq 0x3230
leaq -0x110(%rbp), %rdi
movq -0x118(%rbp), %rcx
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x33a0
cmpq $0x40, %rax
jb 0x1c2cd
leaq -0x110(%rbp), %rdi
addq $0x1, %rdi
leaq 0x3b5b(%rip), %rsi      # 0x1fc06
movl $0x3, %edx
callq 0x3110
cmpl $0x0, %eax
jne 0x1c14d
leaq -0x110(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1b020
movzbl -0x107(%rbp), %ecx
movzbl -0x108(%rbp), %eax
shll $0x8, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jne 0x1c10c
movzbl -0x94(%rbp), %ecx
movzbl -0x93(%rbp), %eax
shll $0x8, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movzbl -0x110(%rbp), %eax
cmpl $0x50, %eax
jne 0x1c131
movq -0x10(%rbp), %rdi
addq $0x658, %rdi            # imm = 0x658
leaq 0x3adb(%rip), %rsi      # 0x1fc05
callq 0x3340
jmp 0x1c148
movq -0x10(%rbp), %rdi
addq $0x658, %rdi            # imm = 0x658
leaq 0x3ac7(%rip), %rsi      # 0x1fc0a
callq 0x3340
jmp 0x1c2fe
leaq -0x110(%rbp), %rdi
addq $0x11, %rdi
leaq 0x3ba0(%rip), %rsi      # 0x1fcff
movl $0x8, %edx
callq 0x3110
cmpl $0x0, %eax
jne 0x1c257
movq -0x10(%rbp), %rdi
addq $0x658, %rdi            # imm = 0x658
leaq 0x3a8b(%rip), %rsi      # 0x1fc0f
callq 0x3340
movzbl -0xf4(%rbp), %ecx
movzbl -0xf3(%rbp), %eax
shll $0x8, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x10(%rbp), %rax
addq $0x34, %rax
movq %rax, -0x180(%rbp)
leaq -0x110(%rbp), %rdi
addq $0x41, %rdi
movl $0x20, %esi
callq 0x1af80
movq -0x180(%rbp), %rdi
movq %rax, %rsi
movl $0x20, %edx
callq 0x1c320
movq -0x10(%rbp), %rax
addq $0x234, %rax            # imm = 0x234
movq %rax, -0x178(%rbp)
leaq -0x110(%rbp), %rdi
addq $0x61, %rdi
movl $0x20, %esi
callq 0x1af80
movq -0x178(%rbp), %rdi
movq %rax, %rsi
movl $0x20, %edx
callq 0x1c320
movq -0x10(%rbp), %rax
addq $0x434, %rax            # imm = 0x434
movq %rax, -0x170(%rbp)
leaq -0x110(%rbp), %rdi
addq $0x81, %rdi
movl $0x20, %esi
callq 0x1af80
movq -0x170(%rbp), %rdi
movq %rax, %rsi
movl $0x20, %edx
callq 0x1c320
jmp 0x1c2fe
leaq -0x110(%rbp), %rdi
leaq 0x1ec9(%rip), %rsi      # 0x1e12e
movl $0x5, %edx
callq 0x3110
cmpl $0x0, %eax
jne 0x1c2c7
leaq -0x158(%rbp), %rdi
callq 0x4450
movq -0x10(%rbp), %rdi
addq $0x658, %rdi            # imm = 0x658
leaq 0x1e9c(%rip), %rsi      # 0x1e12e
callq 0x3340
jmp 0x1c299
leaq -0x158(%rbp), %rdi
callq 0x4490
jmp 0x1c2fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x4490
jmp 0x1c307
jmp 0x1c2c9
jmp 0x1c2cb
jmp 0x1c2cd
movq -0x10(%rbp), %rdi
addq $0x658, %rdi            # imm = 0x658
leaq 0x3a29(%rip), %rsi      # 0x1fd08
callq 0x3340
movzbl -0x110(%rbp), %ecx
movzbl -0x10f(%rbp), %eax
shll $0x8, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x160(%rbp), %rdi
callq 0x3410
nopw %cs:(%rax,%rax)