// File: /workspace/github_c_makefile_star2_O3/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, 0x28fc4(%rip)     # 0x36e08
jne 0xde52
movq %rsi, 0x28fbb(%rip)     # 0x36e08
testq %rsi, %rsi
je 0xdec7
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0xd5e7
testl %eax, %eax
je 0xded1
testq %r14, %r14
je 0xe742
movq 0x717a(%rip), %rbx      # 0x14ff0
leaq 0x2e25(%rip), %rsi      # 0x10ca2
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 0xe744
callq 0xd9b6
movq 0x18f13(%rip), %rdi     # 0x26df0
callq 0x9dc8
movq 0x28f17(%rip), %rdi     # 0x36e00
callq 0x43fa
callq 0xd9ee
movq 0x28f0e(%rip), %rdi     # 0x36e08
movq (%rdi), %rax
callq *0x30(%rax)
movq 0x28f01(%rip), %rdi     # 0x36e08
movq (%rdi), %rax
movl $0x96, %esi
callq *0x28(%rax)
callq 0xda3b
movq 0x18842(%rip), %rbx     # 0x26760
leaq 0x18833(%rip), %r15     # 0x26758
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
movzbl 0x1(%rbx), %eax
cmpl $0x54, %eax
je 0xdf5b
cmpl $0x53, %eax
jne 0xdf89
cmpb $0x49, 0x2(%rbx)
je 0xdf61
jmp 0xdf89
cmpb $0x45, 0x2(%rbx)
jne 0xdf89
cmpb $0x44, 0x3(%rbx)
jne 0xdf89
movzwl 0x8(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x1880c(%rip)     # 0x26784
testw %ax, %ax
je 0xe456
xorl %r15d, %r15d
jmp 0xe466
leaq 0x11(%rbx), %rdi
leaq 0x2cec(%rip), %rsi      # 0x10c80
movl $0x8, %edx
callq 0x3100
testl %eax, %eax
je 0xe07b
leaq 0x1181(%rip), %rsi      # 0xf12e
movl $0x5, %edx
movq %rbx, %rdi
callq 0x3100
testl %eax, %eax
je 0xe22a
movl $0xffffffff, 0x18de0(%rip) # imm = 0xFFFFFFFF
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x18df3(%rip)     # 0x26dd0
movl $0x1, %eax
movl %eax, 0x187a0(%rip)     # 0x26788
movl %eax, 0x1878a(%rip)     # 0x26778
movl $0xfe00, 0x18788(%rip)  # imm = 0xFE00
leaq 0x1878d(%rip), %rdi     # 0x2678c
movq %r14, %rsi
callq 0x31e0
movabsq $0x6e776f6e6b6e55, %rax # imm = 0x6E776F6E6B6E55
movq %rax, 0x18974(%rip)     # 0x2698c
movq %rax, 0x18b6d(%rip)     # 0x26b8c
movq %rax, 0x18d66(%rip)     # 0x26d8c
movzwl (%rbx), %esi
movl %esi, 0x18755(%rip)     # 0x26784
movq 0x18dba(%rip), %rdi     # 0x26df0
addq $0x2, %rbx
movq (%rsp), %rcx
addq $-0x2, %rcx
movq %rbx, %rdx
callq 0xa22c
xorl %eax, %eax
movq 0x18d9d(%rip), %rcx     # 0x26df0
leaq 0x2c82(%rip), %rdx      # 0x10cdc
movb (%rax,%rdx), %sil
movb %sil, 0xb6fb8(%rcx,%rax)
incq %rax
cmpq $0x6, %rax
jne 0xe05a
movq 0xb71d0(%rcx), %rdi
jmp 0xe3a2
movl $0x3, 0x18d27(%rip)     # 0x26dac
movzbl 0x19(%rbx), %eax
movl %eax, 0x18d41(%rip)     # 0x26dd0
movzbl 0x22(%rbx), %eax
movl %eax, 0x186df(%rip)     # 0x26778
movl $0x1, %eax
movl %eax, 0x18d30(%rip)     # 0x26dd4
movl %eax, 0x186de(%rip)     # 0x26788
movl $0xfe00, 0x186cc(%rip)  # imm = 0xFE00
leaq 0x41(%rbx), %r14
leaq 0x186cd(%rip), %r15     # 0x2678c
xorl %ebp, %ebp
movl $0x600, %edx            # imm = 0x600
movq %r15, %rdi
xorl %esi, %esi
callq 0x3130
movq %r15, %rdi
movq %r14, %rsi
callq 0xddd5
movq %r15, %rdi
movl $0x20, %esi
callq 0xd1a5
leaq 0x61(%rbx), %rsi
leaq 0x18899(%rip), %r14     # 0x2698c
movq %r14, %rdi
callq 0xddd5
movq %r14, %rdi
movl $0x20, %esi
callq 0xd1a5
leaq 0x81(%rbx), %rsi
leaq 0x18a76(%rip), %r14     # 0x26b8c
movq %r14, %rdi
callq 0xddd5
movq %r14, %rdi
movl $0x20, %esi
callq 0xd1a5
movzwl (%rbx), %esi
movl %esi, 0x18650(%rip)     # 0x26784
movzbl 0x1e(%rbx), %r14d
movzbl 0x1f(%rbx), %r15d
movl %r15d, %eax
shll $0x8, %eax
orl %r14d, %eax
movl %eax, 0x1862f(%rip)     # 0x2677c
movzbl 0x20(%rbx), %edi
movzbl 0x21(%rbx), %r10d
movl %r10d, %eax
shll $0x8, %eax
orl %edi, %eax
movl %eax, 0x1861c(%rip)     # 0x26780
movzwl 0x1a(%rbx), %edx
movzwl 0x1c(%rbx), %r8d
movq (%rsp), %rax
movq %rax, %r9
subq %rdx, %r9
movb 0x24(%rbx), %r11b
movb 0x25(%rbx), %cl
movb 0x18603(%rip), %r12b    # 0x26788
decb %r12b
movb %r12b, 0x170b2(%rip)    # 0x25241
movb %r14b, 0x170ad(%rip)    # 0x25243
movb %r15b, 0x170a7(%rip)    # 0x25244
testb $0x1, 0x26(%rbx)
movl $0x1b, %r14d
cmovnel %ebp, %r14d
movb %r14b, 0x17094(%rip)    # 0x25246
movb 0x23(%rbx), %r14b
leal -0x2(%r14), %ebp
cmpb $0x4, %bpl
jb 0xe1eb
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
movl %r11d, %ecx
shrl $0x8, %ecx
movb %r11b, 0x17059(%rip)    # 0x2524b
movb %cl, 0x17058(%rip)      # 0x25250
movb %dil, 0x17061(%rip)     # 0x25260
movb %r10b, 0x1705b(%rip)    # 0x25261
cmpl $0x100, %r9d            # imm = 0x100
jg 0xe33f
movq 0x18bd6(%rip), %rdi     # 0x26df0
leaq 0x2(%rbx), %rdx
addq $-0x2, %rax
movq %rax, %rcx
jmp 0xe356
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x3dc4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3dfc
movl $0x2, 0x18b60(%rip)     # 0x26dac
leaq 0x10(%rsp), %r14
movq 0x20(%r14), %rbx
addq $0x9, %rbx
leaq 0x1852c(%rip), %rdi     # 0x2678c
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 0x18706(%rip), %rdi     # 0x2698c
callq 0x31e0
leaq 0x10(%rsp), %rdi
callq 0x40a6
leaq 0x188f0(%rip), %rdi     # 0x26b8c
movq %rax, %rsi
callq 0x31e0
leaq 0x10(%rsp), %rdi
movzwl 0x38(%rdi), %r15d
movzwl 0x34(%rdi), %eax
movl %eax, 0x184cc(%rip)     # 0x26784
movzwl 0x2c(%rdi), %ebp
movl 0x30(%rdi), %ebx
movl $0x1, 0x18b07(%rip)     # 0x26dd0
callq 0x40e4
incl %eax
movl %eax, 0x184a2(%rip)     # 0x26778
leaq 0x10(%rsp), %rdi
callq 0x414a
incl %eax
movl %eax, 0x184a0(%rip)     # 0x26788
movl %eax, 0x18ae6(%rip)     # 0x26dd4
movl %ebp, 0x18488(%rip)     # 0x2677c
movl %ebx, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, 0x1847e(%rip)     # 0x26780
je 0xe3cb
movb %al, 0x16f03(%rip)      # 0x25211
leaq 0x16efb(%rip), %r14     # 0x25210
movl 0x18469(%rip), %eax     # 0x26784
movb %al, 0x16ef2(%rip)      # 0x25213
movb %ah, 0x16eed(%rip)      # 0x25214
movb %bl, 0x16ef9(%rip)      # 0x25226
movl $0x21, %r12d
leaq 0x16eed(%rip), %rcx     # 0x25227
jmp 0xe3fa
movl %r8d, 0x1843e(%rip)     # 0x26784
movq 0x18aa3(%rip), %rdi     # 0x26df0
addq %rbx, %rdx
movl %r8d, %esi
movq %r9, %rcx
callq 0xa22c
movq 0x18a8e(%rip), %rax     # 0x26df0
xorl %ecx, %ecx
leaq 0x16ed5(%rip), %rdx     # 0x25240
movb (%rcx,%rdx), %sil
movb %sil, 0xb6fb8(%rax,%rcx)
incq %rcx
cmpq $0x25, %rcx
jne 0xe36b
movabsq $0x30363338444554, %rcx # imm = 0x30363338444554
movq %rcx, 0x189fb(%rip)     # 0x26d8c
testb $0x2, 0x26(%rbx)
je 0xe72c
movq 0xb71d0(%rax), %rdi
testq %rdi, %rdi
je 0xe72c
cmpl $0x1, 0x18a46(%rip)     # 0x26df8
movq (%rdi), %rax
movq 0x20(%rax), %rax
jne 0xe3bf
xorl %esi, %esi
jmp 0xe3c4
movl $0x1, %esi
callq *%rax
jmp 0xe72c
movb %al, 0x16e60(%rip)      # 0x25231
leaq 0x16e58(%rip), %r14     # 0x25230
movb $0x4c, 0x16e53(%rip)    # 0x25232
movl 0x1839f(%rip), %ebx     # 0x26784
movb %bl, 0x16e48(%rip)      # 0x25233
movl $0x8, %r12d
leaq 0x16e3c(%rip), %rcx     # 0x25234
movl %ebx, %eax
movb %bh, (%rcx)
movabsq $0x30363338444554, %rcx # imm = 0x30363338444554
movq %rcx, 0x1897f(%rip)     # 0x26d8c
movq 0x189dc(%rip), %rdi     # 0x26df0
movl 0x38(%rsp), %edx
addq 0x30(%rsp), %rdx
addl $-0x2, %r15d
movl %eax, %esi
movq %r15, %rcx
callq 0xa22c
movq 0x189be(%rip), %rax     # 0x26df0
xorl %ecx, %ecx
movb (%r14,%rcx), %dl
movb %dl, 0xb6fb8(%rax,%rcx)
incq %rcx
cmpq %rcx, %r12
jne 0xe434
leaq 0x10(%rsp), %rdi
callq 0x3dde
jmp 0xe72c
movzwl 0x7c(%rbx), %eax
movl %eax, 0x18324(%rip)     # 0x26784
movl $0x2, %r15d
movzwl 0xa(%rbx), %ecx
movzwl 0xc(%rbx), %ebp
rolw $0x8, %cx
rolw $0x8, %bp
movzwl %cx, %ecx
testw %cx, %cx
cmovnel %ecx, %eax
movl %eax, 0x182f7(%rip)     # 0x2677c
leaq 0x182cc(%rip), %rsi     # 0x26758
testw %bp, %bp
movl $0xfe33, %eax           # imm = 0xFE33
cmovnel %ebp, %eax
movzwl %ax, %eax
movl %eax, 0x182e0(%rip)     # 0x26780
movzwl 0x10(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x182d7(%rip)     # 0x26788
movl %eax, 0x1891d(%rip)     # 0x26dd4
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x18908(%rip)     # 0x26dd0
movzwl 0xe(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x1829f(%rip)     # 0x26778
movl 0x12(%rbx), %eax
bswapl %eax
movl %eax, 0x18904(%rip)     # 0x26de8
movq %rbx, %rdi
callq 0xd1e8
movq 0x188fd(%rip), %rdi     # 0x26df0
movq 0xb71d0(%rdi), %r14
testq %r14, %r14
je 0xe54b
movq 0x45fb8(%rdi), %rax
movzbl 0x18(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x18(%rax)
movl $0x1, %esi
callq 0x9dea
cmpl $0x2, 0x188af(%rip)     # 0x26dd0
jne 0xe529
testb $0x20, 0x77(%rbx)
jne 0xe565
xorl %esi, %esi
cmpl $0x2, 0x188c6(%rip)     # 0x26df8
sete %sil
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
movabsq $0x31383536444953, %rax # imm = 0x31383536444953
jmp 0xe585
movabsq $0x3f30363338444554, %rax # imm = 0x3F30363338444554
movq %rax, 0x18830(%rip)     # 0x26d8c
movb $0x0, 0x18831(%rip)     # 0x26d94
jmp 0xe58c
xorl %esi, %esi
cmpl $0x1, 0x1888a(%rip)     # 0x26df8
setne %sil
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
movabsq $0x30383538444953, %rax # imm = 0x30383538444953
movq %rax, 0x18800(%rip)     # 0x26d8c
movzbl (%rbx), %eax
cmpl $0x50, %eax
je 0xe643
cmpl $0x52, %eax
jne 0xe707
movq 0x18848(%rip), %rdi     # 0x26df0
movq (%rdi), %rax
movl $0xff13, %esi           # imm = 0xFF13
movl $0xd3, %edx
callq *(%rax)
movb 0x181cb(%rip), %al      # 0x26788
decb %al
movl 0x181bb(%rip), %ecx     # 0x26780
movl %ecx, %edx
shrl $0x8, %edx
testw %bp, %bp
movl $0x1, 0x187d5(%rip)     # 0x26dac
movb %al, 0x16c54(%rip)      # 0x25231
movzwl 0x18198(%rip), %eax     # 0x2677c
movw %ax, 0x16c48(%rip)      # 0x25233
movl $0x18, %eax
movl $0x4c, %esi
cmovel %eax, %esi
movl $0x90, %eax
cmovnel %ecx, %eax
movl $0xfe, %ecx
cmovnel %edx, %ecx
movb %sil, 0x16c26(%rip)     # 0x25235
movb %al, 0x16c21(%rip)      # 0x25236
movb %cl, 0x16c1c(%rip)      # 0x25237
xorl %eax, %eax
movq 0x187cc(%rip), %rdi     # 0x26df0
leaq 0x16c05(%rip), %rcx     # 0x25230
movb (%rax,%rcx), %dl
movb %dl, 0xb6fb8(%rdi,%rax)
incq %rax
cmpq $0x8, %rax
jne 0xe62b
jmp 0xe70e
movl $0x0, 0x1875f(%rip)     # 0x26dac
movq 0x1879c(%rip), %rdi     # 0x26df0
movq (%rdi), %rax
xorl %r12d, %r12d
movl $0xff0a, %esi           # imm = 0xFF0A
xorl %edx, %edx
callq *(%rax)
movq 0x18786(%rip), %r14     # 0x26df0
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 0x180fa(%rip), %al      # 0x26788
decb %al
movb %al, 0x16bab(%rip)      # 0x25241
movl 0x180e0(%rip), %ecx     # 0x2677c
movb %cl, 0x16ba1(%rip)      # 0x25243
movb %ch, 0x16b9c(%rip)      # 0x25244
movb $0x0, 0x16b97(%rip)     # 0x25246
movl 0x18733(%rip), %ecx     # 0x26de8
movzbl %al, %eax
btl %eax, %ecx
movl $0x4546, %eax           # imm = 0x4546
movl $0x39ba, %ecx           # imm = 0x39BA
cmovael %eax, %ecx
movb %cl, 0x16b7d(%rip)      # 0x2524b
movb %ch, 0x16b7c(%rip)      # 0x25250
movzwl 0x180a5(%rip), %eax     # 0x26780
movw %ax, 0x16b7e(%rip)      # 0x25260
movq 0x18707(%rip), %rdi     # 0x26df0
leaq 0x16b50(%rip), %rax     # 0x25240
movb (%r12,%rax), %cl
movb %cl, 0xb6fb8(%rdi,%r12)
incq %r12
cmpq $0x25, %r12
jne 0xe6f0
jmp 0xe70e
movq 0x186e2(%rip), %rdi     # 0x26df0
movl 0x18070(%rip), %esi     # 0x26784
leaq (%rbx,%r15), %rdx
addq $0x7c, %rdx
movq (%rsp), %rcx
subq %r15, %rcx
addq $-0x7c, %rcx
callq 0xa22c
movq 0x286cd(%rip), %rdi     # 0x36e00
movl $0xfe00, %esi           # imm = 0xFE00
callq 0x448e
callq 0xd9ee
xorl %eax, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe753
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3dde
jmp 0xe7b6
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xe7b6
movq %rbx, %rdi
callq 0x30e0
movq %rax, %rbx
movq 0x6874(%rip), %rdi      # 0x14ff0
leaq 0x2513(%rip), %rsi      # 0x10c96
movl $0xb, %edx
callq 0x3260
movq 0x685c(%rip), %rdi      # 0x14ff0
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