// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r13
movl %esi, %edi
callq 0x6db6
testq %rax, %rax
js 0x3fea
movq %rax, %r12
movq %rax, %rdi
addq $0x200000, %rdi         # imm = 0x200000
callq 0x1030
movq %rax, %rbp
movl %r15d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0x11a0
cmpq $0xd, %rax
ja 0x3ff3
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0x1140
leaq 0x338e(%rip), %rsi      # 0x7376
jmp 0x4068
leaq 0x3367(%rip), %rsi      # 0x7358
jmp 0x4068
movq %rax, %r12
leaq 0x31e6(%rip), %rsi      # 0x71e3
pushq $0x3
popq %rdx
movq %rbp, %rdi
callq 0x1150
testl %eax, %eax
je 0x4020
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0x1140
leaq 0x3435(%rip), %rsi      # 0x7453
jmp 0x4068
movzwl 0x4(%rbp), %r14d
leal -0x101(%r14), %eax
cmpw $0xfeff, %ax            # imm = 0xFEFF
ja 0x4046
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0x1140
leaq 0x342c(%rip), %rsi      # 0x7470
jmp 0x4068
movzwl 0x6(%rbp), %edx
leal -0x101(%rdx), %eax
cmpw $0xfeff, %ax            # imm = 0xFEFF
ja 0x407e
pushq $0x1
popq %rsi
movq %rbp, %rdi
callq 0x1140
leaq 0x343c(%rip), %rsi      # 0x74a4
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x201c
movl %ebx, 0x6c(%rsp)
movzwl 0xa(%rbp), %eax
movl %eax, 0x4c(%rsp)
movzwl 0xc(%rbp), %ebx
decb %r14b
movb %r14b, 0x145007(%r13)
decb %dl
movq %r13, 0x50(%rsp)
movb %dl, 0x145008(%r13)
movq %rbp, %rdi
movzbl %r14b, %ebp
incl %ebp
movzbl %dl, %r15d
leal 0x1(%r15), %r13d
movl %r13d, %eax
imull %ebp, %eax
imull $0x7, %eax, %ecx
addl %ebx, %ecx
addl $0xe, %ecx
cmpq %rcx, %r12
jae 0x40d2
pushq $0x1
popq %rsi
jmp 0x3fdc
movq %rdx, 0x30(%rsp)
movq %rdi, 0x20(%rsp)
addl $0xe, %ebx
imull $0xc08, %eax, %edi      # imm = 0xC08
callq 0x1030
movl %r13d, %edi
movl %ebp, %ecx
leaq 0x10(%rax), %rdx
imulq $0xc08, %r15, %rsi      # imm = 0xC08
addq $0xc08, %rsi            # imm = 0xC08
movq %rsi, 0x60(%rsp)
xorl %r9d, %r9d
movq 0x50(%rsp), %rbp
movq %rax, 0x10(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rsi
cmpq %rcx, %r9
je 0x422b
movq %r9, 0x40(%rsp)
imulq %rdi, %r9
movq %rdx, 0x58(%rsp)
xorl %r11d, %r11d
cmpq %rdi, %r11
je 0x41e3
movl %ebx, %r8d
cmpq %r8, %r12
jb 0x41ff
movq 0x20(%rsp), %r15
movl (%r15,%r8), %r13d
leaq (%r9,%r11), %r8
imulq $0xc08, %r8, %r8        # imm = 0xC08
movl %r13d, (%rax,%r8)
addl 0x4c(%rsp), %r13d
cmpq %r13, %r12
jb 0x4216
addq 0x10(%rsp), %r8
leal 0x6(%rbx), %r10d
movzbl (%r15,%r10), %ebp
movl %ebp, 0x4(%r8)
addl $0xc, %ebx
movl %ebx, %r15d
pushq $-0x1
popq %r8
movq %rdx, %r10
incq %r8
leal -0x5(%r15), %ebx
cmpq %rbp, %r8
jae 0x41cf
movl %ebx, %ebx
movb 0x4(%rsi,%rbx), %cl
movb %cl, -0x4(%r10)
movl (%rsi,%rbx), %ecx
movl %ecx, -0x8(%r10)
movl %r15d, %ecx
movzwl (%rsi,%rcx), %ecx
movl %ecx, (%r10)
addq $0xc, %r10
addl $0x7, %r15d
addl %r13d, %ecx
cmpq %rcx, %r12
jae 0x4196
jmp 0x41ff
incq %r11
addq $0xc08, %rdx            # imm = 0xC08
movq 0x50(%rsp), %rbp
jmp 0x413c
movq 0x40(%rsp), %r9
incq %r9
movq 0x58(%rsp), %rdx
addq 0x60(%rsp), %rdx
movq 0x38(%rsp), %rcx
jmp 0x4122
movq 0x10(%rsp), %rdi
callq 0x1170
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdi
jmp 0x3fdc
movq 0x10(%rsp), %rdi
callq 0x1170
pushq $0x1
popq %rsi
movq %r15, %rdi
jmp 0x3fdc
leaq 0x40000(%rbp), %rax
movq %rax, 0x80(%rsp)
xorl %r12d, %r12d
movq $0x0, 0x70(%rsp)
xorl %r10d, %r10d
movq 0x30(%rsp), %rcx
movzbl %r14b, %eax
cmpq %rax, %r10
ja 0x494f
movq %r10, %rax
shlq $0xa, %rax
addq %rbp, %rax
movq %rax, 0x90(%rsp)
movq %r10, %rax
shlq $0xc, %rax
addq 0x80(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x78(%rsp)
xorl %r9d, %r9d
movq %r10, 0x38(%rsp)
movzbl %cl, %eax
cmpq %rax, %r9
ja 0x48a4
movq 0x90(%rsp), %rax
movq %r9, %rbx
movl $0x186a, (%rax,%r9,4)   # imm = 0x186A
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movq %rbx, 0x40(%rsp)
shlq $0x4, %rbx
movq 0x88(%rsp), %r14
leaq (%r14,%rbx), %r15
movq %rax, (%rbx,%r14)
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movq 0x38(%rsp), %r10
movq %rax, 0x8(%rbx,%r14)
xorl %eax, %eax
cmpq $0x186a, %rax           # imm = 0x186A
je 0x430a
movq (%r15), %rcx
movb %r12b, (%rcx,%rax)
movq 0x8(%r15), %rcx
movb %r12b, (%rcx,%rax)
incq %rax
jmp 0x42ee
movzbl 0x145008(%rbp), %ecx
incq %rcx
movq 0x70(%rsp), %rax
imulq %rcx, %rax
imulq %r10, %rcx
movq 0x40(%rsp), %rdx
movq %rdx, %r9
addq %rdx, %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
movq 0x10(%rsp), %rdx
movl 0x4(%rdx,%rcx), %r14d
imulq $0xc, %r14, %rsi
addq 0x78(%rsp), %rax
xorl %edi, %edi
xorl %edx, %edx
cmpq %rdi, %rsi
je 0x437a
movb 0xb(%rax,%rdi), %cl
movl $0x80, %r8d
shll %cl, %r8d
xorl %ecx, %ecx
testb $0x40, 0xc(%rax,%rdi)
sete %cl
leal (%rdx,%rcx,4), %ecx
cmovnel %r12d, %r8d
leal (%r8,%rcx), %edx
addl $0x8, %edx
addq $0xc, %rdi
jmp 0x434a
leal (%r14,%r14,4), %eax
addl %eax, %edx
cmpl $0x186a, %edx           # imm = 0x186A
ja 0x48bc
cmpl $0x1866, %edx           # imm = 0x1866
jne 0x43b0
leal (%r14,%r14), %ecx
xorl %eax, %eax
pushq $0x1
popq %rdx
movl %edx, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl %edx, 0xc(%rsp)
movl %edx, %edi
jmp 0x448e
movl $0x1866, %eax           # imm = 0x1866
subl %edx, %eax
leal (%r14,%r14), %ecx
pushq $0x1
popq %rdx
movl %edx, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movl %edx, %r8d
movl %edx, %edi
movl %edi, %edx
cmpl %ecx, %eax
setae %sil
cmpl $0xc, %edi
setb %dil
andb %sil, %dil
movl $0x0, %esi
cmovnel %ecx, %esi
subl %esi, %eax
movzbl %dil, %edi
addl %edx, %edi
cmpl %r14d, %eax
jb 0x4489
movl 0x1c(%rsp), %esi
cmpl $0xa, %esi
movl $0x0, %edx
cmovbl %r14d, %edx
adcl $0x0, %esi
movl %esi, 0x1c(%rsp)
subl %edx, %eax
cmpl %r14d, %eax
jb 0x4489
movl 0x18(%rsp), %esi
cmpl $0x16, %esi
movl $0x0, %edx
cmovbl %r14d, %edx
adcl $0x0, %esi
movl %esi, 0x18(%rsp)
subl %edx, %eax
cmpl %r14d, %eax
jb 0x4489
cmpl $0x3c, %r8d
movl $0x0, %edx
cmovbl %r14d, %edx
adcl $0x0, %r8d
subl %edx, %eax
cmpl %r14d, %eax
jb 0x4489
movl %edi, %ebx
cmpl $0xc, %edi
setb %dl
cmpl $0xa, 0x1c(%rsp)
setb %sil
cmpl $0x16, 0x18(%rsp)
setb %dil
orb %sil, %dil
cmpl $0x3c, %r8d
setb %sil
orb %dil, %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x4898
testl %eax, %eax
movl %ebx, %edi
jne 0x43cb
movl %r8d, 0xc(%rsp)
leal 0xa(%rcx), %edx
xorl %ebx, %ebx
cmpl %edx, %eax
movl $0x0, %edx
cmoval %r14d, %edx
seta %bl
subl %edx, %eax
addl $0x9, %ecx
cmpl %eax, %ecx
movl $0x0, %ecx
adcl $0x1, %ebx
xorl %eax, %eax
movq %r14, 0x98(%rsp)
movl %edi, 0x2c(%rsp)
cmpq %r14, %rcx
je 0x487a
movq %rcx, 0x58(%rsp)
leal 0x7(%rax), %r13d
leal 0x9(%rax), %r14d
movl 0x1c(%rsp), %ecx
subl $0x1, %ecx
jb 0x44f8
movq (%r15), %rdx
movl %eax, %esi
movb $0x4e, (%rdx,%rsi)
movq 0x8(%r15), %rdx
incl %eax
movb $0x0, (%rdx,%rsi)
incl %r13d
incl %r14d
jmp 0x44d8
xorl %edx, %edx
leal (%rax,%rdx), %ecx
cmpl %edx, %edi
je 0x451c
movq (%r15), %rsi
movl %ecx, %ecx
movb %r12b, (%rsi,%rcx)
movq 0x8(%r15), %rsi
movb %r12b, (%rsi,%rcx)
incl %edx
incl %r13d
incl %r14d
jmp 0x44fa
pushq $-0x5
popq %rdx
leal (%rbx,%rdx), %edi
leal -0x7(%r13), %eax
movq (%r15), %rsi
cmpl $-0x5, %edi
je 0x4545
movb $-0x5f, (%rsi,%rax)
movq 0x8(%r15), %rsi
movb $-0x1, (%rsi,%rax)
decq %rdx
incl %r13d
incl %r14d
jmp 0x451f
movb $-0x2, (%rsi,%rax)
movq 0x8(%r15), %rsi
movq %rbp, %r11
xorl %ebp, %ebp
movb %bpl, (%rsi,%rax)
movzbl 0x145008(%r11), %eax
incq %rax
imulq %r10, %rax
movq %r9, %rsi
addq %r9, %rax
imulq $0xc08, %rax, %rax      # imm = 0xC08
addq 0x10(%rsp), %rax
movq %r10, %r9
imulq $0xc, 0x58(%rsp), %r10
movb 0x8(%r10,%rax), %al
movq (%r15), %r8
leal -0x6(%r13), %edi
movb %al, (%r8,%rdi)
movq 0x8(%r15), %rax
leal -0x5(%r13), %r8d
movb %bpl, (%rax,%rdi)
movzbl 0x145008(%r11), %eax
incq %rax
imulq %r9, %rax
addq %rsi, %rax
imulq $0xc08, %rax, %rax      # imm = 0xC08
movq 0x10(%rsp), %rsi
addq %rsi, %rax
movb 0x9(%r10,%rax), %al
movq (%r15), %rdi
movb %al, (%rdi,%r8)
movq 0x8(%r15), %rax
leal -0x4(%r13), %r9d
movb %bpl, (%rax,%r8)
movzbl 0x145008(%r11), %eax
incq %rax
movq 0x38(%rsp), %r8
imulq %r8, %rax
movq 0x40(%rsp), %rdi
addq %rdi, %rax
imulq $0xc08, %rax, %rax      # imm = 0xC08
addq %rsi, %rax
movb 0xa(%r10,%rax), %al
movq (%r15), %rsi
movb %al, (%rsi,%r9)
movq 0x8(%r15), %rax
leal -0x3(%r13), %esi
movb %bpl, (%rax,%r9)
movzbl 0x145008(%r11), %eax
incq %rax
imulq %r8, %rax
addq %rdi, %rax
imulq $0xc08, %rax, %rax      # imm = 0xC08
addq 0x10(%rsp), %rax
movq %r10, 0x60(%rsp)
movb 0xb(%r10,%rax), %al
movq (%r15), %rdi
movb %al, (%rdi,%rsi)
movq 0x8(%r15), %rax
leal -0x2(%r13), %edi
movq %rdi, 0x30(%rsp)
movb %bpl, (%rax,%rsi)
movq (%r15), %rax
movq %rax, 0xa0(%rsp)
movl %ecx, %esi
addq %rax, %rsi
negq %rdx
callq 0x1a98
movq 0x30(%rsp), %rsi
movq 0xa0(%rsp), %rcx
movb %ah, (%rcx,%rsi)
movq 0x8(%r15), %rcx
leal -0x1(%r13), %edx
movb %bpl, (%rcx,%rsi)
movq (%r15), %rcx
movb %al, (%rcx,%rdx)
movq 0x8(%r15), %rax
movb %bpl, (%rax,%rdx)
movl 0x18(%rsp), %edx
movl 0x2c(%rsp), %edi
leal (%r13,%rbp), %eax
cmpl %ebp, %edx
je 0x46bd
movq (%r15), %rcx
movl %eax, %eax
movb $0x4e, (%rcx,%rax)
movq 0x8(%r15), %rcx
movb $0x0, (%rcx,%rax)
incl %ebp
incl %r14d
jmp 0x469c
movl %edi, %ecx
movq 0x50(%rsp), %rbp
movq 0x38(%rsp), %r10
movq 0x40(%rsp), %r9
movq 0x60(%rsp), %r13
movl %eax, %esi
subl $0x1, %ecx
jb 0x46f0
movq (%r15), %rdx
movb %r12b, (%rdx,%rsi)
movq 0x8(%r15), %rdx
incl %eax
movb %r12b, (%rdx,%rsi)
incl %r14d
jmp 0x46d3
movzbl 0x145008(%rbp), %ecx
incq %rcx
imulq %r10, %rcx
addq %r9, %rcx
imulq $0xc08, %rcx, %rcx      # imm = 0xC08
addq 0x10(%rsp), %rcx
movzbl 0xc(%r13,%rcx), %ecx
movl %ecx, 0x30(%rsp)
testb $0x40, %cl
jne 0x4834
xorl %ecx, %ecx
pushq $0x1
popq %rdx
leal (%rax,%rcx), %edi
cmpl %ecx, %ebx
je 0x4749
movq (%r15), %r8
movl %edi, %edi
movb $-0x5f, (%r8,%rdi)
movq 0x8(%r15), %r8
movb $-0x1, (%r8,%rdi)
incl %ecx
incl %r14d
incq %rdx
jmp 0x4725
xorl %eax, %eax
cmpb $0x0, 0x30(%rsp)
movq (%r15), %rcx
setns %al
leal (%rax,%rax,2), %eax
orl $0xf8, %eax
movb %al, (%rcx,%rdi)
movq 0x8(%r15), %rax
movb $0x0, (%rax,%rdi)
movzbl 0x145008(%rbp), %eax
incq %rax
imulq %r10, %rax
addq %r9, %rax
imulq $0xc08, %rax, %rdi      # imm = 0xC08
movq 0x10(%rsp), %r9
leaq (%r9,%rdi), %r8
movb 0xb(%r13,%r8), %cl
movl $0x80, %eax
shll %cl, %eax
movl 0x10(%r13,%r8), %ecx
addl 0x4c(%rsp), %ecx
addl (%r9,%rdi), %ecx
movq 0x20(%rsp), %r10
leal -0x1(%r14), %r13d
subq $0x1, %rax
jb 0x47d5
movl %ecx, %edi
movb (%r10,%rdi), %dil
movq (%r15), %r8
movl %r13d, %r9d
movb %dil, (%r8,%r9)
movq 0x8(%r15), %rdi
movb $0x0, (%rdi,%r9)
incl %ecx
incl %r14d
incq %rdx
jmp 0x47a8
movq (%r15), %rbp
addq %rbp, %rsi
callq 0x1a98
movl %r13d, %ecx
testb $0x3f, 0x30(%rsp)
je 0x47f8
movb %ah, (%rbp,%rcx)
movq 0x8(%r15), %rdx
movb $0x0, (%rdx,%rcx)
jmp 0x480a
movl %eax, %edx
notl %edx
movb %dh, (%rbp,%rcx)
movq 0x8(%r15), %rdx
movb $0x0, (%rdx,%rcx)
notb %al
movl 0x2c(%rsp), %edi
movq (%r15), %rcx
movl %r14d, %edx
movb %al, (%rcx,%rdx)
movq 0x8(%r15), %rax
movb $0x0, (%rax,%rdx)
incl %r14d
movl %r14d, %eax
movq 0x50(%rsp), %rbp
movq 0x38(%rsp), %r10
movq 0x40(%rsp), %r9
movl 0xc(%rsp), %ecx
movq 0x98(%rsp), %r14
subl $0x1, %ecx
jb 0x485a
movq (%r15), %rdx
movl %eax, %esi
movb $0x4e, (%rdx,%rsi)
movq 0x8(%r15), %rdx
incl %eax
movb $0x0, (%rdx,%rsi)
jmp 0x4840
movq 0x58(%rsp), %rcx
incq %rcx
jmp 0x44be
movq (%r15), %rcx
movl %eax, %edx
movb $0x4e, (%rcx,%rdx)
movq 0x8(%r15), %rcx
incl %eax
movb $0x0, (%rcx,%rdx)
cmpl $0x186a, %eax           # imm = 0x186A
jl 0x4867
incq %r9
movb 0x145008(%rbp), %cl
addq $0xc08, 0x78(%rsp)      # imm = 0xC08
jmp 0x4296
movl %r8d, 0xc(%rsp)
movl %ebx, %edi
jmp 0x448e
incq %r10
movb 0x145007(%rbp), %r14b
addq $0xc08, 0x70(%rsp)      # imm = 0xC08
jmp 0x424e
movq 0x10(%rsp), %rdi
callq 0x1170
pushq $0x1
popq %r15
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x1140
leaq 0x40008(%rbp), %rbx
xorl %r14d, %r14d
cmpq $0x100, %r14            # imm = 0x100
je 0x4943
xorl %r12d, %r12d
cmpq $0x400, %r12            # imm = 0x400
je 0x4930
andl $0x0, (%rbp,%r12)
movq -0x8(%rbx,%r12,4), %rdi
testq %rdi, %rdi
je 0x490e
movq %r15, %rsi
callq 0x1140
andq $0x0, -0x8(%rbx,%r12,4)
movq (%rbx,%r12,4), %rdi
testq %rdi, %rdi
je 0x4925
movq %r15, %rsi
callq 0x1140
andq $0x0, (%rbx,%r12,4)
addq $0x4, %r12
jmp 0x48ed
incq %r14
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %rbx           # imm = 0x1000
jmp 0x48e1
leaq 0x2b8b(%rip), %rsi      # 0x74d5
jmp 0x4068
movq 0x10(%rsp), %rdi
callq 0x1170
pushq $0x1
popq %rsi
movq 0x20(%rsp), %rdi
callq 0x1140
movl 0x6c(%rsp), %eax
movb %al, 0x145005(%rbp)
movl $0x3, 0x141000(%rbp)
movb $0x1, 0x145006(%rbp)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop