// File: /workspace/github_cpp_makefile_star2_O1/atsidaev[P]trx2x/DiskImage.cpp
// Function: TDiskImage::readTD0(int, bool)
void TDiskImage::readTD0(int hfile, bool readonly)
{
   long fsize = filelength(hfile);
   if(fsize < 0)
   {
      ShowError(ERR_GETLEN);
      return;
   }
   unsigned char *ptr = (unsigned char*)new char[fsize+256*20000];
   if(!ptr)
   {
      ShowError(ERR_NOMEM);
      return;
   }
   long rsize = read(hfile, ptr, fsize);

   TD0_MAIN_HEADER *td0hdr = (TD0_MAIN_HEADER*)ptr; 
   TD0_INFO_DATA *td0inf = (TD0_INFO_DATA*)(ptr+12);

   if(!rsize)
   {
      delete ptr;
      ShowError(ERR_CORRUPT);
      return;
   }
   if(rsize < 12)      // header
   {
      delete ptr;
      ShowError(ERR_CORRUPT);
      return;
   }

   if( (*(short*)ptr != WORD2('T','D'))&&(*(short*)ptr != WORD2('t','d')) )// non TD0
   {
      delete ptr;
      ShowError(ERR_FORMAT" TD0!");
      return;
   }
   if( TD0CRC(ptr,10) != td0hdr->CRC ) // CRC bad...
   {
      delete ptr;
      ShowError(ERR_FILECRC" TD0!");
      return;
   }
   if( (td0hdr->Ver > 21)||(td0hdr->Ver < 10) )           // 1.0 <= version <= 2.1...
   {
      delete ptr;
      ShowError(ERR_FILEVER" TD0!");
      return;
   }
   if( td0hdr->DataDOS != 0 )           // if DOS allocated sectors only...
   {
      delete ptr;
      ShowError(ERR_TD0DOSALLOC);
      return;
   }
   if(!unpack_td0(ptr, rsize))
   {
      delete ptr;
      ShowError(ERR_FORMAT" TD0!");
      return;
   }

// loading unpacked TD0...

   int tdOFF = 12;
   if(ptr[7] & 0x80) tdOFF += sizeof(TD0_INFO_DATA) + td0inf->strLen;

   TD0_TRACK_HEADER *tdtrk;
   TD0_SECT_HEADER *tdsect;

   MaxTrack = 0;
   MaxSide = 0;

   for(; tdOFF < rsize ;)
   {
      tdtrk = (TD0_TRACK_HEADER*)(ptr+tdOFF);
      tdOFF += sizeof(TD0_TRACK_HEADER);

      if(tdOFF >= rsize) break;
      if( tdtrk->SectorCount == 0xFF ) break;   // EOF marker


      unsigned trk = tdtrk->Track;
      unsigned side = tdtrk->Side;
      FTrackLength[trk][side] = 6250;

// make unformatted track...
      FTracksPtr[trk][side][0] = (unsigned char*)new char[FTrackLength[trk][side]+1024];      // trk img
      FTracksPtr[trk][side][1] = (unsigned char*)new char[FTrackLength[trk][side]+1024];      // clk img
      for(unsigned ij=0; ij < 6250; ij++)   
      {
         FTracksPtr[trk][side][0][ij] = 0x00;
         FTracksPtr[trk][side][1][ij] = 0x00;         
      }


      unsigned SecCount = tdtrk->SectorCount;

      unsigned int tmpOFF = tdOFF;

// Вычисляем необходимое число байт под данные:
      unsigned int trkdatalen = 0;
      unsigned int SL;
      for(unsigned int ilsec=0; ilsec < SecCount; ilsec++)
      {
         tdsect = (TD0_SECT_HEADER*)(ptr+tmpOFF); 
         tmpOFF += sizeof(TD0_SECT_HEADER)+tdsect->DataLength;

         trkdatalen += 2+6;     // for marks:   0xA1, 0xFE, 6bytes
         trkdatalen += 4;       // for data header/crc: 0xA1, 0xFB, ...,2bytes
//         SL = unsigned(tdsect->ADRM[3]);
//         if(!SL) SL = 128;
//         else SL = 128 << SL;
         SL = tdsect->DataLength-1;
         trkdatalen += SL;
      }

// проверка на возможность формата...
      if(trkdatalen + SecCount*(3+2) > 6250)    // 3x4E & 2x00 per sec checking
      {
         delete ptr;
         for(int t=0; t < 256; t++)
            for(int s=0; s < 256; s++)
            {
               FTrackLength[t][s] = 0;
               if(FTracksPtr[t][s][0]) delete FTracksPtr[t][s][0];
               FTracksPtr[t][s][0] = NULL;
               if(FTracksPtr[t][s][1]) delete FTracksPtr[t][s][1];
               FTracksPtr[t][s][1] = NULL;
            }
         ShowError(ERR_IMPOSSIBLE);
         return;
      }

      unsigned int FreeSpace = 6250 - (trkdatalen + SecCount*(3+2));

      unsigned int SynchroPulseLen = 1; // 1 уже учтен в trkdatalen...
      unsigned int FirstSpaceLen = 1;
      unsigned int SecondSpaceLen = 1;
      unsigned int ThirdSpaceLen = 1;
      unsigned int SynchroSpaceLen = 1;
      FreeSpace -= FirstSpaceLen+SecondSpaceLen+ThirdSpaceLen+SynchroSpaceLen;

// Распределяем длины пробелов и синхропромежутка:
      while(FreeSpace > 0)
      {
         if(FreeSpace>=(SecCount*2)) 
            if(SynchroSpaceLen < 12) {SynchroSpaceLen++; FreeSpace-=SecCount*2;} // Synchro for ADM & DATA
         if(FreeSpace < SecCount) break;

         if(FirstSpaceLen < 10) {FirstSpaceLen++; FreeSpace-=SecCount;}
         if(FreeSpace < SecCount) break;
         if(SecondSpaceLen < 22) {SecondSpaceLen++; FreeSpace-=SecCount;}
         if(FreeSpace < SecCount) break;
         if(ThirdSpaceLen < 60) {ThirdSpaceLen++; FreeSpace-=SecCount;}
         if(FreeSpace < SecCount) break;

         if((SynchroSpaceLen>=12)&&(FirstSpaceLen>=10)&&(SecondSpaceLen>=22)&&(ThirdSpaceLen>=60)) break;
      };
// по возможности делаем три синхроимпульса...
      if(FreeSpace > (SecCount*2)+10) { SynchroPulseLen++; FreeSpace-=SecCount; }
      if(FreeSpace > (SecCount*2)+9) SynchroPulseLen++; 

// Форматируем дорожку...

      unsigned int tptr=0;
      unsigned int ptrcrc;
      unsigned int r;
      unsigned short vgcrc;
      for(unsigned sec=0; sec < SecCount; sec++)
      {
         tdsect = (TD0_SECT_HEADER*)(ptr+tdOFF); 
         tdOFF += sizeof(TD0_SECT_HEADER)+1;

         for(r=0; r < FirstSpaceLen; r++)        // Первый пробел
         {
            FTracksPtr[trk][side][0][tptr] = 0x4E;
            FTracksPtr[trk][side][1][tptr++] = 0x00;
         }
         for(r=0; r < SynchroSpaceLen; r++)        // Синхропромежуток
         {
            FTracksPtr[trk][side][0][tptr] = 0x00;
            FTracksPtr[trk][side][1][tptr++] = 0x00;
         }
         ptrcrc = tptr;
         for(r=0; r < SynchroPulseLen; r++)        // Синхроимпульс
         {
            FTracksPtr[trk][side][0][tptr] = 0xA1;
            FTracksPtr[trk][side][1][tptr++] = 0xFF;
         }
         FTracksPtr[trk][side][0][tptr] = 0xFE;   // Метка "Адрес"
         FTracksPtr[trk][side][1][tptr++] = 0x00;

         FTracksPtr[trk][side][0][tptr] = tdsect->ADRM[0]; // cyl
         FTracksPtr[trk][side][1][tptr++] = 0x00;
         FTracksPtr[trk][side][0][tptr] = tdsect->ADRM[1]; // head 
         FTracksPtr[trk][side][1][tptr++] = 0x00;
         FTracksPtr[trk][side][0][tptr] = tdsect->ADRM[2]; // secN
         FTracksPtr[trk][side][1][tptr++] = 0x00;
         FTracksPtr[trk][side][0][tptr] = tdsect->ADRM[3]; // len code
         FTracksPtr[trk][side][1][tptr++] = 0x00;

         vgcrc = MakeVGCRC(FTracksPtr[trk][side][0]+ptrcrc, tptr-ptrcrc);
         FTracksPtr[trk][side][0][tptr] = (unsigned char)(vgcrc>>8); // VG93 CRC
         FTracksPtr[trk][side][1][tptr++] = 0x00;
         FTracksPtr[trk][side][0][tptr] = (unsigned char)(vgcrc&0xFF);
         FTracksPtr[trk][side][1][tptr++] = 0x00;

         for(r=0; r < SecondSpaceLen; r++)        // Второй пробел
         {
            FTracksPtr[trk][side][0][tptr] = 0x4E;
            FTracksPtr[trk][side][1][tptr++] = 0x00;
         }
         for(r=0; r < SynchroSpaceLen; r++)        // Синхропромежуток
         {
            FTracksPtr[trk][side][0][tptr] = 0x00;
            FTracksPtr[trk][side][1][tptr++] = 0x00;
         }

         if(tdsect->DataLength-1) // oh-oh, data area not present... ;-) 
         {
            ptrcrc = tptr;
            for(r=0; r < SynchroPulseLen; r++)        // Синхроимпульс
            {
               FTracksPtr[trk][side][0][tptr] = 0xA1;
               FTracksPtr[trk][side][1][tptr++] = 0xFF;
            }

            FTracksPtr[trk][side][0][tptr] = 0xFB;   // Метка "Данные"
            FTracksPtr[trk][side][1][tptr++] = 0x00;

//            SL = unsigned(tdsect->ADRM[3]);
//            if(!SL) SL = 128;
//            else SL = 128 << SL;
            SL = tdsect->DataLength-1;

            for(r=0; r < SL; r++)        // сектор SL байт
            {
               FTracksPtr[trk][side][0][tptr] = ptr[tdOFF+r];
               FTracksPtr[trk][side][1][tptr++] = 0x00;
            }
            tdOFF += SL;

            vgcrc = MakeVGCRC(FTracksPtr[trk][side][0]+ptrcrc, tptr-ptrcrc);


            FTracksPtr[trk][side][0][tptr] = (unsigned char)(vgcrc>>8); // VG93 CRC
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = (unsigned char)(vgcrc&0xFF);
            FTracksPtr[trk][side][1][tptr++] = 0x00;
         }

         for(r=0; r < ThirdSpaceLen; r++)        // Третий пробел
         {
            FTracksPtr[trk][side][0][tptr] = 0x4E;
            FTracksPtr[trk][side][1][tptr++] = 0x00;
         }
      }
      for(int eoftrk=tptr; eoftrk < 6250; eoftrk++) 
      {
         FTracksPtr[trk][side][0][tptr] = 0x4E;
         FTracksPtr[trk][side][1][tptr++] = 0x00;
      }

      if(unsigned(MaxTrack) < trk) MaxTrack = trk;
      if(unsigned(MaxSide) < side) MaxSide = side;
   }

   delete ptr;
   ReadOnly = readonly;
   FType = DIT_TD0;
   DiskPresent = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r13
movl %esi, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x1210
movq %rax, %r14
movl %r15d, %edi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1210
movq %rax, %r12
movl %r15d, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x1210
testq %r12, %r12
js 0x59b9
movq %r12, %rdi
addq $0x4e2000, %rdi         # imm = 0x4E2000
callq 0x1030
movq %rax, %r14
movl %r15d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0x11b0
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x59a3
cmpq $0xb, %rax
jg 0x59d3
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x29bf(%rip), %rsi      # 0x8376
jmp 0x59c0
leaq 0x2998(%rip), %rsi      # 0x8358
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x23fa
movzwl (%r14), %eax
cmpl $0x6474, %eax           # imm = 0x6474
je 0x59e9
cmpl $0x4454, %eax           # imm = 0x4454
jne 0x6152
xorl %eax, %eax
leaq 0x57ee(%rip), %rdx      # 0xb1e0
xorl %ecx, %ecx
movzwl %cx, %ecx
movb (%r14,%rax), %sil
xorb %cl, %sil
shrl $0x8, %ecx
movzbl %sil, %esi
xorw (%rdx,%rsi,2), %cx
incq %rax
cmpl $0xa, %eax
jne 0x59f4
rolw $0x8, %cx
cmpw 0xa(%r14), %cx
jne 0x5a3c
movb 0x4(%r14), %al
addb $-0x16, %al
cmpb $-0xd, %al
ja 0x5a55
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2ce1(%rip), %rsi      # 0x871b
jmp 0x59c0
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2cb2(%rip), %rsi      # 0x8702
jmp 0x59c0
cmpb $0x0, 0x8(%r14)
je 0x5a75
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2cca(%rip), %rsi      # 0x873a
jmp 0x59c0
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x72f7
testb %al, %al
je 0x6152
movl %ebx, 0x24(%rsp)
movl $0xc, %r12d
cmpb $0x0, 0x7(%r14)
jns 0x5aa4
movzwl 0xe(%r14), %r12d
addl $0x16, %r12d
movw $0x0, 0x145007(%r13)
movq 0x40(%rsp), %rcx
leaq 0x40000(%r13), %rax
movq %rax, 0x50(%rsp)
leaq 0x40008(%r13), %rax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
movq %r13, 0x18(%rsp)
movq %rcx, 0x38(%rsp)
movslq %r12d, %rbx
cmpq %rbx, %rcx
jle 0x616b
addl $0x4, %r12d
movslq %r12d, %rax
cmpq %rax, %rcx
jle 0x616b
cmpb $-0x1, (%r14,%rbx)
je 0x616b
movl %r12d, 0x4(%rsp)
movzbl 0x1(%r14,%rbx), %r12d
movzbl 0x2(%r14,%rbx), %ebp
movl %r12d, %eax
shll $0xa, %eax
addq %r13, %rax
movl $0x186a, (%rax,%rbp,4)  # imm = 0x186A
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movl %r12d, 0x28(%rsp)
shll $0xc, %r12d
addq 0x50(%rsp), %r12
movq %rbp, 0x58(%rsp)
shll $0x4, %ebp
leaq (%r12,%rbp), %r13
movq %rax, (%rbp,%r12)
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movq %rax, 0x8(%rbp,%r12)
xorl %eax, %eax
movq (%r13), %rcx
movb %r15b, (%rcx,%rax)
movq 0x8(%r13), %rcx
movb %r15b, (%rcx,%rax)
incq %rax
cmpq $0x186a, %rax           # imm = 0x186A
jne 0x5b5a
movzbl (%r14,%rbx), %r11d
testl %r11d, %r11d
movl 0x4(%rsp), %r12d
je 0x5ba4
xorl %eax, %eax
movl %r11d, %ecx
movl %r12d, %edx
movl %edx, %esi
movzwl 0x6(%r14,%rsi), %esi
addl %esi, %edx
addl $0x8, %edx
addl %esi, %eax
addl $0xb, %eax
decl %ecx
jne 0x5b8c
jmp 0x5ba6
xorl %eax, %eax
leal (%r11,%r11,4), %r9d
addl %eax, %r9d
cmpl $0x186b, %r9d           # imm = 0x186B
movl %r9d, 0xc(%rsp)
jae 0x5fc8
movl $0x1, %ebx
xorl %ebp, %ebp
movl $0x0, %r10d
movl $0x1, %esi
movl $0x1, (%rsp)
movl $0x1, %edi
cmpl $0x1866, %r9d           # imm = 0x1866
jne 0x607c
testl %r11d, %r11d
je 0x5f64
leal 0xa(,%r11,2), %eax
xorl %ecx, %ecx
xorl %r9d, %r9d
cmpl %eax, %r10d
seta %r9b
movl $0x0, %eax
cmoval %r11d, %eax
subl %eax, %r10d
leal 0x9(,%r11,2), %eax
cmpl %r10d, %eax
adcl $0x0, %r9d
cmpl $0x1, %ebx
adcl $0x0, %ebx
movl %ebx, 0x34(%rsp)
cmpl $0x1, %edi
adcl $0x0, %edi
leal 0x1(%r9), %eax
cmpl $0x1, %eax
adcl $0x1, %r9d
leal 0x5(%r9), %r10d
cmpl $0x1, %esi
adcl $0x0, %esi
movl %esi, 0x30(%rsp)
movl (%rsp), %r8d
cmpl $0x1, %r8d
adcl $0x0, %r8d
xorl %ebp, %ebp
movq %r11, 0x60(%rsp)
movl %r8d, (%rsp)
movl %ecx, 0x8(%rsp)
movslq %r12d, %rbx
leal 0x9(%rbp), %esi
leal 0xd(%rbp), %r8d
movl 0x34(%rsp), %ecx
movl %esi, %eax
movl %r8d, %edx
movq (%r13), %rsi
movl %ebp, %r8d
movb $0x4e, (%rsi,%r8)
movq 0x8(%r13), %rsi
incl %ebp
movb $0x0, (%rsi,%r8)
leal 0x1(%rax), %esi
leal 0x1(%rdx), %r8d
decl %ecx
jne 0x5c74
xorl %esi, %esi
movl %eax, %r11d
movl %edx, %ecx
leal (%rsi,%rbp), %eax
movq (%r13), %rdx
movb %r15b, (%rdx,%rax)
movq 0x8(%r13), %rdx
movb %r15b, (%rdx,%rax)
incl %esi
leal 0x1(%r11), %eax
leal 0x1(%rcx), %edx
cmpl %esi, %edi
jne 0x5c9d
movl %r12d, 0x4(%rsp)
addl %esi, %ebp
xorl %eax, %eax
movl %ecx, %esi
leal -0x7(%r11), %ecx
movq (%r13), %rdx
movb $-0x5f, (%rdx,%rcx)
movq 0x8(%r13), %rdx
movb $-0x1, (%rdx,%rcx)
incl %eax
incl %r11d
leal 0x1(%rsi), %ecx
cmpl %eax, %r9d
jne 0x5ccb
movq (%r13), %rcx
leal -0x7(%r11), %edx
movb $-0x2, (%rcx,%rdx)
movq 0x8(%r13), %rcx
leal -0x6(%r11), %r8d
movb %r15b, (%rcx,%rdx)
movb (%r14,%rbx), %cl
movq (%r13), %rdx
movb %cl, (%rdx,%r8)
movq 0x8(%r13), %rcx
leal -0x5(%r11), %edx
movb %r15b, (%rcx,%r8)
movb 0x1(%r14,%rbx), %cl
movq (%r13), %r8
movb %cl, (%r8,%rdx)
movq 0x8(%r13), %rcx
leal -0x4(%r11), %r8d
movb %r15b, (%rcx,%rdx)
movb 0x2(%r14,%rbx), %cl
movq (%r13), %rdx
movb %cl, (%rdx,%r8)
movq 0x8(%r13), %rcx
leal -0x3(%r11), %edx
movb %r15b, (%rcx,%r8)
movq %rbx, 0x10(%rsp)
movb 0x3(%r14,%rbx), %cl
movq (%r13), %r8
movb %cl, (%r8,%rdx)
movq 0x8(%r13), %rcx
movb %r15b, (%rcx,%rdx)
movq (%r13), %rdx
movw $0xffff, %cx            # imm = 0xFFFF
cmpl $-0x5, %eax
je 0x5db8
movl %ebp, %eax
addq %rdx, %rax
movw $0xffff, %cx            # imm = 0xFFFF
xorl %ebp, %ebp
movzbl (%rax,%rbp), %r8d
shll $0x8, %r8d
xorl %r8d, %ecx
movl $0x8, %r12d
leal (%rcx,%rcx), %ebx
movl %ebx, %r8d
xorl $0x1021, %r8d           # imm = 0x1021
testw %cx, %cx
cmovnsl %ebx, %r8d
movl %r8d, %ecx
decl %r12d
jne 0x5d94
incq %rbp
cmpq %r10, %rbp
jne 0x5d82
movl 0x4(%rsp), %r12d
addl $0x9, %r12d
leal -0x2(%r11), %eax
movl %eax, %eax
movb %ch, (%rdx,%rax)
movq 0x8(%r13), %rdx
leal -0x1(%r11), %r8d
movb %r15b, (%rdx,%rax)
movq (%r13), %rax
movb %cl, (%rax,%r8)
movq 0x8(%r13), %rax
movb %r15b, (%rax,%r8)
movl 0x30(%rsp), %ecx
movl %esi, %eax
movq (%r13), %rdx
movl %r11d, %esi
movb $0x4e, (%rdx,%rsi)
movq 0x8(%r13), %rdx
incl %r11d
movb $0x0, (%rdx,%rsi)
leal 0x1(%rax), %esi
decl %ecx
jne 0x5dea
movl %edi, %ecx
movq 0x10(%rsp), %r8
movl %eax, %esi
movq (%r13), %rax
movl %r11d, %edx
movb %r15b, (%rax,%rdx)
movq 0x8(%r13), %rax
incl %r11d
movb %r15b, (%rax,%rdx)
leal 0x1(%rsi), %eax
decl %ecx
jne 0x5e10
cmpw $0x1, 0x6(%r14,%r8)
je 0x5f32
movl %r9d, %ecx
movl %esi, %eax
leal -0x1(%rax), %edx
movq (%r13), %rsi
movb $-0x5f, (%rsi,%rdx)
movq 0x8(%r13), %rsi
movb $-0x1, (%rsi,%rdx)
leal 0x1(%rax), %esi
decl %ecx
jne 0x5e3f
movq (%r13), %rcx
leal -0x1(%rsi), %ebp
movb $-0x5, (%rcx,%rbp)
movq 0x8(%r13), %rcx
movb $0x0, (%rcx,%rbp)
movzwl 0x6(%r14,%r8), %ebx
decl %ebx
je 0x5ea1
movl %ebx, %ecx
movl %r12d, %edx
incl %eax
movl %edx, %esi
movb (%r14,%rsi), %sil
movq (%r13), %r8
movb %sil, (%r8,%rax)
movq 0x8(%r13), %rsi
movb $0x0, (%rsi,%rax)
incl %edx
decq %rcx
jne 0x5e7d
leal 0x1(%rax), %esi
movl %eax, %ebp
movl %ebx, 0x2c(%rsp)
movl %r12d, 0x4(%rsp)
movq (%r13), %rax
movq %rax, 0x10(%rsp)
movw $0xffff, %cx            # imm = 0xFFFF
movl %esi, %edx
subl %r11d, %edx
je 0x5efe
movl %r11d, %r11d
addq 0x10(%rsp), %r11
movw $0xffff, %cx            # imm = 0xFFFF
xorl %r12d, %r12d
movzbl (%r11,%r12), %r8d
shll $0x8, %r8d
xorl %r8d, %ecx
movl $0x8, %r8d
leal (%rcx,%rcx), %ebx
movl %ebx, %eax
xorl $0x1021, %eax           # imm = 0x1021
testw %cx, %cx
cmovnsl %ebx, %eax
movl %eax, %ecx
decl %r8d
jne 0x5edf
incq %r12
cmpq %rdx, %r12
jb 0x5ecd
movl 0x4(%rsp), %r12d
addl 0x2c(%rsp), %r12d
movl %esi, %eax
movq 0x10(%rsp), %rdx
movb %ch, (%rdx,%rax)
movq 0x8(%r13), %rdx
leal 0x2(%rbp), %esi
movb %r15b, (%rdx,%rax)
movq (%r13), %rax
movb %cl, (%rax,%rsi)
movq 0x8(%r13), %rax
addl $0x3, %ebp
movb %r15b, (%rax,%rsi)
movl %ebp, %r11d
movl (%rsp), %eax
movl %r11d, %ebp
movq (%r13), %rcx
movl %ebp, %edx
movb $0x4e, (%rcx,%rdx)
movq 0x8(%r13), %rcx
incl %ebp
movb $0x0, (%rcx,%rdx)
decl %eax
jne 0x5f38
movl 0x8(%rsp), %ecx
incl %ecx
movq 0x60(%rsp), %r11
cmpl %r11d, %ecx
jne 0x5c62
cmpl $0x1869, %ebp           # imm = 0x1869
jg 0x5f88
movq (%r13), %rax
movl %ebp, %ecx
movb $0x4e, (%rax,%rcx)
movq 0x8(%r13), %rax
incl %ebp
movb $0x0, (%rax,%rcx)
cmpl $0x186a, %ebp           # imm = 0x186A
jne 0x5f6c
movq 0x18(%rsp), %r13
movl 0x28(%rsp), %eax
cmpb %al, 0x145007(%r13)
movl 0xc(%rsp), %edx
jae 0x5fa5
movb %al, 0x145007(%r13)
movq 0x58(%rsp), %rax
cmpb %al, 0x145008(%r13)
movq 0x38(%rsp), %rcx
jae 0x606b
movb %al, 0x145008(%r13)
jmp 0x606b
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
movq 0x48(%rsp), %rbx
movq 0x18(%rsp), %r13
xorl %ebp, %ebp
xorl %r12d, %r12d
movl $0x0, (%r13,%r12)
movq -0x8(%rbx,%r12,4), %rdi
testq %rdi, %rdi
je 0x6001
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%rbx,%r12,4)
movq (%rbx,%r12,4), %rdi
testq %rdi, %rdi
je 0x601d
movl $0x1, %esi
callq 0x1150
movq $0x0, (%rbx,%r12,4)
addq $0x4, %r12
cmpq $0x400, %r12            # imm = 0x400
jne 0x5fe4
incq %rbp
addq $0x400, %r13            # imm = 0x400
addq $0x1000, %rbx           # imm = 0x1000
cmpq $0x100, %rbp            # imm = 0x100
jne 0x5fe1
leaq 0x2482(%rip), %rsi      # 0x84d5
callq 0x23fa
movq 0x18(%rsp), %r13
movl 0x4(%rsp), %r12d
movq 0x38(%rsp), %rcx
movl 0xc(%rsp), %edx
cmpl $0x186b, %edx           # imm = 0x186B
jb 0x5ad8
jmp 0x6196
movl $0x1866, %r10d          # imm = 0x1866
subl %r9d, %r10d
leal (%r11,%r11), %eax
movl %eax, 0x8(%rsp)
movl $0x1, (%rsp)
movl %edi, %eax
movl 0x8(%rsp), %edi
cmpl %edi, %r10d
setae %cl
cmpl $0xc, %eax
setb %dl
andb %cl, %dl
movl $0x0, %ecx
cmovnel %edi, %ecx
subl %ecx, %r10d
movzbl %dl, %edi
addl %eax, %edi
cmpl %r11d, %r10d
jb 0x5bea
cmpl $0xa, %ebx
movl $0x0, %eax
cmovbl %r11d, %eax
adcl $0x0, %ebx
subl %eax, %r10d
cmpl %r11d, %r10d
jb 0x5bea
cmpl $0x16, %esi
movl $0x0, %eax
cmovbl %r11d, %eax
adcl $0x0, %esi
subl %eax, %r10d
cmpl %r11d, %r10d
jb 0x5bea
movl (%rsp), %r8d
cmpl $0x3c, %r8d
movl $0x0, %eax
cmovbl %r11d, %eax
adcl $0x0, %r8d
subl %eax, %r10d
cmpl %r11d, %r10d
movl %r8d, (%rsp)
jb 0x5bea
cmpl $0xc, %edi
setb %al
cmpl $0xa, %ebx
setb %cl
cmpl $0x16, %esi
setb %dl
orb %cl, %dl
cmpl $0x3c, %r8d
setb %cl
orb %dl, %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x5bea
testl %r10d, %r10d
jne 0x6094
jmp 0x5bea
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x257f(%rip), %rsi      # 0x86e5
jmp 0x59c0
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
movl 0x24(%rsp), %eax
movb %al, 0x145005(%r13)
movl $0x4, 0x141000(%r13)
movb $0x1, 0x145006(%r13)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop