// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x8(%rsp)
movq %rdi, %r14
cmpq $0x0, 0x28ef9(%rip)     # 0x35e18
pushq $0x1
popq %rbx
jne 0xcf34
movq %rsi, 0x28eed(%rip)     # 0x35e18
testq %rsi, %rsi
je 0xd75a
leaq 0x8(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0xc7bf
testl %eax, %eax
je 0xcf7c
testq %r14, %r14
je 0xd758
movq 0x7098(%rip), %rdi      # 0x13ff0
leaq 0x2b3b(%rip), %rsi      # 0xfa9a
callq 0x3200
movq %rax, %rdi
movq %r14, %rsi
callq 0x3200
movq %rax, %rdi
callq 0x3110
jmp 0xd75a
callq 0xcafa
callq 0xc962
callq 0xcb32
movq 0x28e86(%rip), %rdi     # 0x35e18
movq (%rdi), %rax
callq *0x30(%rax)
movq 0x28e79(%rip), %rdi     # 0x35e18
movq (%rdi), %rax
movl $0x96, %esi
callq *0x28(%rax)
callq 0xcb7f
leaq 0x187b2(%rip), %rdi     # 0x25768
movq %r14, %rsi
callq 0x3390
movq 0x8(%rsp), %rbx
movzbl 0x1(%rbx), %eax
cmpl $0x54, %eax
je 0xcfd9
cmpl $0x53, %eax
jne 0xd007
cmpb $0x49, 0x2(%rbx)
je 0xcfdf
jmp 0xd007
cmpb $0x45, 0x2(%rbx)
jne 0xd007
cmpb $0x44, 0x3(%rbx)
jne 0xd007
movzwl 0x8(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x1879e(%rip)     # 0x25794
testw %ax, %ax
je 0xd48e
xorl %r15d, %r15d
jmp 0xd49c
leaq 0x11(%rbx), %rdi
leaq 0x2a66(%rip), %rsi      # 0xfa78
pushq $0x8
popq %rdx
callq 0x3100
testl %eax, %eax
je 0xd0df
leaq 0x1105(%rip), %rsi      # 0xe12e
pushq $0x5
popq %rdx
movq %rbx, %rdi
callq 0x3100
testl %eax, %eax
je 0xd282
orl $-0x1, 0x18d79(%rip)    # 0x25dbc
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x18d8c(%rip)     # 0x25de0
pushq $0x1
popq %rax
movl %eax, 0x1873b(%rip)     # 0x25798
movl %eax, 0x18725(%rip)     # 0x25788
movl $0xfe00, 0x18723(%rip)  # imm = 0xFE00
leaq 0x18728(%rip), %rdi     # 0x2579c
movq %r14, %rsi
callq 0x31e0
movabsq $0x6e776f6e6b6e55, %rax # imm = 0x6E776F6E6B6E55
movq %rax, 0x1890f(%rip)     # 0x2599c
movq %rax, 0x18b08(%rip)     # 0x25b9c
movq %rax, 0x18d01(%rip)     # 0x25d9c
movzwl (%rbx), %esi
movl %esi, 0x186f0(%rip)     # 0x25794
movq 0x18d55(%rip), %rdi     # 0x25e00
addq $0x2, %rbx
movq (%rsp), %rcx
addq $-0x2, %rcx
movq %rbx, %rdx
callq 0x9d72
movq 0x18d3a(%rip), %rdi     # 0x25e00
leaq 0x17198(%rip), %rdx     # 0x24265
pushq $0x6
popq %rcx
movl $0xfe00, %esi           # imm = 0xFE00
callq 0xd8c2
jmp 0xd3d7
movl $0x3, 0x18cd3(%rip)     # 0x25dbc
movzbl 0x19(%rbx), %eax
movl %eax, 0x18ced(%rip)     # 0x25de0
movzbl 0x22(%rbx), %eax
movl %eax, 0x1868b(%rip)     # 0x25788
pushq $0x1
popq %rax
movl %eax, 0x18cde(%rip)     # 0x25de4
movl %eax, 0x1868c(%rip)     # 0x25798
movl $0xfe00, 0x1867a(%rip)  # imm = 0xFE00
leaq 0x41(%rbx), %r14
leaq 0x1867b(%rip), %r15     # 0x2579c
xorl %r12d, %r12d
movl $0x600, %edx            # imm = 0x600
movq %r15, %rdi
xorl %esi, %esi
callq 0x3130
movq %r15, %rdi
movq %r14, %rsi
callq 0xced7
pushq $0x20
popq %rbp
movq %r15, %rdi
movl %ebp, %esi
callq 0xc402
leaq 0x61(%rbx), %rsi
leaq 0x18846(%rip), %r14     # 0x2599c
movq %r14, %rdi
callq 0xced7
movq %r14, %rdi
movl %ebp, %esi
callq 0xc402
leaq 0x81(%rbx), %rsi
leaq 0x18a26(%rip), %r14     # 0x25b9c
movq %r14, %rdi
callq 0xced7
movq %r14, %rdi
movl %ebp, %esi
callq 0xc402
movzwl (%rbx), %esi
movl %esi, 0x18603(%rip)     # 0x25794
movzbl 0x1e(%rbx), %ebp
movzbl 0x1f(%rbx), %r14d
movl %r14d, %eax
shll $0x8, %eax
orl %ebp, %eax
movl %eax, 0x185e4(%rip)     # 0x2578c
movzbl 0x20(%rbx), %edi
movzbl 0x21(%rbx), %r10d
movl %r10d, %eax
shll $0x8, %eax
orl %edi, %eax
movl %eax, 0x185d1(%rip)     # 0x25790
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 0x185b8(%rip), %r15b    # 0x25798
decb %r15b
movb %r15b, 0x17057(%rip)    # 0x24241
movb %bpl, 0x17052(%rip)     # 0x24243
movb %r14b, 0x1704c(%rip)    # 0x24244
testb $0x1, 0x26(%rbx)
pushq $0x1b
popq %rbp
cmovnel %r12d, %ebp
movb %bpl, 0x1703c(%rip)     # 0x24246
movb 0x23(%rbx), %r14b
leal -0x2(%r14), %ebp
cmpb $0x4, %bpl
jb 0xd243
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, 0x17001(%rip)    # 0x2424b
movb %cl, 0x17000(%rip)      # 0x24250
movb %dil, 0x17009(%rip)     # 0x24260
movb %r10b, 0x17003(%rip)    # 0x24261
cmpl $0x100, %r9d            # imm = 0x100
jg 0xd385
movq 0x18b8e(%rip), %rdi     # 0x25e00
leaq 0x2(%rbx), %rdx
addq $-0x2, %rax
movq %rax, %rcx
jmp 0xd39c
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x3d2c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3d5e
movl $0x2, 0x18b18(%rip)     # 0x25dbc
leaq 0x10(%rsp), %rbx
movq 0x20(%rbx), %rsi
addq $0x9, %rsi
leaq 0x184e4(%rip), %rdi     # 0x2579c
callq 0x31e0
movq %rbx, %rdi
callq 0x3f9c
leaq 0x186d0(%rip), %rdi     # 0x2599c
movq %rax, %rsi
callq 0x31e0
leaq 0x10(%rsp), %rdi
callq 0x3fb8
leaq 0x188b7(%rip), %rdi     # 0x25b9c
movq %rax, %rsi
callq 0x31e0
leaq 0x10(%rsp), %rdi
movzwl 0x38(%rdi), %r15d
movzwl 0x34(%rdi), %eax
movl %eax, 0x18493(%rip)     # 0x25794
movzwl 0x2c(%rdi), %ebp
movl 0x30(%rdi), %ebx
movl $0x1, 0x18ace(%rip)     # 0x25de0
callq 0x3ff6
incl %eax
movl %eax, 0x18469(%rip)     # 0x25788
leaq 0x10(%rsp), %rdi
callq 0x405c
incl %eax
movl %eax, 0x18467(%rip)     # 0x25798
movl %eax, 0x18aad(%rip)     # 0x25de4
movl %ebp, 0x1844f(%rip)     # 0x2578c
movl %ebx, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, 0x18445(%rip)     # 0x25790
je 0xd40c
movb %al, 0x16eba(%rip)      # 0x24211
leaq 0x16eb2(%rip), %r14     # 0x24210
movl 0x18430(%rip), %eax     # 0x25794
movb %al, 0x16ea9(%rip)      # 0x24213
movb %ah, 0x16ea4(%rip)      # 0x24214
movb %bl, 0x16eb0(%rip)      # 0x24226
pushq $0x21
popq %rbp
leaq 0x16ea7(%rip), %rcx     # 0x24227
jmp 0xd438
movl %r8d, 0x18408(%rip)     # 0x25794
movq 0x18a6d(%rip), %rdi     # 0x25e00
addq %rbx, %rdx
movl %r8d, %esi
movq %r9, %rcx
callq 0x9d72
movq 0x18a58(%rip), %rdi     # 0x25e00
leaq 0x16e91(%rip), %rdx     # 0x24240
pushq $0x25
popq %rcx
movl $0xfe00, %esi           # imm = 0xFE00
callq 0xd8c2
movabsq $0x30363338444554, %rax # imm = 0x30363338444554
movq %rax, 0x189cf(%rip)     # 0x25d9c
testb $0x2, 0x26(%rbx)
je 0xd742
movq 0x18a22(%rip), %rax     # 0x25e00
movq 0xb71d0(%rax), %rdi
testq %rdi, %rdi
je 0xd742
cmpl $0x1, 0x18a13(%rip)     # 0x25e08
movq (%rdi), %rax
movq 0x20(%rax), %rax
jne 0xd402
xorl %esi, %esi
jmp 0xd405
pushq $0x1
popq %rsi
callq *%rax
jmp 0xd742
movb %al, 0x16e1f(%rip)      # 0x24231
leaq 0x16e17(%rip), %r14     # 0x24230
movb $0x4c, 0x16e12(%rip)    # 0x24232
movl 0x1836e(%rip), %ebx     # 0x25794
movb %bl, 0x16e07(%rip)      # 0x24233
pushq $0x8
popq %rbp
leaq 0x16dfe(%rip), %rcx     # 0x24234
movl %ebx, %eax
movb %bh, (%rcx)
movabsq $0x30363338444554, %rcx # imm = 0x30363338444554
movq %rcx, 0x18951(%rip)     # 0x25d9c
movq 0x189ae(%rip), %rdi     # 0x25e00
movl 0x38(%rsp), %edx
addq 0x30(%rsp), %rdx
addl $-0x2, %r15d
movl %eax, %esi
movq %r15, %rcx
callq 0x9d72
movq 0x18990(%rip), %rdi     # 0x25e00
movl $0xfe00, %esi           # imm = 0xFE00
movq %r14, %rdx
movl %ebp, %ecx
callq 0xd8c2
leaq 0x10(%rsp), %rdi
callq 0x3d42
jmp 0xd742
movzwl 0x7c(%rbx), %eax
movl %eax, 0x182fc(%rip)     # 0x25794
pushq $0x2
popq %r15
movzwl 0xa(%rbx), %ecx
movzwl 0xc(%rbx), %ebp
rolw $0x8, %cx
rolw $0x8, %bp
movzwl %cx, %ecx
testw %cx, %cx
cmovnel %ecx, %eax
testw %bp, %bp
movl $0xfe33, %ecx           # imm = 0xFE33
cmovnel %ebp, %ecx
movl %eax, 0x182c6(%rip)     # 0x2578c
movzwl %cx, %eax
movl %eax, 0x182c1(%rip)     # 0x25790
movzwl 0x10(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x182b8(%rip)     # 0x25798
movl %eax, 0x188fe(%rip)     # 0x25de4
movzwl 0x4(%rbx), %eax
rolw $0x8, %ax
leaq 0x18273(%rip), %r14     # 0x25768
movzwl %ax, %eax
movl %eax, 0x188e2(%rip)     # 0x25de0
movzwl 0xe(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x18279(%rip)     # 0x25788
pushq $0x12
popq %rsi
movq %rbx, %rdi
callq 0xd8e9
movl %eax, 0x188d8(%rip)     # 0x25df8
movq %rbx, %rdi
movq %r14, %rsi
callq 0xc445
movq 0x188ce(%rip), %rdi     # 0x25e00
movq 0xb71d0(%rdi), %r14
testq %r14, %r14
je 0xd588
movq 0x45fb8(%rdi), %rax
movzbl 0x18(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x18(%rax)
pushq $0x1
popq %rsi
callq 0x997e
cmpl $0x2, 0x18882(%rip)     # 0x25de0
jne 0xd566
testb $0x20, 0x77(%rbx)
jne 0xd5a2
xorl %esi, %esi
cmpl $0x2, 0x18899(%rip)     # 0x25e08
sete %sil
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
movabsq $0x31383536444953, %rax # imm = 0x31383536444953
jmp 0xd5c2
movabsq $0x3f30363338444554, %rax # imm = 0x3F30363338444554
movq %rax, 0x18803(%rip)     # 0x25d9c
movb $0x0, 0x18804(%rip)     # 0x25da4
jmp 0xd5c9
xorl %esi, %esi
cmpl $0x1, 0x1885d(%rip)     # 0x25e08
setne %sil
movq (%r14), %rax
movq %r14, %rdi
callq *0x20(%rax)
movabsq $0x30383538444953, %rax # imm = 0x30383538444953
movq %rax, 0x187d3(%rip)     # 0x25d9c
movzbl (%rbx), %eax
cmpl $0x52, %eax
je 0xd68c
cmpl $0x50, %eax
jne 0xd71d
andl $0x0, 0x187d7(%rip)     # 0x25dbc
movq 0x18814(%rip), %rdi     # 0x25e00
movq (%rdi), %rax
movl $0xff0a, %esi           # imm = 0xFF0A
xorl %edx, %edx
callq *(%rax)
movq 0x18801(%rip), %r14     # 0x25e00
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 0x18175(%rip), %al      # 0x25798
decb %al
movb %al, 0x16c16(%rip)      # 0x24241
leaq 0x16c0e(%rip), %rdx     # 0x24240
movl 0x18154(%rip), %ecx     # 0x2578c
movb %cl, 0x16c05(%rip)      # 0x24243
movb %ch, 0x16c00(%rip)      # 0x24244
movb $0x0, 0x16bfb(%rip)     # 0x24246
movl 0x187a7(%rip), %ecx     # 0x25df8
movzbl %al, %eax
btl %eax, %ecx
movl $0x4546, %eax           # imm = 0x4546
movl $0x39ba, %ecx           # imm = 0x39BA
cmovael %eax, %ecx
movb %cl, 0x16be1(%rip)      # 0x2424b
movb %ch, 0x16be0(%rip)      # 0x24250
movzwl 0x18119(%rip), %eax     # 0x25790
movw %ax, 0x16be2(%rip)      # 0x24260
movq 0x1877b(%rip), %rdi     # 0x25e00
pushq $0x25
jmp 0xd712
movq 0x1876d(%rip), %rdi     # 0x25e00
movq (%rdi), %rax
movl $0xff13, %esi           # imm = 0xFF13
movl $0xd3, %edx
callq *(%rax)
movb 0x180f0(%rip), %al      # 0x25798
decb %al
movl 0x180e0(%rip), %ecx     # 0x25790
movl %ecx, %esi
shrl $0x8, %esi
testw %bp, %bp
movl $0x1, 0x186fa(%rip)     # 0x25dbc
movb %al, 0x16b69(%rip)      # 0x24231
leaq 0x16b61(%rip), %rdx     # 0x24230
pushq $0x18
popq %rax
pushq $0x4c
popq %rdi
cmovel %eax, %edi
movl $0x90, %eax
cmovnel %ecx, %eax
movzwl 0x180a5(%rip), %ecx     # 0x2578c
movw %cx, 0x16b45(%rip)      # 0x24233
movl $0xfe, %ecx
cmovnel %esi, %ecx
movb %dil, 0x16b38(%rip)     # 0x24235
movb %al, 0x16b33(%rip)      # 0x24236
movb %cl, 0x16b2e(%rip)      # 0x24237
movq 0x186f0(%rip), %rdi     # 0x25e00
pushq $0x8
popq %rcx
movl $0xfe00, %esi           # imm = 0xFE00
callq 0xd8c2
movq 0x186dc(%rip), %rdi     # 0x25e00
movl 0x1806a(%rip), %esi     # 0x25794
leaq (%rbx,%r15), %rdx
addq $0x7c, %rdx
movq (%rsp), %rcx
subq %r15, %rcx
addq $-0x7c, %rcx
callq 0x9d72
movq 0x286c7(%rip), %rdi     # 0x35e10
movl $0xfe00, %esi           # imm = 0xFE00
callq 0x4352
callq 0xcb32
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd76b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3d42
jmp 0xd7c3
movq %rax, %rbx
cmpl $0x1, %edx
jne 0xd7c3
movq %rbx, %rdi
callq 0x30d0
movq %rax, %rbx
movq 0x685c(%rip), %rdi      # 0x13ff0
leaq 0x22f3(%rip), %rsi      # 0xfa8e
callq 0x3200
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3200
movq %rax, %rdi
callq 0x3110
pushq $0x2
popq %rdi
callq 0x3270
movq %rax, %rbx
callq 0x3310
movq %rbx, %rdi
callq 0x3340