// File: /workspace/github_cpp_makefile_star2_O3/atsidaev[P]trx2x/DiskImage.cpp
// Function: TDiskImage::readFDD(int, bool)
void TDiskImage::readFDD(int hfile, bool readonly)
{

   long fsize = filelength(hfile);
   if(fsize < 0 )
   {
      ShowError(ERR_GETLEN);
      return;
   }

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

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

   FDD_MAIN_HEADER *fdd_hdr = (FDD_MAIN_HEADER*)ptr;

   int MaxC = fdd_hdr->MaxTracks;
   int MaxH = fdd_hdr->MaxHeads;

   if( MaxH > 2 )
   {
      delete ptr;
      ShowError(ERR_MANYSIDS);
      return;
   }


   MaxH = (MaxH - 1)&0xFF;
   MaxC = (MaxC - 1)&0xFF;


   MaxTrack = MaxC;
   MaxSide = MaxH;


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

   FDD_TRACK_HEADER *trackinfo;

   unsigned int trk, side;

   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;         
         }

         if( (fdd_hdr->DataOffset[trk*(MaxSide+1)+side]+2) > int(rsize) )
         {
            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_CORRUPT);
            return;
         }

         trackinfo = (FDD_TRACK_HEADER *) (ptr + fdd_hdr->DataOffset[trk*(MaxSide+1)+side]);

         SecCount = trackinfo->SectNum;

         if( ( 2+SecCount*8 + fdd_hdr->DataOffset[trk*(MaxSide+1)+side]) > rsize )
         {
            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_CORRUPT);
            return;
         }
         else if(trackinfo->sect[SecCount-1].SectPos > int(rsize))
         {
            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_CORRUPT);
            return;
         }



// Вычисляем необходимое число байт под данные:
         trkdatalen = 0;
         for(unsigned int ilsec=0; ilsec < SecCount; ilsec++)
         {
            trkdatalen += 2+6;     // for marks:   0xA1, 0xFE, 6bytes
            SL = unsigned(trackinfo->sect[ilsec].size);
            if(!SL) SL = 128;
            else SL = 128 << SL;

            trkdatalen += 4;       // for data header/crc: 0xA1, 0xFB, ...,2bytes

            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;
         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] = trackinfo->sect[sec].trk;  // cyl
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = trackinfo->sect[sec].side; // head 
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = trackinfo->sect[sec].sect; // secN
            FTracksPtr[trk][side][1][tptr++] = 0x00;
            FTracksPtr[trk][side][0][tptr] = trackinfo->sect[sec].size; // 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;
            }


