// File: /workspace/github_cpp_makefile_star2_O1/atsidaev[P]trx2x/DiskImage.cpp
// Function: TDiskImage::readFDI(int, bool)
void TDiskImage::readFDI(int hfile, bool readonly)
{
   long fsize = filelength(hfile);
   if(fsize < 0)
   {
      ShowError(ERR_GETLEN);
      return;
   }

   unsigned char *ptr = (unsigned char*)new char[fsize+1024*2048];
   if(!ptr)
   {
      ShowError(ERR_NOMEM);
      return;
   }

   unsigned long rsize = read(hfile, ptr, fsize);
   if(rsize < 14)
   {
      delete ptr;
      ShowError(ERR_CORRUPT);
      return;
   }

   if(memcmp(ptr, "FDI", 3) != 0) 
   {
      delete ptr;
      ShowError(ERR_FORMAT" FDI!");
      return;
   }

// ==========================================
// ********** Analyse FDI header ************...
// ------------------------------------------
   unsigned short *fdihead = (unsigned short*)(ptr+4);
   unsigned int fdiCylCount  = fdihead[0];      // +4
   unsigned int fdiSideCount = fdihead[1];      // +6
//   unsigned int fdiOFFtext   = fdihead[2];      // +8
   unsigned int fdiOFFdata   = fdihead[3];      // +A
   unsigned int fdiSIZEext   = fdihead[4];      // +C

   if((fdiCylCount > 256)||(fdiCylCount == 0))
   {
      delete ptr;
      ShowError(ERR_MANYCYLS);
      return;
   }
   if((fdiSideCount > 256)||(fdiSideCount == 0))
   {
      delete ptr;
      ShowError(ERR_MANYSIDS);
      return;
   }

   MaxTrack = (unsigned char)(fdiCylCount-1);
   MaxSide = (unsigned char)(fdiSideCount-1);

   if(rsize < 0x0E + fdiSIZEext + (unsigned(MaxTrack) + 1) * (unsigned(MaxSide) + 1) * 7 )
   {
      delete ptr;
      ShowError(ERR_CORRUPT);
      return;
   }


   struct FDISECINFO
   {
      unsigned char ADAM[5];
      unsigned int SectorOffset;        // относит DataOffset
   };
   struct FDITRACKHDR
   {
      unsigned int DataOffset;          // относит начала файла
      unsigned int SectorCount;
      FDISECINFO SectorsInfo[256];
   };

   FDITRACKHDR *tracksinfo = new FDITRACKHDR[(unsigned(MaxTrack)+1)*(unsigned(MaxSide)+1)];

   unsigned int fdiOFF = 0x0E + fdiSIZEext;

   unsigned int trk, side;
// Анализ области заголовков треков...
   for(trk=0; trk <= unsigned(MaxTrack); trk++)
      for(side=0; side <= unsigned(MaxSide); side++)
      {
         if(rsize < fdiOFF )
         {
            delete[] tracksinfo;
            delete ptr;
            ShowError(ERR_CORRUPT);
            return;
         }

         tracksinfo[trk*(MaxSide+1)+side].DataOffset = *((uint32_t*)(ptr+fdiOFF));
         fdiOFF+=4;

         if(rsize < fdiOFFdata+tracksinfo[trk*(MaxSide+1)+side].DataOffset )
         {
            delete[] tracksinfo;
            delete ptr;
            ShowError(ERR_CORRUPT);
            return;
         }

         fdiOFF+=2;      // "Всегда содержит 0 (резерв для модернизации)"

         tracksinfo[trk*(MaxSide+1)+side].SectorCount = unsigned(ptr[fdiOFF++]);

         for(unsigned isec=0; isec < tracksinfo[trk*(MaxSide+1)+side].SectorCount; isec++)
         {
            memcpy(tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[isec].ADAM, ptr+fdiOFF,5);
            fdiOFF+=5;
            tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[isec].SectorOffset = unsigned(*((unsigned short*)(ptr+fdiOFF)));
            fdiOFF+=2;

            if(rsize < fdiOFFdata+tracksinfo[trk*(MaxSide+1)+side].DataOffset+tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[isec].SectorOffset )
            {
               delete[] tracksinfo;
               delete ptr;
               ShowError(ERR_CORRUPT);
               return;
            }
         }
      }

// форматирование нового диска и размещение FDI секторов...
   unsigned int ptrcrc;
   unsigned int r;
   unsigned short vgcrc;
   unsigned int trkdatalen;
   unsigned SecCount;
   unsigned SL;

   for(trk=0; trk <= unsigned(MaxTrack); trk++)
      for(side=0; side <= unsigned(MaxSide); 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;         
         }

         SecCount = tracksinfo[trk*(MaxSide+1)+side].SectorCount;

// Вычисляем необходимое число байт под данные:
         trkdatalen = 0;
         for(unsigned int ilsec=0; ilsec < SecCount; ilsec++)
         {
            trkdatalen += 2+6;     // for marks:   0xA1, 0xFE, 6bytes
            SL = unsigned(tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[ilsec].ADAM[3]);
            if(!SL) SL = 128;
            else SL = 128 << SL;

            if(tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[ilsec].ADAM[4] & 0x40)
               SL = 0;          // заголовок без массива данных
            else
               trkdatalen += 4;       // for data header/crc: 0xA1, 0xFB, ...,2bytes

            trkdatalen += SL;
         }

         if(trkdatalen + SecCount*(3+2) > 6250)    // 3x4E & 2x00 per sec checking
         {
            delete[] tracksinfo;
            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;
         for(unsigned sec=0; sec < SecCount; sec++)
         {
            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] = tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].ADAM[0]; // cyl
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].ADAM[1]; // head 
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].ADAM[2]; // secN
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].ADAM[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;
            }

            unsigned char fdiSectorFlags = tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].ADAM[4];

