// File: /workspace/github_c_makefile_star2_O1/calmopyrin[P]tedplay/tedplay.cpp
// Function: tedplayMain(char*, Audio*)
int tedplayMain(char *fileName, Audio *player_)
{
	size_t bufLength;
	unsigned char *buf = 0;

	if (!player) {
		player = player_;
		if (!player)
			return 1;
	}

	if (!readFile(fileName, &buf, &bufLength)) {

		tedplayPause();
		machineReset();
		tedplayPlay();
		// if we do not flush the buffer, the reset may not get executed
		player->flush();
		// let it run so that the reset sequence can finish
		player->sleep(150);
		tedplayStop();

		psidHdr.fileName = fileName;

		if (!strncmp((const char *) buf + 1, "SID", 3) || !strncmp((const char *) buf + 1, "TED", 3)) {
			psidHdr.loadAddress = buf[PSID_START + 1] + (buf[PSID_START] << 8);
			unsigned int corr = 0;
			// zero load address means PRG module
			if (!psidHdr.loadAddress) {
				psidHdr.loadAddress = buf[PSID_MAX_HEADER_LENGTH] + (buf[PSID_MAX_HEADER_LENGTH + 1] << 8);
				corr = 2;
			}
			unsigned short initAddr = buf[PSID_INIT + 1] + (buf[PSID_INIT] << 8);
			unsigned short replayAddr = buf[PSID_MAIN + 1] + (buf[PSID_MAIN] << 8);
			// zero init address means equal to load address
			psidHdr.initAddress = initAddr ? initAddr : psidHdr.loadAddress;
			// 0 means an IRQ handler will be installed in the init routine
			// (most likely nothing happens)
			psidHdr.replayAddress = replayAddr ? replayAddr : 0xfe33;
			psidHdr.defaultTune = readPsid16(buf, PSID_DEFSONG);
			psidHdr.current = psidHdr.defaultTune;
			psidHdr.version = readPsid16(buf, PSID_VERSION);
			psidHdr.tracks = readPsid16(buf, PSID_NUMBER);
			psidHdr.speed = readPsid32(buf, PSID_SPEED);
			parsePsid(buf, psidHdr);

			// setup the SID card
			SIDsound *sid = ted->getSidCard();
			if (sid) {
				// Disable the ROM & IRQ's, so almost the entire memory is RAM
				// more SID's are likely to play
				ted->cpuptr->setST(ted->cpuptr->getST() | 4);
				ted->ChangeMemBankSetup(true);
				// v2 SID files have flags
				if (psidHdr.version == 2 && (readPsid16(buf, PSID_FLAGS) & 0x20)) {
					if (sidModelSelect != SID6581 + 1)
						sid->setModel(SID8580);
					else
						sid->setModel(SID6581);
					strcpy(psidHdr.model, "SID8580");
				} else {
					if (sidModelSelect != SID8580 + 1)
						sid->setModel(SID6581);
					else
						sid->setModel(SID8580);
					strcpy(psidHdr.model, "SID6581");
				}
			} else {
				strcpy(psidHdr.model, "TED8360?");
			}
			if (buf[0] == 'P') { // PSID/PTED
				psidHdr.type = 0;
#ifdef NEWPLAYER
				psidPlayer[0x22] = psidHdr.defaultTune - 1;
				psidPlayer[0x5b] = psidHdr.initAddress & 0xff;
				psidPlayer[0x5c] = psidHdr.initAddress >> 8;
				if (psidHdr.replayAddress) {
					psidPlayer[0xb1] = psidHdr.replayAddress & 0xff;
					psidPlayer[0xb2] = psidHdr.replayAddress >> 8;
				}
				psidPlayer[0xA3] = psidHdr.speed & 0xFF;
				psidPlayer[0xA4] = (psidHdr.speed >> 8) & 0xFF;
				psidPlayer[0xA5] = (psidHdr.speed >> 16) & 0xFF;
				psidPlayer[0xA6] = (psidHdr.speed >> 24) & 0xFF;
#else
				ted->Write(0xFF0A, 0x00); // no IRQ allowed
				ted->Write(0xFF09, ted->Read(0xFF09)); // ack IRQ
#if 1
				tmfPlayer[1] = psidHdr.defaultTune - 1;
				tmfPlayer[3] = psidHdr.initAddress & 0xff;
				tmfPlayer[4] = psidHdr.initAddress >> 8;
				tmfPlayer[6] = 0x00;
				// 60 Hz or Vblank based - we use timers anyway
				unsigned short timer = (TED_SOUND_CLOCK * 4) / (psidHdr.speed & (1 << tmfPlayer[1]) ? 60 : 50);
				tmfPlayer[11] = timer & 0xFF;
				tmfPlayer[16] = timer >> 8;
				tmfPlayer[32] = psidHdr.replayAddress & 0xff;
				tmfPlayer[33] = psidHdr.replayAddress >> 8;

				ted->writeProtectedPlayerMemory(playerStartAddress, tmfPlayer, sizeof(tmfPlayer));
#else
				psidPlayer[1] = psidHdr.defaultTune - 1;
				psidPlayer[3] = psidHdr.initAddress & 0xff;
				psidPlayer[4] = psidHdr.initAddress >> 8;
				psidPlayer[22] = psidHdr.replayAddress & 0xff;
				psidPlayer[23] = psidHdr.replayAddress >> 8;
				ted->writeProtectedPlayerMemory(playerStartAddress, psidPlayer, sizeof(psidPlayer));
#endif
#endif
			} else if (buf[0] == 'R') { // RSID/RTED
				ted->Write(0xFF13, 0xD3); // slow mode to match C64 frequency better
				psidHdr.type = 1;
				rsidPlayer[1] = psidHdr.defaultTune - 1;
				rsidPlayer[3] = psidHdr.initAddress & 0xff;
				rsidPlayer[4] = psidHdr.initAddress >> 8;
				if (replayAddr != 0) {
					rsidPlayer[5] = 0x4C; // JMP
					rsidPlayer[6] = psidHdr.replayAddress & 0xff;
					rsidPlayer[7] = psidHdr.replayAddress >> 8;
				} else {
					rsidPlayer[5] = 0x18; // CLC
					rsidPlayer[6] = 0x90; // BCC *-2
					rsidPlayer[7] = 0xfe;
				}
				ted->writeProtectedPlayerMemory(playerStartAddress, rsidPlayer, sizeof(rsidPlayer));
			}
			ted->injectCodeToRAM(psidHdr.loadAddress, buf + PSID_MAX_HEADER_LENGTH + corr,
				bufLength - PSID_MAX_HEADER_LENGTH - corr);
		}
		else if (!strncmp((const char*)buf + 17, "TEDMUSIC", 8)) {
			// specs http://siz.hu/en/tedmusiccollection
			psidHdr.type = 3;
			psidHdr.version = buf[25];
			psidHdr.tracks = buf[34];
			psidHdr.defaultTune = psidHdr.current = 1;
			psidHdr.replayAddress = playerStartAddress;
			memset(psidHdr.title, 0, sizeof(psidHdr.title));
			memset(psidHdr.author, 0, sizeof(psidHdr.author));
			memset(psidHdr.copyright, 0, sizeof(psidHdr.copyright));
			copyPetsciiToAsc(psidHdr.title, (char*)buf + 65, 32);
			trimTrailingSpace(psidHdr.title, 32);
			copyPetsciiToAsc(psidHdr.author, (char*)buf + 97, 32);
			trimTrailingSpace(psidHdr.author, 32);
			copyPetsciiToAsc(psidHdr.copyright, (char*)buf + 129, 32);
			trimTrailingSpace(psidHdr.copyright, 32);
			psidHdr.loadAddress = buf[0] + (buf[1] << 8);
			psidHdr.initAddress = buf[30] + (buf[31] << 8);
			psidHdr.replayAddress = buf[32] + (buf[33] << 8);
			// The offset where song data starts from the beginning of the file (load address included)
			unsigned int musicDataOffset = buf[26] + (buf[27] << 8);
			// Memory address where the real music data should be loaded (in case of BASIC load this is the address where the music should be relocated to)
			unsigned int relocatedAddress = buf[28] + (buf[29] << 8);
			// Music data size
			size_t musicDataSize = bufLength - musicDataOffset;
			// Timing
			unsigned char timingLo = buf[36];
			unsigned char timingHi = buf[37];

			tmfPlayer[1] = psidHdr.defaultTune - 1;
			tmfPlayer[3] = psidHdr.initAddress & 0xff;
			tmfPlayer[4] = psidHdr.initAddress >> 8;
			tmfPlayer[6] = (buf[38] & 1) ? 0x00 : 0x1B;
			// timer based timing? FIXME: PAL only
			if (buf[35] >= 2 && buf[35] < 6) {
				tmfPlayer[11] = timingLo;
				tmfPlayer[16] = timingHi;
			}
			// Vblank based - we use timers anyway
			else {
				unsigned int frameRate = (buf[35] == 1 || buf[35] == 7) ? 60 : 50;
				unsigned short timer = (TED_SOUND_CLOCK * 4) / frameRate;
				// doubleSpeed?
				if (buf[35] >= 6)
					timer /= 2;
				tmfPlayer[11] = timer & 0xFF;
				tmfPlayer[16] = timer >> 8;
			}
			tmfPlayer[32] = psidHdr.replayAddress & 0xff;
			tmfPlayer[33] = psidHdr.replayAddress >> 8;

			// if offset is illegal fall back to normal load
			if (int(musicDataSize) - 257 < 0) {
				ted->injectCodeToRAM(psidHdr.loadAddress, buf + 2, bufLength - 2);
			}
			else {
				psidHdr.loadAddress = relocatedAddress;
				ted->injectCodeToRAM(relocatedAddress, buf + musicDataOffset, musicDataSize);
			}
			ted->writeProtectedPlayerMemory(playerStartAddress, tmfPlayer, sizeof(tmfPlayer));

			strcpy(psidHdr.model, "TED8360");
			if (buf[38] & 2) {
				SIDsound* sid = ted->getSidCard();
				if (sid) {
					if (sidModelSelect != SID6581 + 1)
						sid->setModel(SID8580);
					else
						sid->setModel(SID6581);
				}
			}

		} else if (!strncmp((const char *) buf, "CBM8M", 5)) {
			CbmTune tune;
			tune.parse(fileName);
			psidHdr.type = 2;
			strcpy(psidHdr.title, tune.getName());
			strcpy(psidHdr.author, tune.getAuthor());
			strcpy(psidHdr.copyright, tune.getReleaseDate());
			unsigned int dataLen = tune.getDumpLength(0);
			psidHdr.loadAddress = tune.getLoadAddress(0);
			unsigned short initAddr = tune.getInitAddress(0);
			unsigned short replayAddr = tune.getPlayAddress(0);
			unsigned char *playerData;
			unsigned int playerLength;
			psidHdr.version = 1;
			psidHdr.tracks = tune.getNrOfSubtunes() + 1;
			psidHdr.defaultTune = tune.getDefaultSubtune() + 1;
			psidHdr.current = psidHdr.defaultTune;
			psidHdr.initAddress = initAddr;
			psidHdr.replayAddress = replayAddr;
			if (replayAddr) {
				psidPlayer[1] = psidHdr.defaultTune;
				psidPlayer[3] = psidHdr.loadAddress & 0xff;
				psidPlayer[4] = psidHdr.loadAddress >> 8;
				psidPlayer[22] = psidHdr.replayAddress & 0xff;
				psidPlayer[23] = psidHdr.replayAddress >> 8;
				playerLength = 33;
				playerData = psidPlayer;
			} else {
				rsidPlayer[1] = psidHdr.defaultTune;
				rsidPlayer[2] = 0x4C; // JMP
				rsidPlayer[3] = psidHdr.loadAddress & 0xff;
				rsidPlayer[4] = psidHdr.loadAddress >> 8;
				playerLength = 8;
				playerData = rsidPlayer;
			}
			strcpy(psidHdr.model, "TED8360");

			ted->injectCodeToRAM(psidHdr.loadAddress, tune.getBinaryData(0), dataLen - 2);
			ted->writeProtectedPlayerMemory(playerStartAddress, playerData, playerLength);
		} else { // PRG
			psidHdr.type = -1;
			psidHdr.version = 0;
			psidHdr.tracks = psidHdr.defaultTune = 1;
			psidHdr.current = 1;
			psidHdr.replayAddress = playerStartAddress;
			strcpy(psidHdr.title, fileName);
			strcpy(psidHdr.author, "Unknown");
			strcpy(psidHdr.copyright, "Unknown");
			strcpy(psidHdr.model, "Unknown");
			psidHdr.loadAddress = buf[0] + (buf[1] << 8);

			ted->injectCodeToRAM(psidHdr.loadAddress, buf + 2, bufLength - 2);
			ted->writeProtectedPlayerMemory(playerStartAddress, prgPlayer, sizeof(prgPlayer));
			SIDsound *sid = ted->getSidCard();
			if (sid) {
				if (sidModelSelect != SID6581 + 1)
					sid->setModel(SID8580);
				else
					sid->setModel(SID6581);
			}
		}
#if 1
		cpu->setPC(playerStartAddress);
#else
		char start[64];
		ted->copyToKbBuffer("M\317:\r");
		player->sleep(200);
		sprintf(start, "G%04X\r", playerStartAddress);
		ted->copyToKbBuffer(start);
#endif
		try {
			tedplayPlay();
		} catch (char *txt) {
			std::cerr << "Exception: " << txt << std::endl;
			exit(2);
		}
#if 0 //_DEBUG
		//Sleep(3000);
		if (fileName) {
			std::string fn = fileName;
			fn += ".bin";
			dumpMem(fn);
		}
#endif
		return 0;
	}
	if (fileName) {
		std::cerr << "Error opening: " << fileName << std::endl;
		return 1;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %r14
movq $0x0, 0x8(%rsp)
cmpq $0x0, 0x284a3(%rip)     # 0x35df8
jne 0xd963
movq %rsi, 0x2849a(%rip)     # 0x35df8
testq %rsi, %rsi
je 0xd9d8
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0xd0f9
testl %eax, %eax
je 0xd9e2
testq %r14, %r14
je 0xe0fc
movq 0x6669(%rip), %rbx      # 0x13ff0
leaq 0x30f0(%rip), %rsi      # 0x10a7e
movl $0xf, %edx
movq %rbx, %rdi
callq 0x3260
movq %r14, %rdi
callq 0x30f0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3260
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3200
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3050
movq %rax, %rdi
callq 0x3150
movl $0x1, %eax
jmp 0xe0fe
callq 0xd4ce
movq 0x183f2(%rip), %rdi     # 0x25de0
callq 0x9cae
movq 0x283f6(%rip), %rdi     # 0x35df0
callq 0x4416
callq 0xd506
movq 0x283ed(%rip), %rdi     # 0x35df8
movq (%rdi), %rax
callq *0x30(%rax)
movq 0x283e0(%rip), %rdi     # 0x35df8
movq (%rdi), %rax
movl $0x96, %esi
callq *0x28(%rax)
callq 0xd553
movq 0x17d21(%rip), %rbx     # 0x25750
leaq 0x17d12(%rip), %r15     # 0x25748
movq %r14, %rdi
callq 0x30f0
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x3300
movq 0x8(%rsp), %rbx
leaq 0x1(%rbx), %r15
leaq 0x2f06(%rip), %rsi      # 0x10967
movl $0x3, %edx
movq %r15, %rdi
callq 0x3100
testl %eax, %eax
je 0xdb84
leaq 0x2fe8(%rip), %rsi      # 0x10a65
movl $0x3, %edx
movq %r15, %rdi
callq 0x3100
testl %eax, %eax
je 0xdb84
leaq 0x11(%rbx), %rdi
leaq 0x2fbb(%rip), %rsi      # 0x10a58
movl $0x8, %edx
callq 0x3100
testl %eax, %eax
je 0xdcbf
leaq 0x1678(%rip), %rsi      # 0xf12e
movl $0x5, %edx
movq %rbx, %rdi
callq 0x3100
testl %eax, %eax
je 0xdf76
movl $0xffffffff, 0x182c7(%rip) # imm = 0xFFFFFFFF
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x182da(%rip)     # 0x25dc0
movl $0x1, %eax
movl %eax, 0x17c87(%rip)     # 0x25778
movl %eax, 0x17c71(%rip)     # 0x25768
movl $0xfe00, 0x17c6f(%rip)  # imm = 0xFE00
leaq 0x17c74(%rip), %rdi     # 0x2577c
movq %r14, %rsi
callq 0x31e0
movabsq $0x6e776f6e6b6e55, %rax # imm = 0x6E776F6E6B6E55
movq %rax, 0x17e5b(%rip)     # 0x2597c
movq %rax, 0x18054(%rip)     # 0x25b7c
movq %rax, 0x1824d(%rip)     # 0x25d7c
movzwl (%rbx), %esi
movl %esi, 0x17c3c(%rip)     # 0x25774
movq 0x182a1(%rip), %rdi     # 0x25de0
addq $0x2, %rbx
movq (%rsp), %rcx
addq $-0x2, %rcx
movq %rbx, %rdx
callq 0xa0ce
xorl %eax, %eax
movq 0x18284(%rip), %rcx     # 0x25de0
leaq 0x2f55(%rip), %rdx      # 0x10ab8
movb (%rax,%rdx), %sil
movb %sil, 0xb6fb8(%rcx,%rax)
incq %rax
cmpq $0x6, %rax
jne 0xdb63
movq 0xb71d0(%rcx), %rdi
jmp 0xe1d0
movzwl 0x8(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x17bdf(%rip)     # 0x25774
testw %ax, %ax
je 0xdb9f
xorl %r15d, %r15d
jmp 0xdbaf
movzwl 0x7c(%rbx), %eax
movl %eax, 0x17bcb(%rip)     # 0x25774
movl $0x2, %r15d
movzwl 0xa(%rbx), %eax
movzwl 0xc(%rbx), %ebp
rolw $0x8, %ax
rolw $0x8, %bp
leaq 0x17b82(%rip), %rsi     # 0x25748
testw %ax, %ax
jne 0xdbd3
movl 0x17ba3(%rip), %eax     # 0x25774
jmp 0xdbd6
movzwl %ax, %eax
movl %eax, 0x17b90(%rip)     # 0x2576c
testw %bp, %bp
movl $0xfe33, %eax           # imm = 0xFE33
cmovnel %ebp, %eax
movzwl %ax, %eax
movl %eax, 0x17b80(%rip)     # 0x25770
movzwl 0x10(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x17b77(%rip)     # 0x25778
movl %eax, 0x181bd(%rip)     # 0x25dc4
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x181a8(%rip)     # 0x25dc0
movzwl 0xe(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x17b3f(%rip)     # 0x25768
movl 0x12(%rbx), %eax
bswapl %eax
movl %eax, 0x181a4(%rip)     # 0x25dd8
movq %rbx, %rdi
callq 0xccf8
movq 0x1819d(%rip), %rdi     # 0x25de0
movq 0xb71d0(%rdi), %r14
testq %r14, %r14
je 0xdca2
movq 0x45fb8(%rdi), %rax
movzbl 0x18(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x18(%rax)
movl $0x1, %esi
callq 0x9cd0
cmpl $0x2, 0x1814f(%rip)     # 0x25dc0
jne 0xdc7d
testb $0x20, 0x77(%rbx)
jne 0xde13
xorl %esi, %esi
cmpl $0x2, 0x18162(%rip)     # 0x25de8
sete %sil
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
movabsq $0x31383536444953, %rax # imm = 0x31383536444953
jmp 0xde33
movabsq $0x3f30363338444554, %rax # imm = 0x3F30363338444554
movq %rax, 0x180c9(%rip)     # 0x25d7c
movb $0x0, 0x180ca(%rip)     # 0x25d84
jmp 0xde3a
movl $0x3, 0x180d3(%rip)     # 0x25d9c
movzbl 0x19(%rbx), %eax
movl %eax, 0x180ed(%rip)     # 0x25dc0
movzbl 0x22(%rbx), %eax
movl %eax, 0x17a8b(%rip)     # 0x25768
movl $0x1, %eax
movl %eax, 0x180dc(%rip)     # 0x25dc4
movl %eax, 0x17a8a(%rip)     # 0x25778
movl $0xfe00, 0x17a78(%rip)  # imm = 0xFE00
leaq 0x41(%rbx), %r14
leaq 0x17a79(%rip), %r15     # 0x2577c
xorl %ebp, %ebp
movl $0x600, %edx            # imm = 0x600
movq %r15, %rdi
xorl %esi, %esi
callq 0x3130
movq %r15, %rdi
movq %r14, %rsi
callq 0xd8e6
movq %r15, %rdi
movl $0x20, %esi
callq 0xccb5
leaq 0x61(%rbx), %rsi
leaq 0x17c45(%rip), %r14     # 0x2597c
movq %r14, %rdi
callq 0xd8e6
movq %r14, %rdi
movl $0x20, %esi
callq 0xccb5
leaq 0x81(%rbx), %rsi
leaq 0x17e22(%rip), %r14     # 0x25b7c
movq %r14, %rdi
callq 0xd8e6
movq %r14, %rdi
movl $0x20, %esi
callq 0xccb5
movzwl (%rbx), %esi
movl %esi, 0x179fc(%rip)     # 0x25774
movzbl 0x1e(%rbx), %r14d
movzbl 0x1f(%rbx), %r15d
movl %r15d, %eax
shll $0x8, %eax
orl %r14d, %eax
movl %eax, 0x179db(%rip)     # 0x2576c
movzbl 0x20(%rbx), %edi
movzbl 0x21(%rbx), %r10d
movl %r10d, %eax
shll $0x8, %eax
orl %edi, %eax
movl %eax, 0x179c8(%rip)     # 0x25770
movzwl 0x1a(%rbx), %edx
movzwl 0x1c(%rbx), %r8d
movq (%rsp), %rax
movq %rax, %r9
subq %rdx, %r9
movb 0x24(%rbx), %cl
movb 0x25(%rbx), %r11b
movb 0x179af(%rip), %r12b    # 0x25778
decb %r12b
movb %r12b, 0x1646e(%rip)    # 0x24241
movb %r14b, 0x16469(%rip)    # 0x24243
movb %r15b, 0x16463(%rip)    # 0x24244
testb $0x1, 0x26(%rbx)
movl $0x1b, %r14d
cmovnel %ebp, %r14d
movb %r14b, 0x16450(%rip)    # 0x24246
movb 0x23(%rbx), %r14b
leal -0x2(%r14), %ebp
cmpb $0x3, %bpl
ja 0xe10b
movb %cl, 0x1643d(%rip)      # 0x2424b
jmp 0xe13b
xorl %esi, %esi
cmpl $0x1, 0x17fcc(%rip)     # 0x25de8
setne %sil
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
movabsq $0x30383538444953, %rax # imm = 0x30383538444953
movq %rax, 0x17f42(%rip)     # 0x25d7c
movzbl (%rbx), %eax
cmpl $0x52, %eax
je 0xdf16
cmpl $0x50, %eax
jne 0xe0c1
movl $0x0, 0x17f43(%rip)     # 0x25d9c
movq 0x17f80(%rip), %rdi     # 0x25de0
movq (%rdi), %rax
xorl %r12d, %r12d
movl $0xff0a, %esi           # imm = 0xFF0A
xorl %edx, %edx
callq *(%rax)
movq 0x17f6a(%rip), %r14     # 0x25de0
movq (%r14), %rax
movq %r14, %rdi
movl $0xff09, %esi           # imm = 0xFF09
callq *0x8(%rax)
movq (%r14), %rcx
movzbl %al, %edx
movq %r14, %rdi
movl $0xff09, %esi           # imm = 0xFF09
callq *(%rcx)
movb 0x178de(%rip), %al      # 0x25778
decb %al
movb %al, 0x1639f(%rip)      # 0x24241
movl 0x178c4(%rip), %ecx     # 0x2576c
movb %cl, 0x16395(%rip)      # 0x24243
movb %ch, 0x16390(%rip)      # 0x24244
movb $0x0, 0x1638b(%rip)     # 0x24246
movl 0x17f17(%rip), %ecx     # 0x25dd8
movzbl %al, %eax
btl %eax, %ecx
movl $0x4546, %eax           # imm = 0x4546
movl $0x39ba, %ecx           # imm = 0x39BA
cmovael %eax, %ecx
movb %cl, 0x16371(%rip)      # 0x2424b
movb %ch, 0x16370(%rip)      # 0x24250
movzwl 0x17889(%rip), %eax     # 0x25770
movw %ax, 0x16372(%rip)      # 0x24260
movq 0x17eeb(%rip), %rax     # 0x25de0
leaq 0x16344(%rip), %rcx     # 0x24240
movb (%r12,%rcx), %dl
movb %dl, 0xb6fb8(%rax,%r12)
incq %r12
cmpq $0x25, %r12
jne 0xdefc
jmp 0xe0c1
movq 0x17ec3(%rip), %rdi     # 0x25de0
movq (%rdi), %rax
movl $0xff13, %esi           # imm = 0xFF13
movl $0xd3, %edx
callq *(%rax)
movb 0x17846(%rip), %al      # 0x25778
decb %al
movl $0x1, 0x17e5e(%rip)     # 0x25d9c
movb %al, 0x162ed(%rip)      # 0x24231
movzwl 0x17821(%rip), %eax     # 0x2576c
movw %ax, 0x162e1(%rip)      # 0x24233
testw %bp, %bp
je 0xe08b
movb $0x4c, 0x162d3(%rip)    # 0x24235
movl 0x17808(%rip), %eax     # 0x25770
movb %al, 0x162c8(%rip)      # 0x24236
shrl $0x8, %eax
jmp 0xe096
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x3df0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3e28
movl $0x2, 0x17e04(%rip)     # 0x25d9c
leaq 0x10(%rsp), %r14
movq 0x20(%r14), %rbx
addq $0x9, %rbx
leaq 0x177d0(%rip), %rdi     # 0x2577c
movq %rbx, %rsi
callq 0x31e0
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movq %rax, %rdi
callq 0x30f0
leaq (%rbx,%rax), %rsi
incq %rsi
leaq 0x179aa(%rip), %rdi     # 0x2597c
callq 0x31e0
leaq 0x10(%rsp), %rdi
callq 0x40c0
leaq 0x17b94(%rip), %rdi     # 0x25b7c
movq %rax, %rsi
callq 0x31e0
leaq 0x10(%rsp), %rdi
movzwl 0x38(%rdi), %r15d
movzwl 0x34(%rdi), %eax
movl %eax, 0x17770(%rip)     # 0x25774
movzwl 0x2c(%rdi), %ebp
movl 0x30(%rdi), %ebx
movl $0x1, 0x17dab(%rip)     # 0x25dc0
callq 0x40fe
incl %eax
movl %eax, 0x17746(%rip)     # 0x25768
leaq 0x10(%rsp), %rdi
callq 0x4164
incl %eax
movl %eax, 0x17744(%rip)     # 0x25778
movl %eax, 0x17d8a(%rip)     # 0x25dc4
movl %ebp, 0x1772c(%rip)     # 0x2576c
movl %ebx, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, 0x17722(%rip)     # 0x25770
je 0xe1f9
movb %al, 0x161b7(%rip)      # 0x24211
leaq 0x161af(%rip), %r14     # 0x24210
movl 0x1770d(%rip), %eax     # 0x25774
movb %al, 0x161a6(%rip)      # 0x24213
movb %ah, 0x161a1(%rip)      # 0x24214
movb %bl, 0x161ad(%rip)      # 0x24226
movl $0x21, %r12d
leaq 0x161a1(%rip), %rax     # 0x24227
jmp 0xe226
movw $0x9018, 0x161a1(%rip)  # imm = 0x9018
movb $-0x2, %al
movb %al, 0x1619b(%rip)      # 0x24237
movq 0x17d3d(%rip), %rax     # 0x25de0
xorl %ecx, %ecx
leaq 0x16184(%rip), %rdx     # 0x24230
movb (%rcx,%rdx), %sil
movb %sil, 0xb6fb8(%rax,%rcx)
incq %rcx
cmpq $0x8, %rcx
jne 0xe0ac
movq 0x17d18(%rip), %rdi     # 0x25de0
movl 0x176a6(%rip), %esi     # 0x25774
leaq (%rbx,%r15), %rdx
addq $0x7c, %rdx
movq (%rsp), %rcx
subq %r15, %rcx
addq $-0x7c, %rcx
callq 0xa0ce
movq 0x27d03(%rip), %rdi     # 0x35df0
movl $0xfe00, %esi           # imm = 0xFE00
callq 0x44aa
callq 0xd506
xorl %eax, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x7, %r14b
movl $0x39ba, %ecx           # imm = 0x39BA
movl $0x4546, %r11d          # imm = 0x4546
cmovel %ecx, %r11d
cmpb $0x1, %r14b
cmovel %ecx, %r11d
cmpb $0x6, %r14b
setae %cl
shrl %cl, %r11d
movb %r11b, 0x16114(%rip)    # 0x2424b
shrl $0x8, %r11d
movb %r11b, 0x1610e(%rip)    # 0x24250
movb %dil, 0x16117(%rip)     # 0x24260
movb %r10b, 0x16111(%rip)    # 0x24261
cmpl $0x100, %r9d            # imm = 0x100
jg 0xe16d
movq 0x17c80(%rip), %rdi     # 0x25de0
leaq 0x2(%rbx), %rdx
addq $-0x2, %rax
movq %rax, %rcx
jmp 0xe184
movl %r8d, 0x17600(%rip)     # 0x25774
movq 0x17c65(%rip), %rdi     # 0x25de0
addq %rbx, %rdx
movl %r8d, %esi
movq %r9, %rcx
callq 0xa0ce
movq 0x17c50(%rip), %rax     # 0x25de0
xorl %ecx, %ecx
leaq 0x160a7(%rip), %rdx     # 0x24240
movb (%rcx,%rdx), %sil
movb %sil, 0xb6fb8(%rax,%rcx)
incq %rcx
cmpq $0x25, %rcx
jne 0xe199
movabsq $0x30363338444554, %rcx # imm = 0x30363338444554
movq %rcx, 0x17bbd(%rip)     # 0x25d7c
testb $0x2, 0x26(%rbx)
je 0xe0e6
movq 0xb71d0(%rax), %rdi
testq %rdi, %rdi
je 0xe0e6
cmpl $0x1, 0x17c08(%rip)     # 0x25de8
movq (%rdi), %rax
movq 0x20(%rax), %rax
jne 0xe1ed
xorl %esi, %esi
jmp 0xe1f2
movl $0x1, %esi
callq *%rax
jmp 0xe0e6
movb %al, 0x16032(%rip)      # 0x24231
leaq 0x1602a(%rip), %r14     # 0x24230
movb $0x4c, 0x16025(%rip)    # 0x24232
movl 0x17561(%rip), %ebx     # 0x25774
movb %bl, 0x1601a(%rip)      # 0x24233
movl $0x8, %r12d
leaq 0x1600e(%rip), %rax     # 0x24234
movb %bh, (%rax)
movabsq $0x30363338444554, %rax # imm = 0x30363338444554
movq %rax, 0x17b43(%rip)     # 0x25d7c
movq 0x17ba0(%rip), %rdi     # 0x25de0
movl 0x1752e(%rip), %esi     # 0x25774
movl 0x38(%rsp), %edx
addq 0x30(%rsp), %rdx
addl $-0x2, %r15d
movq %r15, %rcx
callq 0xa0ce
movq 0x17b7e(%rip), %rax     # 0x25de0
xorl %ecx, %ecx
movb (%r14,%rcx), %dl
movb %dl, 0xb6fb8(%rax,%rcx)
incq %rcx
cmpq %rcx, %r12
jne 0xe264
leaq 0x10(%rsp), %rdi
callq 0x3e0a
jmp 0xe0e6
jmp 0xe288
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3e0a
jmp 0xe2eb
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xe2eb
movq %rbx, %rdi
callq 0x30e0
movq %rax, %rbx
movq 0x5d3f(%rip), %rdi      # 0x13ff0
leaq 0x27ba(%rip), %rsi      # 0x10a72
movl $0xb, %edx
callq 0x3260
movq 0x5d27(%rip), %rdi      # 0x13ff0
movq %rbx, %rsi
callq 0x3210
movq %rax, %rdi
callq 0x3110
movl $0x2, %edi
callq 0x3280
movq %rax, %rbx
callq 0x3330
movq %rbx, %rdi
callq 0x3360