// DATA AM
            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( trackinfo->sect[sec].size );
            if(!SL) SL = 128;
            else SL = 128 << SL;

            unsigned int secDATAOFF = trackinfo->sect[sec].SectPos;

            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);


            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;
         }
      }

   delete ptr;
   ReadOnly = readonly;
   FType = DIT_FDD;
   DiskPresent = true;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %edx, 0x20(%rsp)
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 0x61df
movq %r12, %rdi
addq $0x8000, %rdi           # imm = 0x8000
callq 0x1030
movq %rax, %rbx
movl %r15d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0x11b0
cmpq $0x1023, %rax           # imm = 0x1023
ja 0x61e8
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1150
leaq 0x21f5(%rip), %rsi      # 0x83d2
jmp 0x6204
leaq 0x21ce(%rip), %rsi      # 0x83b4
jmp 0x6204
movb 0x1f(%rbx), %dl
cmpb $0x3, %dl
jb 0x6217
movl $0x1, %esi
movq %rbx, %rdi
callq 0x1150
leaq 0x22fc(%rip), %rsi      # 0x8500
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2410
movq %rax, 0x58(%rsp)
movb 0x1e(%rbx), %cl
decb %dl
decb %cl
movb %cl, 0x145007(%rbp)
movb %dl, 0x145008(%rbp)
leaq 0x40000(%rbp), %rax
movq %rbx, 0x8(%rsp)
leaq 0x5(%rbx), %rcx
movq %rcx, 0x48(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbp, 0x50(%rsp)
movq %rax, 0x40(%rsp)
movq %r14, %rcx
shlq $0xa, %rcx
addq %rbp, %rcx
movq %rcx, 0x68(%rsp)
movq %r14, %rcx
shlq $0xc, %rcx
addq %rax, %rcx
movq %rcx, 0x60(%rsp)
xorl %ebx, %ebx
movq %r14, 0x30(%rsp)
movq 0x68(%rsp), %rax
movl $0x186a, (%rax,%rbx,4)  # imm = 0x186A
movl $0x1c6a, %edi           # imm = 0x1C6A
callq 0x1030
movq %rbx, 0x18(%rsp)
shlq $0x4, %rbx
movq 0x60(%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 0x62b6
movzbl 0x145008(%rbp), %eax
incq %rax
imulq %r14, %rax
addq 0x18(%rsp), %rax
movq 0x8(%rsp), %rdi
movl 0x24(%rdi,%rax,4), %edx
leal 0x2(%rdx), %eax
movq 0x58(%rsp), %rcx
cmpl %ecx, %eax
ja 0x6841
movzbl 0x1(%rdi,%rdx), %r13d
leal (%rax,%r13,8), %eax
cmpq %rax, %rcx
jb 0x68c3
leaq (%rdi,%rdx), %rsi
leal -0x1(%r13), %eax
movq %rsi, 0x10(%rsp)
cmpl %ecx, 0x6(%rsi,%rax,8)
ja 0x6945
testq %r13, %r13
je 0x634d
addq 0x48(%rsp), %rdx
xorl %edi, %edi
xorl %esi, %esi
movb (%rdx,%rdi,8), %cl
movl $0x80, %eax
shll %cl, %eax
addl %eax, %esi
addl $0xc, %esi
incq %rdi
cmpq %rdi, %r13
jne 0x6334
jmp 0x634f
xorl %esi, %esi
leal (%r13,%r13,4), %eax
addl %esi, %eax
cmpl $0x186a, %eax           # imm = 0x186A
ja 0x69cc
cmpl $0x1866, %eax           # imm = 0x1866
jne 0x66cf
leal (,%r13,2), %r11d
movl $0x1, %edi
xorl %ecx, %ecx
movl $0x1, %r9d
movl $0x1, %ebx
movl $0x1, %r8d
testq %r13, %r13
je 0x67ac
addq $0x2, 0x10(%rsp)
leal 0xa(%r11), %eax
xorl %r14d, %r14d
xorl %r10d, %r10d
cmpl %eax, %ecx
seta %r10b
movl $0x0, %eax
cmoval %r13d, %eax
subl %eax, %ecx
addl $0x9, %r11d
cmpl %ecx, %r11d
adcl $0x0, %r10d
leal 0x1(%r10), %r11d
cmpl $0x1, %edi
adcl $0x0, %edi
movl %edi, 0x2c(%rsp)
cmpl $0x1, %r8d
adcl $0x0, %r8d
addl $0x6, %r10d
cmpl $0x1, %r9d
adcl $0x0, %r9d
movl %r9d, 0x28(%rsp)
cmpl $0x1, %ebx
adcl $0x0, %ebx
movl %r13d, %eax
movq %rax, 0x70(%rsp)
xorl %ebp, %ebp
movl %ebx, 0x24(%rsp)
leal 0x9(%rbp), %eax
leal 0xd(%rbp), %edi
movl 0x2c(%rsp), %edx
movl %eax, %ecx
movl %edi, %esi
movq (%r15), %rax
movl %ebp, %edi
movb $0x4e, (%rax,%rdi)
movq 0x8(%r15), %rax
incl %ebp
movb $0x0, (%rax,%rdi)
leal 0x1(%rcx), %eax
leal 0x1(%rsi), %edi
decl %edx
jne 0x6406
xorl %edi, %edi
movl %ecx, %r13d
movl %esi, %edx
leal (%rdi,%rbp), %eax
movq (%r15), %rcx
movb %r12b, (%rcx,%rax)
movq 0x8(%r15), %rcx
movb %r12b, (%rcx,%rax)
incl %edi
leal 0x1(%r13), %ecx
leal 0x1(%rdx), %esi
cmpl %edi, %r8d
jne 0x6429
addl %edi, %ebp
xorl %edi, %edi
movl %edx, %ecx
leal -0x7(%r13), %eax
movq (%r15), %rdx
movb $-0x5f, (%rdx,%rax)
movq 0x8(%r15), %rdx
movb $-0x1, (%rdx,%rax)
incl %edi
incl %r13d
leal 0x1(%rcx), %edx
cmpl %edi, %r11d
jne 0x6452
movq (%r15), %rax
leal -0x7(%r13), %edx
movb $-0x2, (%rax,%rdx)
movq 0x8(%r15), %rax
leal -0x6(%r13), %esi
movb %r12b, (%rax,%rdx)
movq 0x10(%rsp), %r9
movb (%r9,%r14,8), %al
movq (%r15), %rdx
movb %al, (%rdx,%rsi)
movq 0x8(%r15), %rax
leal -0x5(%r13), %edx
movb %r12b, (%rax,%rsi)
movb 0x1(%r9,%r14,8), %al
movq (%r15), %rsi
movb %al, (%rsi,%rdx)
movq 0x8(%r15), %rax
leal -0x4(%r13), %esi
movb %r12b, (%rax,%rdx)
movb 0x2(%r9,%r14,8), %al
movq (%r15), %rdx
movb %al, (%rdx,%rsi)
movq 0x8(%r15), %rax
leal -0x3(%r13), %edx
movb %r12b, (%rax,%rsi)
movq %r14, 0x38(%rsp)
movb 0x3(%r9,%r14,8), %al
movq (%r15), %rsi
movb %al, (%rsi,%rdx)
movq 0x8(%r15), %rax
movb %r12b, (%rax,%rdx)
movq (%r15), %rsi
movw $0xffff, %dx            # imm = 0xFFFF
cmpl $-0x5, %edi
je 0x6532
movl %ebp, %edi
addq %rsi, %rdi
movw $0xffff, %dx            # imm = 0xFFFF
xorl %ebp, %ebp
movzbl (%rdi,%rbp), %eax
shll $0x8, %eax
xorl %eax, %edx
movl $0x8, %ebx
leal (%rdx,%rdx), %r14d
movl %r14d, %eax
xorl $0x1021, %eax           # imm = 0x1021
testw %dx, %dx
cmovnsl %r14d, %eax
movl %eax, %edx
decl %ebx
jne 0x6511
incq %rbp
cmpq %r10, %rbp
jne 0x6503
leal -0x2(%r13), %eax
movl %eax, %eax
movb %dh, (%rsi,%rax)
movq 0x8(%r15), %rsi
leal -0x1(%r13), %edi
movb %r12b, (%rsi,%rax)
movq (%r15), %rax
movb %dl, (%rax,%rdi)
movq 0x8(%r15), %rax
movb %r12b, (%rax,%rdi)
movl 0x28(%rsp), %esi
movl %ecx, %edx
movq (%r15), %rax
movl %r13d, %ecx
movb $0x4e, (%rax,%rcx)
movq 0x8(%r15), %rax
incl %r13d
movb $0x0, (%rax,%rcx)
leal 0x1(%rdx), %ecx
decl %esi
jne 0x6559
movl %r8d, %ecx
movq 0x38(%rsp), %r9
movl %edx, %esi
movq (%r15), %rax
movl %r13d, %edx
movb %r12b, (%rax,%rdx)
movq 0x8(%r15), %rax
incl %r13d
movb %r12b, (%rax,%rdx)
leal 0x1(%rsi), %edx
decl %ecx
jne 0x657f
movl %r11d, %eax
movl %esi, %edi
leal -0x1(%rdi), %ecx
movq (%r15), %rdx
movb $-0x5f, (%rdx,%rcx)
movq 0x8(%r15), %rdx
movb $-0x1, (%rdx,%rcx)
leal 0x1(%rdi), %esi
decl %eax
jne 0x65a0
movq (%r15), %rax
leal -0x1(%rsi), %ebp
movb $-0x5, (%rax,%rbp)
movq 0x8(%r15), %rax
movb $0x0, (%rax,%rbp)
movq 0x10(%rsp), %rax
movzbl 0x3(%rax,%r9,8), %ecx
cmpq $0x18, %rcx
ja 0x6617
movq 0x10(%rsp), %rax
movl 0x4(%rax,%r9,8), %edx
movl $0x80, %esi
shlq %cl, %rsi
movq 0x8(%rsp), %r9
incl %edi
movl %edx, %eax
movb (%r9,%rax), %al
movq (%r15), %rcx
movb %al, (%rcx,%rdi)
movq 0x8(%r15), %rax
movb $0x0, (%rax,%rdi)
incl %edx
decq %rsi
jne 0x65f5
leal 0x1(%rdi), %esi
movl %edi, %ebp
movq (%r15), %rcx
movw $0xffff, %dx            # imm = 0xFFFF
movl %esi, %edi
subl %r13d, %edi
je 0x6665
movl %r13d, %r13d
addq %rcx, %r13
movw $0xffff, %dx            # imm = 0xFFFF
xorl %ebx, %ebx
movzbl (%r13,%rbx), %eax
shll $0x8, %eax
xorl %eax, %edx
movl $0x8, %eax
leal (%rdx,%rdx), %r9d
movl %r9d, %r14d
xorl $0x1021, %r14d          # imm = 0x1021
testw %dx, %dx
cmovnsl %r9d, %r14d
movl %r14d, %edx
decl %eax
jne 0x6641
incq %rbx
cmpq %rdi, %rbx
jb 0x6631
movl %esi, %eax
movb %dh, (%rcx,%rax)
movq 0x8(%r15), %rcx
leal 0x2(%rbp), %esi
movb %r12b, (%rcx,%rax)
movq (%r15), %rax
movb %dl, (%rax,%rsi)
movq 0x8(%r15), %rax
addl $0x3, %ebp
movb %r12b, (%rax,%rsi)
movl 0x24(%rsp), %eax
movq (%r15), %rcx
movl %ebp, %edx
movb $0x4e, (%rcx,%rdx)
movq 0x8(%r15), %rcx
incl %ebp
movb $0x0, (%rcx,%rdx)
decl %eax
jne 0x668a
movq 0x38(%rsp), %r14
incq %r14
cmpq 0x70(%rsp), %r14
jne 0x63fc
cmpl $0x1869, %ebp           # imm = 0x1869
movq 0x30(%rsp), %r14
movq 0x18(%rsp), %rdx
jle 0x67b8
jmp 0x67d3
movl $0x1866, %ecx           # imm = 0x1866
subl %eax, %ecx
leal (,%r13,2), %r11d
movl $0x1, %edi
movl $0x1, %r9d
movl $0x1, %ebx
movl $0x1, %r8d
movl %r8d, %eax
cmpl %r11d, %ecx
setae %dl
cmpl $0xc, %r8d
setb %sil
andb %dl, %sil
movl $0x0, %edx
cmovnel %r11d, %edx
subl %edx, %ecx
movzbl %sil, %r8d
addl %eax, %r8d
cmpl %r13d, %ecx
jb 0x638c
cmpl $0xa, %edi
movl $0x0, %eax
cmovbl %r13d, %eax
adcl $0x0, %edi
subl %eax, %ecx
cmpl %r13d, %ecx
jb 0x638c
cmpl $0x16, %r9d
movl $0x0, %eax
cmovbl %r13d, %eax
adcl $0x0, %r9d
subl %eax, %ecx
cmpl %r13d, %ecx
jb 0x638c
cmpl $0x3c, %ebx
movl $0x0, %eax
cmovbl %r13d, %eax
adcl $0x0, %ebx
subl %eax, %ecx
cmpl %r13d, %ecx
jb 0x638c
cmpl $0xc, %r8d
setb %al
cmpl $0xa, %edi
setb %dl
cmpl $0x16, %r9d
setb %sil
orb %dl, %sil
cmpl $0x3c, %ebx
setb %dl
orb %sil, %dl
orb %al, %dl
cmpb $0x1, %dl
jne 0x638c
testl %ecx, %ecx
jne 0x66f4
jmp 0x638c
xorl %ebp, %ebp
movq 0x30(%rsp), %r14
movq 0x18(%rsp), %rdx
movq (%r15), %rax
movl %ebp, %ecx
movb $0x4e, (%rax,%rcx)
movq 0x8(%r15), %rax
incl %ebp
movb $0x0, (%rax,%rcx)
cmpl $0x186a, %ebp           # imm = 0x186A
jne 0x67b8
leaq 0x1(%rdx), %rbx
movq 0x50(%rsp), %rbp
movzbl 0x145008(%rbp), %ecx
cmpq %rcx, %rdx
jb 0x6279
leaq 0x1(%r14), %rax
movzbl 0x145007(%rbp), %ecx
cmpq %rcx, %r14
movq %rax, %r14
movq 0x40(%rsp), %rax
jb 0x6254
movl $0x1, %esi
movq 0x8(%rsp), %rdi
callq 0x1150
movl 0x20(%rsp), %eax
movb %al, 0x145005(%rbp)
movl $0x7, 0x141000(%rbp)
movb $0x1, 0x145006(%rbp)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %esi
callq 0x1150
leaq 0x40008(%rbp), %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, (%rbp,%rbx)
movq -0x8(%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x6873
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%r14,%rbx,4)
movq (%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x688f
movl $0x1, %esi
callq 0x1150
movq $0x0, (%r14,%rbx,4)
addq $0x4, %rbx
cmpq $0x400, %rbx            # imm = 0x400
jne 0x6857
incq %r15
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %r14           # imm = 0x1000
cmpq $0x100, %r15            # imm = 0x100
jne 0x6855
jmp 0x61d6
movl $0x1, %esi
callq 0x1150
leaq 0x40008(%rbp), %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, (%rbp,%rbx)
movq -0x8(%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x68f5
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%r14,%rbx,4)
movq (%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x6911
movl $0x1, %esi
callq 0x1150
movq $0x0, (%r14,%rbx,4)
addq $0x4, %rbx
cmpq $0x400, %rbx            # imm = 0x400
jne 0x68d9
incq %r15
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %r14           # imm = 0x1000
cmpq $0x100, %r15            # imm = 0x100
jne 0x68d7
jmp 0x61d6
movl $0x1, %esi
movq 0x8(%rsp), %rdi
callq 0x1150
leaq 0x40008(%rbp), %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, (%rbp,%rbx)
movq -0x8(%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x697c
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%r14,%rbx,4)
movq (%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x6998
movl $0x1, %esi
callq 0x1150
movq $0x0, (%r14,%rbx,4)
addq $0x4, %rbx
cmpq $0x400, %rbx            # imm = 0x400
jne 0x6960
incq %r15
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %r14           # imm = 0x1000
cmpq $0x100, %r15            # imm = 0x100
jne 0x695e
jmp 0x61d6
movl $0x1, %esi
movq 0x8(%rsp), %rdi
callq 0x1150
leaq 0x40008(%rbp), %r14
xorl %r15d, %r15d
xorl %ebx, %ebx
movl $0x0, (%rbp,%rbx)
movq -0x8(%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x6a03
movl $0x1, %esi
callq 0x1150
movq $0x0, -0x8(%r14,%rbx,4)
movq (%r14,%rbx,4), %rdi
testq %rdi, %rdi
je 0x6a1f
movl $0x1, %esi
callq 0x1150
movq $0x0, (%r14,%rbx,4)
addq $0x4, %rbx
cmpq $0x400, %rbx            # imm = 0x400
jne 0x69e7
incq %r15
addq $0x400, %rbp            # imm = 0x400
addq $0x1000, %r14           # imm = 0x1000
cmpq $0x100, %r15            # imm = 0x100
jne 0x69e5
leaq 0x1adc(%rip), %rsi      # 0x8531
jmp 0x6204