// !!!!!!!!!
// !WARNING! this feature of FDI format is NOT FULL DOCUMENTED!!!
// !!!!!!!!!
//
//  Flags::bit6 - Возможно, 1 в данном разряде
//                будет обозначать адресный маркер без области данных.
//

            if(!(fdiSectorFlags & 0x40)) // 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;
               }
   
               if(fdiSectorFlags & 0x80)
                  FTracksPtr[trk][side][0][tptr] = 0xF8;   // Метка "Удаленные данные"
               else
                  FTracksPtr[trk][side][0][tptr] = 0xFB;   // Метка "Данные"
               FTracksPtr[trk][side][1][tptr++] = 0x00;
   
   
               SL = unsigned(tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].ADAM[3]);
               if(!SL) SL = 128;
               else SL = 128 << SL;
   
               unsigned int secDATAOFF = fdiOFFdata + tracksinfo[trk*(MaxSide+1)+side].DataOffset + tracksinfo[trk*(MaxSide+1)+side].SectorsInfo[sec].SectorOffset;
   
               for(r=0; r < SL; r++)        // сектор SL байт
               {
                  FTracksPtr[trk][side][0][tptr] = ptr[secDATAOFF+r];
                  FTracksPtr[trk][side][1][tptr++] = 0x00;
               }
   
               vgcrc = MakeVGCRC(FTracksPtr[trk][side][0]+ptrcrc, tptr-ptrcrc);
   
   
               if(fdiSectorFlags & 0x3F)        // CRC correct?
               {
                  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;
               }
               else     // oh-oh, high technology... CRC bad... ;-)
               {
                  FTracksPtr[trk][side][0][tptr] = (unsigned char)(vgcrc>>8)^0xFF; // emulation bad CRC... ;)
                  FTracksPtr[trk][side][1][tptr++] = 0x00;
                  FTracksPtr[trk][side][0][tptr] = (unsigned char)(vgcrc&0xFF)^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;
         }
      }

   delete[] tracksinfo;
   delete ptr;
   ReadOnly = readonly;
   FType = DIT_FDI;
   DiskPresent = true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %rbp
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 0x4a11
movq %r12, %rdi
addq $0x200000, %rdi         # imm = 0x200000
callq 0x1030
movq %rax, %r14
movl %r15d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0x11b0
cmpq $0xd, %rax
ja 0x4a1d
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x396a(%rip), %rsi      # 0x8376
jmp 0x4aa2
leaq 0x3940(%rip), %rsi      # 0x8358
jmp 0x4aa2
movq %rax, %r12
movzwl (%r14), %eax
xorl $0x4446, %eax           # imm = 0x4446
movzbl 0x2(%r14), %ecx
xorl $0x49, %ecx
orw %ax, %cx
je 0x4a4c
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x3a09(%rip), %rsi      # 0x8453
jmp 0x4aa2
movzwl 0x4(%r14), %eax
leal -0x101(%rax), %ecx
movzwl %cx, %ecx
cmpl $0xfeff, %ecx           # imm = 0xFEFF
ja 0x4a78
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x39fa(%rip), %rsi      # 0x8470
jmp 0x4aa2
movzwl 0x6(%r14), %ecx
leal -0x101(%rcx), %edx
movzwl %dx, %edx
cmpl $0xfeff, %edx           # imm = 0xFEFF
ja 0x4ab8
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x3a02(%rip), %rsi      # 0x84a4
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x23fa
movl %ebx, 0x48(%rsp)
movzwl 0xa(%r14), %esi
movzwl 0xc(%r14), %r13d
decb %al
movb %al, 0x145007(%rbp)
decb %cl
movb %cl, 0x145008(%rbp)
movzbl %al, %edx
incl %edx
movzbl %cl, %eax
incl %eax
imull %edx, %eax
leal (,%rax,8), %ecx
subl %eax, %ecx
addl %r13d, %ecx
addl $0xe, %ecx
cmpq %rcx, %r12
jb 0x49f8
addl $0xe, %r13d
imull $0xc08, %eax, %edi      # imm = 0xC08
movl %esi, 0x10(%rsp)
callq 0x1030
movl 0x10(%rsp), %r8d
movq %rax, %rdi
leaq 0x10(%rax), %r10
xorl %r11d, %r11d
movq %rbp, 0x28(%rsp)
movq %rax, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movzbl 0x145008(%rbp), %ecx
xorl %r15d, %r15d
movl %r13d, %r13d
cmpq %r13, %r12
jb 0x53a8
movl (%r14,%r13), %edx
incl %ecx
imull %r11d, %ecx
addl %r15d, %ecx
imulq $0xc08, %rcx, %rax      # imm = 0xC08
movl %edx, (%rdi,%rax)
addl %r8d, %edx
cmpq %rdx, %r12
jb 0x53a8
addq %rdi, %rax
leal 0x6(%r13), %edx
addl $0x7, %r13d
movzbl (%r14,%rdx), %edx
movl %edx, 0x4(%rax)
testl %edx, %edx
setne %bl
je 0x4c0f
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
addq %r10, %rcx
xorl %edx, %edx
movl %r13d, %ebp
movl %r13d, %esi
movb 0x4(%r14,%rsi), %r9b
movb %r9b, -0x4(%rcx)
movl (%r14,%rsi), %esi
movl %esi, -0x8(%rcx)
leal 0x5(%rbp), %esi
movzwl (%r14,%rsi), %esi
movl %esi, (%rcx)
movl (%rax), %r9d
addl %r8d, %r9d
addl %esi, %r9d
cmpq %r9, %r12
jb 0x4bd1
incl %edx
addq $0xc, %rcx
leal 0x7(%rbp), %r13d
cmpl 0x4(%rax), %edx
setb %bl
jb 0x4b8f
jmp 0x4c04
movq %r11, %r13
callq 0x1180
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x3789(%rip), %rsi      # 0x8376
callq 0x23fa
movq %r13, %r11
movq 0x20(%rsp), %r10
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %r8d
addl $0x7, %ebp
movl %ebp, %r13d
movq 0x28(%rsp), %rbp
testb $0x1, %bl
jne 0x5396
leal 0x1(%r15), %eax
movzbl 0x145008(%rbp), %ecx
cmpl %ecx, %r15d
movl %eax, %r15d
jb 0x4b36
leal 0x1(%r11), %eax
movzbl 0x145007(%rbp), %ecx
cmpl %ecx, %r11d
movl %eax, %r11d
jb 0x4b2c
leaq 0x40000(%rbp), %rax
xorl %r12d, %r12d
movq $0x0, 0x58(%rsp)
xorl %r8d, %r8d
movq %rax, 0x70(%rsp)
movq %r8, %rcx
shlq $0xa, %rcx
addq %rbp, %rcx
movq %rcx, 0x80(%rsp)
movq %r8, %rcx
shlq $0xc, %rcx
addq %rax, %rcx
movq %rcx, 0x78(%rsp)
movq %rdi, 0x60(%rsp)
xorl %ecx, %ecx
movq %r8, 0x30(%rsp)
movq 0x80(%rsp), %rax
movl $0x186a, (%rax,%rcx,4)  # imm = 0x186A
movl $0x1c6a, %edi           # imm = 0x1C6A
movq %rcx, %rbx
callq 0x1030
movq %rbx, 0x38(%rsp)
shlq $0x4, %rbx
movq 0x78(%rsp), %r13
leaq (%rbx,%r13), %r15
movq %rax, (%rbx,%r13)
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movq %rax, 0x8(%rbx,%r13)
xorl %eax, %eax
movq (%r15), %rcx
movb %r12b, (%rcx,%rax)
movq 0x8(%r15), %rcx
movb %r12b, (%rcx,%rax)
incq %rax
cmpq $0x186a, %rax           # imm = 0x186A
jne 0x4cd1
movzbl 0x145008(%rbp), %eax
incq %rax
movq %rax, %rcx
imulq 0x30(%rsp), %rcx
addq 0x38(%rsp), %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
movq 0x18(%rsp), %rdi
movl 0x4(%rdi,%rcx), %r10d
testq %r10, %r10
je 0x4d67
imulq 0x58(%rsp), %rax
addq 0x60(%rsp), %rax
leaq (,%r10,4), %rcx
leaq (%rcx,%rcx,2), %rsi
xorl %r9d, %r9d
xorl %edx, %edx
movb 0xb(%rax,%r9), %cl
movl $0x80, %r8d
shll %cl, %r8d
xorl %ecx, %ecx
testb $0x40, 0xc(%rax,%r9)
sete %cl
cmovnel %r12d, %r8d
leal (%rdx,%rcx,4), %ecx
leal (%r8,%rcx), %edx
addl $0x8, %edx
addq $0xc, %r9
cmpq %r9, %rsi
jne 0x4d35
jmp 0x4d69
xorl %edx, %edx
leal (%r10,%r10,4), %esi
addl %edx, %esi
cmpl $0x186a, %esi           # imm = 0x186A
ja 0x53b2
movl $0x1, %r11d
xorl %ecx, %ecx
movl $0x0, %eax
movl $0x1, %ebx
movl $0x1, %r8d
movl $0x1, %r13d
cmpl $0x1866, %esi           # imm = 0x1866
je 0x4e65
movl $0x1866, %eax           # imm = 0x1866
subl %esi, %eax
leal (%r10,%r10), %edx
movl %r8d, %r9d
movl %r13d, %esi
cmpl %edx, %eax
setae %dil
cmpl $0xc, %r13d
setb %r8b
andb %dil, %r8b
movl $0x0, %edi
cmovnel %edx, %edi
subl %edi, %eax
movzbl %r8b, %r13d
addl %esi, %r13d
cmpl %r10d, %eax
jb 0x4e62
cmpl $0xa, %r11d
movl $0x0, %esi
cmovbl %r10d, %esi
adcl $0x0, %r11d
subl %esi, %eax
cmpl %r10d, %eax
jb 0x4e62
cmpl $0x16, %ebx
movl $0x0, %esi
cmovbl %r10d, %esi
adcl $0x0, %ebx
subl %esi, %eax
cmpl %r10d, %eax
movl %r9d, %r8d
jb 0x4e65
cmpl $0x3c, %r8d
movl $0x0, %esi
cmovbl %r10d, %esi
adcl $0x0, %r8d
subl %esi, %eax
cmpl %r10d, %eax
jb 0x4e65
cmpl $0xc, %r13d
setb %sil
cmpl $0xa, %r11d
setb %dil
cmpl $0x16, %ebx
setb %r9b
orb %dil, %r9b
cmpl $0x3c, %r8d
setb %dil
orb %r9b, %dil
orb %sil, %dil
cmpb $0x1, %dil
jne 0x4e65
testl %eax, %eax
jne 0x4db0
jmp 0x4e65
movl %r9d, %r8d
movl %r8d, %edx
testq %r10, %r10
movq 0x30(%rsp), %r8
je 0x52f7
leal 0xa(,%r10,2), %ecx
movq $0x0, 0x20(%rsp)
xorl %esi, %esi
cmpl %ecx, %eax
seta %sil
movl $0x0, %ecx
cmoval %r10d, %ecx
subl %ecx, %eax
leal 0x9(,%r10,2), %ecx
cmpl %eax, %ecx
adcl $0x0, %esi
cmpl $0x1, %r11d
adcl $0x0, %r11d
movl %r11d, 0x54(%rsp)
cmpl $0x1, %r13d
adcl $0x0, %r13d
leal 0x1(%rsi), %eax
cmpl $0x1, %eax
adcl $0x1, %esi
movq %rsi, 0x68(%rsp)
leal 0x5(%rsi), %r11d
cmpl $0x1, %ebx
adcl $0x0, %ebx
movl %ebx, 0x50(%rsp)
cmpl $0x1, %edx
adcl $0x0, %edx
movl %edx, 0x4c(%rsp)
xorl %ecx, %ecx
movq %r10, 0x40(%rsp)
movl %r13d, 0x14(%rsp)
leal 0x9(%rcx), %edx
leal 0xd(%rcx), %r9d
movl 0x54(%rsp), %eax
movl %edx, %esi
movl %r9d, %edi
movq (%r15), %rdx
movl %ecx, %r9d
movb $0x4e, (%rdx,%r9)
movq 0x8(%r15), %rdx
incl %ecx
movb $0x0, (%rdx,%r9)
leal 0x1(%rsi), %edx
leal 0x1(%rdi), %r9d
decl %eax
jne 0x4ef9
xorl %ebx, %ebx
movl %esi, %eax
movl %edi, %edx
leal (%rcx,%rbx), %esi
movq (%r15), %rdi
movb %r12b, (%rdi,%rsi)
movq 0x8(%r15), %rdi
movb %r12b, (%rdi,%rsi)
incl %ebx
leal 0x1(%rax), %esi
leal 0x1(%rdx), %edi
cmpl %ebx, %r13d
jne 0x4f21
addl %ebx, %ecx
xorl %ebx, %ebx
movq 0x68(%rsp), %r9
movl %eax, %esi
movl %edx, %edi
leal -0x7(%rsi), %eax
movq (%r15), %rdx
movb $-0x5f, (%rdx,%rax)
movq 0x8(%r15), %rdx
movb $-0x1, (%rdx,%rax)
incl %ebx
leal 0x1(%rsi), %eax
leal 0x1(%rdi), %edx
cmpl %ebx, %r9d
jne 0x4f4d
movq (%r15), %rdx
leal -0x7(%rax), %r9d
movb $-0x2, (%rdx,%r9)
movq 0x8(%r15), %rdx
leal -0x6(%rax), %ebx
movb %r12b, (%rdx,%r9)
movzbl 0x145008(%rbp), %edx
incq %rdx
imulq %r8, %rdx
movq 0x38(%rsp), %r10
addq %r10, %rdx
imulq $0xc08, %rdx, %r9       # imm = 0xC08
movq %rbp, %r8
movq 0x18(%rsp), %rbp
addq %rbp, %r9
movq 0x20(%rsp), %rdx
leaq (,%rdx,4), %rdx
leaq (%rdx,%rdx,2), %rdx
movb 0x8(%r9,%rdx), %r9b
movq (%r15), %r13
movb %r9b, (%r13,%rbx)
movq 0x8(%r15), %r9
leal -0x5(%rax), %r13d
movb %r12b, (%r9,%rbx)
movzbl 0x145008(%r8), %r9d
incq %r9
imulq 0x30(%rsp), %r9
addq %r10, %r9
imulq $0xc08, %r9, %r9        # imm = 0xC08
addq %rbp, %r9
movb 0x9(%r9,%rdx), %r9b
movq (%r15), %rbx
movb %r9b, (%rbx,%r13)
movq 0x8(%r15), %r9
leal -0x4(%rax), %ebx
movb %r12b, (%r9,%r13)
movzbl 0x145008(%r8), %r9d
incq %r9
imulq 0x30(%rsp), %r9
addq %r10, %r9
imulq $0xc08, %r9, %r9        # imm = 0xC08
addq %rbp, %r9
movb 0xa(%r9,%rdx), %r9b
movq (%r15), %r13
movb %r9b, (%r13,%rbx)
movq 0x8(%r15), %r9
leal -0x3(%rax), %r13d
movb %r12b, (%r9,%rbx)
movzbl 0x145008(%r8), %r9d
movq 0x30(%rsp), %r8
incq %r9
imulq %r8, %r9
addq %r10, %r9
imulq $0xc08, %r9, %r9        # imm = 0xC08
addq %rbp, %r9
movb 0xb(%r9,%rdx), %dl
movq (%r15), %r9
movb %dl, (%r9,%r13)
movq 0x8(%r15), %rdx
leal -0x2(%rax), %r9d
movl %r9d, 0xc(%rsp)
movb %r12b, (%rdx,%r13)
movq (%r15), %rdx
movl %ecx, %r13d
movq %rdx, %r10
addq %rdx, %r13
movw $0xffff, %cx            # imm = 0xFFFF
xorl %ebp, %ebp
movzbl (%r13,%rbp), %r9d
shll $0x8, %r9d
xorl %r9d, %ecx
movl $0x8, %r9d
leal (%rcx,%rcx), %edx
movl %edx, %ebx
xorl $0x1021, %ebx           # imm = 0x1021
testw %cx, %cx
cmovnsl %edx, %ebx
movl %ebx, %ecx
decl %r9d
jne 0x50a8
incq %rbp
cmpq %r11, %rbp
jne 0x5095
movl 0xc(%rsp), %edx
movq %r10, %rbx
movb %ch, (%rbx,%rdx)
movq 0x8(%r15), %r9
movb %r12b, (%r9,%rdx)
movq (%r15), %rdx
movl %esi, %esi
movb %cl, (%rdx,%rsi)
movq 0x8(%r15), %rcx
movb %r12b, (%rcx,%rsi)
movl 0x50(%rsp), %edx
movl %edi, %ecx
movq (%r15), %rsi
movl %eax, %edi
movb $0x4e, (%rsi,%rdi)
movq 0x8(%r15), %rsi
incl %eax
movb $0x0, (%rsi,%rdi)
leal 0x1(%rcx), %edi
decl %edx
jne 0x50ee
movl 0x14(%rsp), %r13d
movl %r13d, %edx
movq 0x28(%rsp), %rbp
movl %ecx, %edi
movq (%r15), %rcx
movl %eax, %esi
movb %r12b, (%rcx,%rsi)
movq 0x8(%r15), %rcx
incl %eax
movb %r12b, (%rcx,%rsi)
leal 0x1(%rdi), %ecx
decl %edx
jne 0x5117
movzbl 0x145008(%rbp), %ecx
incq %rcx
imulq %r8, %rcx
movq 0x38(%rsp), %rsi
addq %rsi, %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
addq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdx
leaq (%rdx,%rdx,2), %rbx
movzbl 0xc(%rcx,%rbx,4), %ecx
movl %ecx, 0xc(%rsp)
testb $0x40, %cl
jne 0x5284
movq 0x68(%rsp), %rcx
movl %edi, %edx
leal -0x1(%rdx), %edi
movq (%r15), %r9
movb $-0x5f, (%r9,%rdi)
movq 0x8(%r15), %r9
movb $-0x1, (%r9,%rdi)
leal 0x1(%rdx), %edi
decl %ecx
jne 0x5175
xorl %ecx, %ecx
cmpb $0x0, 0xc(%rsp)
movq (%r15), %r9
movl %edx, %r13d
setns %cl
leal 0xf8(%rcx,%rcx,2), %ecx
movb %cl, (%r9,%r13)
movq 0x8(%r15), %rcx
movb $0x0, (%rcx,%r13)
movzbl 0x145008(%rbp), %ecx
incq %rcx
imulq %r8, %rcx
addq %rsi, %rcx
imulq $0xc08, %rcx, %r9       # imm = 0xC08
movq 0x18(%rsp), %rsi
leaq (%rsi,%r9), %r13
movzbl 0xb(%r13,%rbx,4), %ecx
cmpl $0x18, %ecx
ja 0x521f
movl $0x80, %edi
shll %cl, %edi
cmpl $0x1, %edi
adcl $0x0, %edi
movl 0x10(%r13,%rbx,4), %ecx
addl 0x10(%rsp), %ecx
addl (%rsi,%r9), %ecx
incl %edx
movl %ecx, %r9d
movb (%r14,%r9), %r9b
movq (%r15), %rbx
movb %r9b, (%rbx,%rdx)
movq 0x8(%r15), %r9
movb $0x0, (%r9,%rdx)
incl %ecx
decq %rdi
jne 0x51fc
leal 0x1(%rdx), %edi
movq (%r15), %r10
movw $0xffff, %cx            # imm = 0xFFFF
movl %edi, %r13d
subl %eax, %r13d
je 0x526b
movl %eax, %eax
addq %r10, %rax
movw $0xffff, %cx            # imm = 0xFFFF
xorl %ebp, %ebp
movzbl (%rax,%rbp), %r9d
shll $0x8, %r9d
xorl %r9d, %ecx
movl $0x8, %r9d
leal (%rcx,%rcx), %esi
movl %esi, %ebx
xorl $0x1021, %ebx           # imm = 0x1021
testw %cx, %cx
cmovnsl %esi, %ebx
movl %ebx, %ecx
decl %r9d
jne 0x524b
incq %rbp
cmpq %r13, %rbp
jb 0x5239
movl %edi, %eax
testb $0x3f, 0xc(%rsp)
je 0x528b
movq %r10, %rsi
movb %ch, (%rsi,%rax)
movq 0x8(%r15), %rsi
movb $0x0, (%rsi,%rax)
jmp 0x529f
movq 0x40(%rsp), %r10
jmp 0x52c4
movl %ecx, %ebx
notl %ebx
movq %r10, %rsi
movb %bh, (%rsi,%rax)
movq 0x8(%r15), %rsi
movb $0x0, (%rsi,%rax)
notb %cl
movq 0x28(%rsp), %rbp
movl 0x14(%rsp), %r13d
movq 0x40(%rsp), %r10
leal 0x2(%rdx), %eax
movq (%r15), %rsi
movb %cl, (%rsi,%rax)
movq 0x8(%r15), %rcx
movb $0x0, (%rcx,%rax)
addl $0x3, %edx
movl %edx, %eax
movl 0x4c(%rsp), %edx
movl %eax, %ecx
movq (%r15), %rax
movl %ecx, %esi
movb $0x4e, (%rax,%rsi)
movq 0x8(%r15), %rax
incl %ecx
movb $0x0, (%rax,%rsi)
decl %edx
jne 0x52ca
movq 0x20(%rsp), %rdx
incq %rdx
movq %rdx, 0x20(%rsp)
cmpq %r10, %rdx
jne 0x4eee
cmpl $0x1869, %ecx           # imm = 0x1869
movq 0x38(%rsp), %rsi
jg 0x531f
movq (%r15), %rax
movl %ecx, %edx
movb $0x4e, (%rax,%rdx)
movq 0x8(%r15), %rax
incl %ecx
movb $0x0, (%rax,%rdx)
cmpl $0x186a, %ecx           # imm = 0x186A
jne 0x5304
leaq 0x1(%rsi), %rax
movzbl 0x145008(%rbp), %ecx
addq $0xc08, 0x60(%rsp)      # imm = 0xC08
cmpq %rcx, %rsi
movq %rax, %rcx
jb 0x4c8e
leaq 0x1(%r8), %rax
movzbl 0x145007(%rbp), %ecx
addq $0xc08, 0x58(%rsp)      # imm = 0xC08
cmpq %rcx, %r8
movq %rax, %r8
movq 0x18(%rsp), %rdi
movq 0x70(%rsp), %rax
jb 0x4c61
callq 0x1180
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
movl 0x48(%rsp), %eax
movb %al, 0x145005(%rbp)
movl $0x3, 0x141000(%rbp)
movb $0x1, 0x145006(%rbp)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1180
jmp 0x49f8
callq 0x1180
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x40008(%rbp), %rbx
xorl %r14d, %r14d
xorl %r15d, %r15d
movl $0x0, (%rbp,%r15)
movq -0x8(%rbx,%r15,4), %rdi
testq %rdi, %rdi
je 0x53ee
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%rbx,%r15,4)
movq (%rbx,%r15,4), %rdi
testq %rdi, %rdi
je 0x540a
movl $0x1, %esi
callq 0x1150
movq $0x0, (%rbx,%r15,4)
addq $0x4, %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x53d1
incq %r14
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %rbx           # imm = 0x1000
cmpq $0x100, %r14            # imm = 0x100
jne 0x53ce
leaq 0x3095(%rip), %rsi      # 0x84d5
jmp 0x4aa2
nop