// File: /workspace/github_cpp_makefile_star2_O3/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, %ebp
movl %esi, %r15d
movq %rdi, %rbx
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 0x4a17
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 0x4a23
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x39c0(%rip), %rsi      # 0x83d2
jmp 0x4aa8
leaq 0x3996(%rip), %rsi      # 0x83b4
jmp 0x4aa8
movq %rax, %r12
movzwl (%r14), %eax
xorl $0x4446, %eax           # imm = 0x4446
movzbl 0x2(%r14), %ecx
xorl $0x49, %ecx
orw %ax, %cx
je 0x4a52
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x3a5f(%rip), %rsi      # 0x84af
jmp 0x4aa8
movzwl 0x4(%r14), %eax
leal -0x101(%rax), %ecx
movzwl %cx, %ecx
cmpl $0xfeff, %ecx           # imm = 0xFEFF
ja 0x4a7e
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x3a50(%rip), %rsi      # 0x84cc
jmp 0x4aa8
movzwl 0x6(%r14), %ecx
leal -0x101(%rcx), %edx
movzwl %dx, %edx
cmpl $0xfeff, %edx           # imm = 0xFEFF
ja 0x4abe
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x3a58(%rip), %rsi      # 0x8500
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2410
movl %ebp, 0x4c(%rsp)
movzwl 0xa(%r14), %edx
movl %edx, 0x3c(%rsp)
movzwl 0xc(%r14), %r13d
decb %al
movb %al, 0x145007(%rbx)
decb %cl
movq %rbx, 0x28(%rsp)
movb %cl, 0x145008(%rbx)
movzbl %al, %ebp
incl %ebp
movzbl %cl, %r15d
leal 0x1(%r15), %ebx
movl %ebx, %eax
imull %ebp, %eax
leal (,%rax,8), %ecx
subl %eax, %ecx
addl %r13d, %ecx
addl $0xe, %ecx
cmpq %rcx, %r12
jb 0x49fe
addl $0xe, %r13d
imull $0xc08, %eax, %edi      # imm = 0xC08
callq 0x1030
movl %ebx, %edi
movl %ebp, %ecx
movq %rcx, 0x10(%rsp)
leaq 0x10(%rax), %rdx
imulq $0xc08, %r15, %rsi      # imm = 0xC08
addq $0xc08, %rsi            # imm = 0xC08
xorl %r8d, %r8d
movq %rax, 0x18(%rsp)
movq %r8, 0x8(%rsp)
imulq %rdi, %r8
movq %rdx, 0x30(%rsp)
xorl %r10d, %r10d
movl %r13d, %r13d
cmpq %r13, %r12
jb 0x53c5
movl (%r14,%r13), %r11d
leaq (%r8,%r10), %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
movl %r11d, (%rax,%rcx)
addl 0x3c(%rsp), %r11d
cmpq %r11, %r12
jb 0x53c5
addq %rax, %rcx
leal 0x6(%r13), %r9d
movzbl (%r14,%r9), %r15d
addl $0x7, %r13d
movl %r15d, 0x4(%rcx)
testl %r15d, %r15d
je 0x4bd9
movq %rdx, %r9
xorl %ecx, %ecx
movl %r13d, %ebx
movb 0x4(%r14,%rbx), %bpl
movb %bpl, -0x4(%r9)
movl (%r14,%rbx), %ebx
movl %ebx, -0x8(%r9)
leal 0x5(%r13), %ebx
movzwl (%r14,%rbx), %ebx
movl %ebx, (%r9)
addl %r11d, %ebx
cmpq %rbx, %r12
jb 0x53b6
incq %rcx
addl $0x7, %r13d
addq $0xc, %r9
cmpq %r15, %rcx
jb 0x4b9d
incq %r10
addq $0xc08, %rdx            # imm = 0xC08
cmpq %rdi, %r10
movq 0x18(%rsp), %rax
jne 0x4b52
movq 0x8(%rsp), %r8
incq %r8
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
cmpq 0x10(%rsp), %r8
jne 0x4b41
movq 0x28(%rsp), %rax
addq $0x40000, %rax          # imm = 0x40000
movq %rax, 0x68(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x50(%rsp)
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, %rcx
shlq $0xa, %rcx
movq 0x28(%rsp), %rbp
addq %rbp, %rcx
movq %rcx, 0x78(%rsp)
shlq $0xc, %rax
addq 0x68(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
xorl %ecx, %ecx
movq 0x78(%rsp), %rax
movl $0x186a, (%rax,%rcx,4)  # imm = 0x186A
movl $0x1c6a, %edi           # imm = 0x1C6A
movq %rcx, %rbx
callq 0x1030
movq %rbx, 0x10(%rsp)
shlq $0x4, %rbx
movq 0x70(%rsp), %r15
leaq (%r15,%rbx), %r13
movq %rax, (%rbx,%r15)
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movq %rax, 0x8(%rbx,%r15)
xorl %eax, %eax
movq (%r13), %rcx
movb %r12b, (%rcx,%rax)
movq 0x8(%r13), %rcx
movb %r12b, (%rcx,%rax)
incq %rax
cmpq $0x186a, %rax           # imm = 0x186A
jne 0x4ca4
movzbl 0x145008(%rbp), %eax
incq %rax
movq %rax, %rcx
imulq 0x8(%rsp), %rcx
addq 0x10(%rsp), %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
movq 0x18(%rsp), %rdi
movl 0x4(%rdi,%rcx), %r10d
testq %r10, %r10
je 0x4d3b
imulq 0x50(%rsp), %rax
addq 0x58(%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 0x4d09
jmp 0x4d3d
xorl %edx, %edx
leal (%r10,%r10,4), %ecx
addl %edx, %ecx
cmpl $0x186a, %ecx           # imm = 0x186A
ja 0x53ca
movq %rbp, %r15
cmpl $0x1866, %ecx           # imm = 0x1866
jne 0x5228
leal (%r10,%r10), %ecx
movl $0x1, %r9d
xorl %eax, %eax
movl $0x1, %ebx
movl $0x1, %ebp
movl $0x1, %r11d
movq 0x10(%rsp), %r8
testq %r10, %r10
je 0x5304
leal 0xa(%rcx), %edx
movq $0x0, 0x30(%rsp)
xorl %esi, %esi
cmpl %edx, %eax
seta %sil
movl $0x0, %edx
cmoval %r10d, %edx
subl %edx, %eax
addl $0x9, %ecx
cmpl %eax, %ecx
adcl $0x0, %esi
cmpl $0x1, %r9d
adcl $0x0, %r9d
movl %r9d, 0x48(%rsp)
leal 0x1(%rsi), %eax
movl %eax, 0x38(%rsp)
cmpl $0x1, %r11d
adcl $0x0, %r11d
addl $0x6, %esi
movq %rsi, 0x80(%rsp)
cmpl $0x1, %ebx
adcl $0x0, %ebx
movl %ebx, 0x44(%rsp)
cmpl $0x1, %ebp
adcl $0x0, %ebp
xorl %ecx, %ecx
movq %r10, 0x60(%rsp)
movl %ebp, 0x20(%rsp)
movl %r11d, 0x40(%rsp)
leal 0x9(%rcx), %edx
leal 0xd(%rcx), %r9d
movl 0x48(%rsp), %eax
movl %edx, %esi
movl %r9d, %edi
movq (%r13), %rdx
movl %ecx, %r9d
movb $0x4e, (%rdx,%r9)
movq 0x8(%r13), %rdx
incl %ecx
movb $0x0, (%rdx,%r9)
leal 0x1(%rsi), %edx
leal 0x1(%rdi), %r9d
decl %eax
jne 0x4e01
xorl %r9d, %r9d
movl %esi, %eax
movl %edi, %edx
leal (%rcx,%r9), %esi
movq (%r13), %rdi
movb %r12b, (%rdi,%rsi)
movq 0x8(%r13), %rdi
movb %r12b, (%rdi,%rsi)
incl %r9d
leal 0x1(%rax), %esi
leal 0x1(%rdx), %edi
cmpl %r9d, %r11d
jne 0x4e2b
addl %r9d, %ecx
xorl %r9d, %r9d
movl 0x38(%rsp), %r8d
movl %eax, %esi
movl %edx, %edi
leal -0x7(%rsi), %eax
movq (%r13), %rdx
movb $-0x5f, (%rdx,%rax)
movq 0x8(%r13), %rdx
movb $-0x1, (%rdx,%rax)
incl %r9d
leal 0x1(%rsi), %eax
leal 0x1(%rdi), %edx
cmpl %r9d, %r8d
jne 0x4e5c
movq (%r13), %rdx
leal -0x7(%rax), %r9d
movb $-0x2, (%rdx,%r9)
movq 0x8(%r13), %rdx
leal -0x6(%rax), %ebx
movb %r12b, (%rdx,%r9)
movq %r15, %r11
movzbl 0x145008(%r15), %edx
incq %rdx
movq 0x8(%rsp), %r10
imulq %r10, %rdx
movq 0x10(%rsp), %r8
addq %r8, %rdx
imulq $0xc08, %rdx, %r9       # imm = 0xC08
movq 0x18(%rsp), %rbp
addq %rbp, %r9
movq 0x30(%rsp), %rdx
leaq (,%rdx,4), %rdx
leaq (%rdx,%rdx,2), %rdx
movb 0x8(%r9,%rdx), %r9b
movq (%r13), %r15
movb %r9b, (%r15,%rbx)
movq 0x8(%r13), %r9
leal -0x5(%rax), %r15d
movb %r12b, (%r9,%rbx)
movzbl 0x145008(%r11), %r9d
incq %r9
imulq %r10, %r9
addq %r8, %r9
imulq $0xc08, %r9, %r9        # imm = 0xC08
addq %rbp, %r9
movb 0x9(%r9,%rdx), %r9b
movq (%r13), %rbx
movb %r9b, (%rbx,%r15)
movq 0x8(%r13), %r9
leal -0x4(%rax), %ebx
movb %r12b, (%r9,%r15)
movzbl 0x145008(%r11), %r9d
incq %r9
imulq %r10, %r9
addq %r8, %r9
imulq $0xc08, %r9, %r9        # imm = 0xC08
addq %rbp, %r9
movb 0xa(%r9,%rdx), %r9b
movq (%r13), %r15
movb %r9b, (%r15,%rbx)
movq 0x8(%r13), %r9
leal -0x3(%rax), %r15d
movb %r12b, (%r9,%rbx)
movzbl 0x145008(%r11), %r9d
incq %r9
imulq %r10, %r9
addq %r8, %r9
imulq $0xc08, %r9, %r9        # imm = 0xC08
addq %rbp, %r9
movb 0xb(%r9,%rdx), %dl
movq (%r13), %r9
movb %dl, (%r9,%r15)
movq 0x8(%r13), %rdx
leal -0x2(%rax), %r8d
movl %r8d, 0x24(%rsp)
movb %r12b, (%rdx,%r15)
movq (%r13), %rdx
movl %ecx, %r9d
movq %rdx, %r8
addq %rdx, %r9
movw $0xffff, %cx            # imm = 0xFFFF
xorl %r15d, %r15d
movl 0x40(%rsp), %r11d
movq 0x80(%rsp), %r10
movzbl (%r9,%r15), %ebx
shll $0x8, %ebx
xorl %ebx, %ecx
movl $0x8, %ebx
leal (%rcx,%rcx), %edx
movl %edx, %ebp
xorl $0x1021, %ebp           # imm = 0x1021
testw %cx, %cx
cmovnsl %edx, %ebp
movl %ebp, %ecx
decl %ebx
jne 0x4fc4
incq %r15
cmpq %r10, %r15
jne 0x4fb5
movl 0x24(%rsp), %edx
movq %r8, %rbx
movb %ch, (%rbx,%rdx)
movq 0x8(%r13), %r9
movb %r12b, (%r9,%rdx)
movq (%r13), %rdx
movl %esi, %esi
movb %cl, (%rdx,%rsi)
movq 0x8(%r13), %rcx
movb %r12b, (%rcx,%rsi)
movl 0x44(%rsp), %edx
movl %edi, %ecx
movq (%r13), %rsi
movl %eax, %edi
movb $0x4e, (%rsi,%rdi)
movq 0x8(%r13), %rsi
incl %eax
movb $0x0, (%rsi,%rdi)
leal 0x1(%rcx), %edi
decl %edx
jne 0x500a
movl %r11d, %edx
movq 0x28(%rsp), %rbp
movq 0x18(%rsp), %r9
movq 0x60(%rsp), %r10
movq 0x10(%rsp), %r8
movl %ecx, %edi
movq (%r13), %rcx
movl %eax, %esi
movb %r12b, (%rcx,%rsi)
movq 0x8(%r13), %rcx
incl %eax
movb %r12b, (%rcx,%rsi)
leal 0x1(%rdi), %ecx
decl %edx
jne 0x503e
movzbl 0x145008(%rbp), %ecx
incq %rcx
imulq 0x8(%rsp), %rcx
addq %r8, %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
addq %r9, %rcx
movq 0x30(%rsp), %rdx
leaq (%rdx,%rdx,2), %r15
movzbl 0xc(%rcx,%r15,4), %esi
testb $0x40, %sil
jne 0x51a3
movl 0x38(%rsp), %ecx
movl %edi, %edx
leal -0x1(%rdx), %edi
movq (%r13), %r9
movb $-0x5f, (%r9,%rdi)
movq 0x8(%r13), %r9
movb $-0x1, (%r9,%rdi)
leal 0x1(%rdx), %edi
decl %ecx
jne 0x5095
xorl %ecx, %ecx
movl %esi, 0x24(%rsp)
testb %sil, %sil
movq (%r13), %r9
movl %edx, %ebx
setns %cl
leal 0xf8(%rcx,%rcx,2), %ecx
movb %cl, (%r9,%rbx)
movq 0x8(%r13), %rcx
movb $0x0, (%rcx,%rbx)
movzbl 0x145008(%rbp), %ecx
incq %rcx
imulq 0x8(%rsp), %rcx
addq %r8, %rcx
imulq $0xc08, %rcx, %r9       # imm = 0xC08
movq 0x18(%rsp), %rsi
leaq (%rsi,%r9), %rbx
movzbl 0xb(%rbx,%r15,4), %ecx
cmpq $0x18, %rcx
ja 0x5140
movl $0x80, %edi
shlq %cl, %rdi
movl 0x10(%rbx,%r15,4), %ecx
addl 0x3c(%rsp), %ecx
addl (%rsi,%r9), %ecx
incl %edx
movl %ecx, %r9d
movb (%r14,%r9), %r9b
movq (%r13), %rbx
movb %r9b, (%rbx,%rdx)
movq 0x8(%r13), %r9
movb $0x0, (%r9,%rdx)
incl %ecx
decq %rdi
jne 0x511c
leal 0x1(%rdx), %edi
movq (%r13), %r10
movw $0xffff, %cx            # imm = 0xFFFF
movl %edi, %r15d
subl %eax, %r15d
je 0x518a
movl %eax, %eax
addq %r10, %rax
movw $0xffff, %cx            # imm = 0xFFFF
xorl %r9d, %r9d
movzbl (%rax,%r9), %ebx
shll $0x8, %ebx
xorl %ebx, %ecx
movl $0x8, %ebx
leal (%rcx,%rcx), %esi
movl %esi, %ebp
xorl $0x1021, %ebp           # imm = 0x1021
testw %cx, %cx
cmovnsl %esi, %ebp
movl %ebp, %ecx
decl %ebx
jne 0x516b
incq %r9
cmpq %r15, %r9
jb 0x515c
movl %edi, %eax
testb $0x3f, 0x24(%rsp)
je 0x51ac
movq %r10, %rsi
movb %ch, (%rsi,%rax)
movq 0x8(%r13), %rsi
movb $0x0, (%rsi,%rax)
jmp 0x51c0
movq %rbp, %r15
movl 0x20(%rsp), %ebp
jmp 0x51e5
movl %ecx, %ebx
notl %ebx
movq %r10, %rsi
movb %bh, (%rsi,%rax)
movq 0x8(%r13), %rsi
movb $0x0, (%rsi,%rax)
notb %cl
movq 0x28(%rsp), %r15
movl 0x20(%rsp), %ebp
leal 0x2(%rdx), %eax
movq (%r13), %rsi
movb %cl, (%rsi,%rax)
movq 0x8(%r13), %rcx
movb $0x0, (%rcx,%rax)
addl $0x3, %edx
movl %edx, %eax
movq 0x60(%rsp), %r10
movl %ebp, %edx
movl %eax, %ecx
movq (%r13), %rax
movl %ecx, %esi
movb $0x4e, (%rax,%rsi)
movq 0x8(%r13), %rax
incl %ecx
movb $0x0, (%rax,%rsi)
decl %edx
jne 0x51e9
movq 0x30(%rsp), %rdx
incq %rdx
movq %rdx, 0x30(%rsp)
cmpq %r10, %rdx
jne 0x4df6
cmpl $0x1869, %ecx           # imm = 0x1869
jle 0x5306
jmp 0x5322
movl $0x1866, %eax           # imm = 0x1866
subl %ecx, %eax
leal (%r10,%r10), %ecx
movl $0x1, %r9d
movl $0x1, %ebx
movl $0x1, %ebp
movl $0x1, %r11d
movl %r11d, %edx
cmpl %ecx, %eax
setae %sil
cmpl $0xc, %r11d
setb %dil
andb %sil, %dil
movl $0x0, %esi
cmovnel %ecx, %esi
subl %esi, %eax
movzbl %dil, %r11d
addl %edx, %r11d
cmpl %r10d, %eax
jb 0x4d88
cmpl $0xa, %r9d
movl $0x0, %edx
cmovbl %r10d, %edx
adcl $0x0, %r9d
subl %edx, %eax
cmpl %r10d, %eax
jb 0x4d88
cmpl $0x16, %ebx
movl $0x0, %edx
cmovbl %r10d, %edx
adcl $0x0, %ebx
subl %edx, %eax
cmpl %r10d, %eax
jb 0x4d88
cmpl $0x3c, %ebp
movl $0x0, %edx
cmovbl %r10d, %edx
adcl $0x0, %ebp
subl %edx, %eax
cmpl %r10d, %eax
jb 0x4d88
cmpl $0xc, %r11d
setb %dl
cmpl $0xa, %r9d
setb %sil
cmpl $0x16, %ebx
setb %dil
orb %sil, %dil
cmpl $0x3c, %ebp
setb %sil
orb %dil, %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x4d7a
testl %eax, %eax
jne 0x5249
jmp 0x4d7a
xorl %ecx, %ecx
movq (%r13), %rax
movl %ecx, %edx
movb $0x4e, (%rax,%rdx)
movq 0x8(%r13), %rax
incl %ecx
movb $0x0, (%rax,%rdx)
cmpl $0x186a, %ecx           # imm = 0x186A
jne 0x5306
leaq 0x1(%r8), %rax
movq %r15, %rbp
movzbl 0x145008(%r15), %ecx
addq $0xc08, 0x58(%rsp)      # imm = 0xC08
cmpq %rcx, %r8
movq %rax, %rcx
jb 0x4c64
movq 0x8(%rsp), %rdx
leaq 0x1(%rdx), %rax
movzbl 0x145007(%rbp), %ecx
addq $0xc08, 0x50(%rsp)      # imm = 0xC08
cmpq %rcx, %rdx
movq %rax, 0x8(%rsp)
jb 0x4c31
movq 0x18(%rsp), %rdi
callq 0x1180
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
movq 0x28(%rsp), %rax
movl 0x4c(%rsp), %ecx
movb %cl, 0x145005(%rax)
movl $0x3, 0x141000(%rax)
movb $0x1, 0x145006(%rax)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rdi
callq 0x1180
jmp 0x49fe
movq %rax, %rdi
jmp 0x53bb
callq 0x1180
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x40008(%rbp), %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
movl $0x0, (%rbp,%r12)
movq -0x8(%r14,%r12,4), %rdi
testq %rdi, %rdi
je 0x5406
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%r14,%r12,4)
movq (%r14,%r12,4), %rdi
testq %rdi, %rdi
je 0x5422
movl $0x1, %esi
callq 0x1150
movq $0x0, (%r14,%r12,4)
addq $0x4, %r12
cmpq $0x400, %r12            # imm = 0x400
jne 0x53e9
incq %r15
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %r14           # imm = 0x1000
cmpq $0x100, %r15            # imm = 0x100
jne 0x53e6
leaq 0x30d9(%rip), %rsi      # 0x8531
jmp 0x4aa8
nop