// File: /workspace/github_cpp_makefile_star2_O3/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 0x5975
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 0x595f
cmpq $0xb, %rax
jg 0x598f
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2a5f(%rip), %rsi      # 0x83d2
jmp 0x597c
leaq 0x2a38(%rip), %rsi      # 0x83b4
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2410
movzwl (%r14), %eax
cmpl $0x6474, %eax           # imm = 0x6474
je 0x59a5
cmpl $0x4454, %eax           # imm = 0x4454
jne 0x6100
xorl %eax, %eax
leaq 0x5832(%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 0x59b0
rolw $0x8, %cx
cmpw 0xa(%r14), %cx
jne 0x59f8
movb 0x4(%r14), %al
addb $-0x16, %al
cmpb $-0xd, %al
ja 0x5a11
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2d81(%rip), %rsi      # 0x8777
jmp 0x597c
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2d52(%rip), %rsi      # 0x875e
jmp 0x597c
cmpb $0x0, 0x8(%r14)
je 0x5a31
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x2d6a(%rip), %rsi      # 0x8796
jmp 0x597c
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x72b9
testb %al, %al
je 0x6100
movl %ebx, 0x28(%rsp)
movl $0xc, %ebp
cmpb $0x0, 0x7(%r14)
jns 0x5a5e
movzwl 0xe(%r14), %ebp
addl $0x16, %ebp
movw $0x0, 0x145007(%r13)
movq 0x40(%rsp), %rdx
leaq 0x40000(%r13), %rax
movq %rax, 0x50(%rsp)
leaq 0x40008(%r13), %rax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
movq %r13, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movslq %ebp, %rbx
cmpq %rbx, %rdx
jle 0x6119
addl $0x4, %ebp
movslq %ebp, %rax
cmpq %rax, %rdx
jle 0x6119
cmpb $-0x1, (%r14,%rbx)
je 0x6119
movl %ebp, 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, 0xc(%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 0x5b12
movzbl (%r14,%rbx), %r8d
testl %r8d, %r8d
movl 0x4(%rsp), %ebp
je 0x5b5a
xorl %eax, %eax
movl %r8d, %ecx
movl %ebp, %edx
movl %edx, %esi
movzwl 0x6(%r14,%rsi), %esi
addl %esi, %edx
addl $0x8, %edx
addl %esi, %eax
addl $0xb, %eax
decl %ecx
jne 0x5b42
jmp 0x5b5c
xorl %eax, %eax
leal (%r8,%r8,4), %esi
addl %eax, %esi
cmpl $0x186b, %esi           # imm = 0x186B
jae 0x5f1d
cmpl $0x1866, %esi           # imm = 0x1866
jne 0x5fc8
leal (%r8,%r8), %r11d
movl $0x1, %ebx
xorl %r10d, %r10d
movl $0x1, %r12d
movl $0x1, %r9d
movl $0x1, %edi
testl %r8d, %r8d
je 0x60a1
movl %esi, 0x8(%rsp)
leal 0xa(%r11), %eax
xorl %edx, %edx
movl %r9d, %ecx
xorl %r9d, %r9d
cmpl %eax, %r10d
seta %r9b
movl $0x0, %eax
movq %r8, 0x60(%rsp)
cmoval %r8d, %eax
subl %eax, %r10d
addl $0x9, %r11d
cmpl %r10d, %r11d
adcl $0x0, %r9d
cmpl $0x1, %ebx
adcl $0x0, %ebx
movl %ebx, 0x38(%rsp)
leal 0x1(%r9), %r10d
cmpl $0x1, %edi
adcl $0x0, %edi
addl $0x6, %r9d
cmpl $0x1, %r12d
adcl $0x0, %r12d
movl %r12d, 0x34(%rsp)
cmpl $0x1, %ecx
adcl $0x0, %ecx
movl %ecx, 0x30(%rsp)
xorl %ebx, %ebx
movl %edx, 0x3c(%rsp)
movslq %ebp, %r12
leal 0x9(%rbx), %esi
leal 0xd(%rbx), %r8d
movl 0x38(%rsp), %ecx
movl %esi, %eax
movl %r8d, %edx
movq (%r13), %rsi
movl %ebx, %r8d
movb $0x4e, (%rsi,%r8)
movq 0x8(%r13), %rsi
incl %ebx
movb $0x0, (%rsi,%r8)
leal 0x1(%rax), %esi
leal 0x1(%rdx), %r8d
decl %ecx
jne 0x5c16
xorl %esi, %esi
movl %eax, %r11d
movl %edx, %ecx
leal (%rbx,%rsi), %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 0x5c3f
movl %ebp, 0x4(%rsp)
addl %esi, %ebx
xorl %esi, %esi
movl %ecx, %eax
leal -0x7(%r11), %ecx
movq (%r13), %rdx
movb $-0x5f, (%rdx,%rcx)
movq 0x8(%r13), %rdx
movb $-0x1, (%rdx,%rcx)
incl %esi
incl %r11d
leal 0x1(%rax), %ecx
cmpl %esi, %r10d
jne 0x5c6c
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,%r12), %cl
movq (%r13), %rdx
movb %cl, (%rdx,%r8)
movq 0x8(%r13), %rcx
leal -0x5(%r11), %edx
movb %r15b, (%rcx,%r8)
movb 0x1(%r14,%r12), %cl
movq (%r13), %r8
movb %cl, (%r8,%rdx)
movq 0x8(%r13), %rcx
leal -0x4(%r11), %r8d
movb %r15b, (%rcx,%rdx)
movb 0x2(%r14,%r12), %cl
movq (%r13), %rdx
movb %cl, (%rdx,%r8)
movq 0x8(%r13), %rcx
leal -0x3(%r11), %edx
movb %r15b, (%rcx,%r8)
movq %r12, 0x10(%rsp)
movb 0x3(%r14,%r12), %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, %esi
je 0x5d59
movl %ebx, %esi
addq %rdx, %rsi
movw $0xffff, %cx            # imm = 0xFFFF
xorl %ebx, %ebx
movzbl (%rsi,%rbx), %r8d
shll $0x8, %r8d
xorl %r8d, %ecx
movl $0x8, %r12d
leal (%rcx,%rcx), %ebp
movl %ebp, %r8d
xorl $0x1021, %r8d           # imm = 0x1021
testw %cx, %cx
cmovnsl %ebp, %r8d
movl %r8d, %ecx
decl %r12d
jne 0x5d35
incq %rbx
cmpq %r9, %rbx
jne 0x5d23
movl 0x4(%rsp), %ebp
addl $0x9, %ebp
leal -0x2(%r11), %esi
movl %esi, %esi
movb %ch, (%rdx,%rsi)
movq 0x8(%r13), %rdx
leal -0x1(%r11), %r8d
movb %r15b, (%rdx,%rsi)
movq (%r13), %rdx
movb %cl, (%rdx,%r8)
movq 0x8(%r13), %rcx
movb %r15b, (%rcx,%r8)
movl 0x34(%rsp), %edx
movl %eax, %ecx
movq (%r13), %rax
movl %r11d, %esi
movb $0x4e, (%rax,%rsi)
movq 0x8(%r13), %rax
incl %r11d
movb $0x0, (%rax,%rsi)
leal 0x1(%rcx), %eax
decl %edx
jne 0x5d89
movl %edi, %edx
movq 0x10(%rsp), %r8
movl %ecx, %eax
movq (%r13), %rcx
movl %r11d, %esi
movb %r15b, (%rcx,%rsi)
movq 0x8(%r13), %rcx
incl %r11d
movb %r15b, (%rcx,%rsi)
leal 0x1(%rax), %ecx
decl %edx
jne 0x5daf
cmpw $0x1, 0x6(%r14,%r8)
je 0x5ed0
movl %r10d, %edx
movl %eax, %ecx
leal -0x1(%rcx), %eax
movq (%r13), %rsi
movb $-0x5f, (%rsi,%rax)
movq 0x8(%r13), %rsi
movb $-0x1, (%rsi,%rax)
leal 0x1(%rcx), %eax
decl %edx
jne 0x5dde
movq (%r13), %rdx
leal -0x1(%rax), %esi
movb $-0x5, (%rdx,%rsi)
movq 0x8(%r13), %rdx
movb $0x0, (%rdx,%rsi)
movzwl 0x6(%r14,%r8), %ebx
decl %ebx
je 0x5e3f
movl %ebx, %eax
movl %ebp, %edx
incl %ecx
movl %edx, %esi
movb (%r14,%rsi), %sil
movq (%r13), %r8
movb %sil, (%r8,%rcx)
movq 0x8(%r13), %rsi
movb $0x0, (%rsi,%rcx)
incl %edx
decq %rax
jne 0x5e1b
leal 0x1(%rcx), %eax
movl %ecx, %esi
movl %ebx, 0x2c(%rsp)
movl %ebp, 0x4(%rsp)
movq (%r13), %rcx
movq %rcx, 0x10(%rsp)
movw $0xffff, %cx            # imm = 0xFFFF
movl %eax, %ebp
subl %r11d, %ebp
je 0x5e9c
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, %edx
xorl $0x1021, %edx           # imm = 0x1021
testw %cx, %cx
cmovnsl %ebx, %edx
movl %edx, %ecx
decl %r8d
jne 0x5e7c
incq %r12
cmpq %rbp, %r12
jb 0x5e6a
movl 0x4(%rsp), %ebp
addl 0x2c(%rsp), %ebp
movl %eax, %eax
movq 0x10(%rsp), %rdx
movb %ch, (%rdx,%rax)
movq 0x8(%r13), %rdx
leal 0x2(%rsi), %r8d
movb %r15b, (%rdx,%rax)
movq (%r13), %rax
movb %cl, (%rax,%r8)
movq 0x8(%r13), %rax
addl $0x3, %esi
movb %r15b, (%rax,%r8)
movl %esi, %r11d
movl 0x30(%rsp), %eax
movl %r11d, %ebx
movq (%r13), %rcx
movl %ebx, %edx
movb $0x4e, (%rcx,%rdx)
movq 0x8(%r13), %rcx
incl %ebx
movb $0x0, (%rcx,%rdx)
decl %eax
jne 0x5ed7
movl 0x3c(%rsp), %edx
incl %edx
cmpl 0x60(%rsp), %edx
jne 0x5c04
cmpl $0x1869, %ebx           # imm = 0x1869
movq 0x18(%rsp), %rdx
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edi
jle 0x60ac
jmp 0x60c8
movl %esi, 0x8(%rsp)
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
movq 0x48(%rsp), %rbx
movq 0x20(%rsp), %r13
xorl %ebp, %ebp
xorl %r12d, %r12d
movl $0x0, (%r13,%r12)
movq -0x8(%rbx,%r12,4), %rdi
testq %rdi, %rdi
je 0x5f5a
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%rbx,%r12,4)
movq (%rbx,%r12,4), %rdi
testq %rdi, %rdi
je 0x5f76
movl $0x1, %esi
callq 0x1150
movq $0x0, (%rbx,%r12,4)
addq $0x4, %r12
cmpq $0x400, %r12            # imm = 0x400
jne 0x5f3d
incq %rbp
addq $0x400, %r13            # imm = 0x400
addq $0x1000, %rbx           # imm = 0x1000
cmpq $0x100, %rbp            # imm = 0x100
jne 0x5f3a
leaq 0x2585(%rip), %rsi      # 0x8531
callq 0x2410
movq 0x20(%rsp), %r13
movl 0x4(%rsp), %ebp
movq 0x18(%rsp), %rdx
movl 0x8(%rsp), %esi
jmp 0x60f2
movl $0x1866, %r10d          # imm = 0x1866
subl %esi, %r10d
leal (%r8,%r8), %r11d
movl $0x1, %ebx
movl $0x1, %r12d
movl $0x1, %r9d
movl $0x1, %edi
movl %edi, %eax
cmpl %r11d, %r10d
setae %cl
cmpl $0xc, %edi
setb %dl
andb %cl, %dl
movl $0x0, %ecx
cmovnel %r11d, %ecx
subl %ecx, %r10d
movzbl %dl, %edi
addl %eax, %edi
cmpl %r8d, %r10d
jb 0x5b97
cmpl $0xa, %ebx
movl $0x0, %eax
cmovbl %r8d, %eax
adcl $0x0, %ebx
subl %eax, %r10d
cmpl %r8d, %r10d
jb 0x5b97
cmpl $0x16, %r12d
movl $0x0, %eax
cmovbl %r8d, %eax
adcl $0x0, %r12d
subl %eax, %r10d
cmpl %r8d, %r10d
jb 0x5b97
cmpl $0x3c, %r9d
movl $0x0, %eax
cmovbl %r8d, %eax
adcl $0x0, %r9d
subl %eax, %r10d
cmpl %r8d, %r10d
jb 0x5b97
cmpl $0xc, %edi
setb %al
cmpl $0xa, %ebx
setb %cl
cmpl $0x16, %r12d
setb %dl
orb %cl, %dl
cmpl $0x3c, %r9d
setb %cl
orb %dl, %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x5b97
testl %r10d, %r10d
jne 0x5feb
jmp 0x5b97
xorl %ebx, %ebx
movq 0x18(%rsp), %rdx
movl 0xc(%rsp), %edi
movq (%r13), %rax
movl %ebx, %ecx
movb $0x4e, (%rax,%rcx)
movq 0x8(%r13), %rax
incl %ebx
movb $0x0, (%rax,%rcx)
cmpl $0x186a, %ebx           # imm = 0x186A
jne 0x60ac
movq 0x20(%rsp), %r13
cmpb %dil, 0x145007(%r13)
movq 0x58(%rsp), %rax
jae 0x60e2
movb %dil, 0x145007(%r13)
cmpb %al, 0x145008(%r13)
jae 0x60f2
movb %al, 0x145008(%r13)
cmpl $0x186b, %esi           # imm = 0x186B
jb 0x5a92
jmp 0x6144
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
leaq 0x262d(%rip), %rsi      # 0x8741
jmp 0x597c
movl $0x1, %esi
movq %r14, %rdi
callq 0x1150
movl 0x28(%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