// File: /workspace/github_cpp_makefile_star2_O2/atsidaev[P]trx2x/DiskImage.cpp
// Function: TDiskImage::writeTRD(int)
void TDiskImage::writeTRD(int hfile)
{
   VGFIND_SECTOR vgfs;

// prepare nullbuf...
   unsigned char nullbuf[256];
   for(int i=0; i < 256; i++) nullbuf[i] = '*';
   memcpy(nullbuf, errsect, sizeof(errsect));

   for(unsigned int trk=0; trk <= unsigned(MaxTrack); trk++)
      for(unsigned int side=0; side <= unsigned(MaxSide); side++)
         for(unsigned int sec=0; sec < 16; sec++)
         {
            if(FindSector(trk, side, sec+1, &vgfs))
            {
               write(hfile, vgfs.SectorPointer, 256);
               if((!vgfs.CRCOK)||(!vgfs.vgfa.CRCOK)) cout << "Warning: sector "<<(sec+1)<<" on track "<<trk<<", side "<<side<<" with BAD CRC!" << endl;
               if(vgfs.SectorLength != 256) cout << "Warning: sector "<<(sec+1)<<" on track "<<trk<<", side "<<side<<" is non 256 bytes!" << endl;
            }
            else 
            {
               write(hfile, nullbuf, 256);
               cout << "DANGER! Sector "<<(sec+1)<<" on track "<<trk<<", side "<<side<<" not found!" << endl;
            }
         }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %esi, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x2076
movb $0x2a, 0x70(%rsp,%rax)
incq %rax
jmp 0x2064
movq 0x80e1(%rip), %rax      # 0xa15e
leaq 0x70(%rsp), %rcx
movq %rax, 0x2e(%rcx)
movaps 0x80c3(%rip), %xmm0     # 0xa150
movaps %xmm0, 0x20(%rcx)
movaps 0x80a8(%rip), %xmm0     # 0xa140
movaps %xmm0, 0x10(%rcx)
movaps 0x808d(%rip), %xmm0     # 0xa130
movaps %xmm0, (%rcx)
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
movzbl 0x145007(%rax), %eax
cmpq %rax, %r12
ja 0x2248
movzbl %r12b, %r15d
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movzbl 0x145008(%rax), %eax
cmpq %rax, %rbp
ja 0x2240
movzbl %bpl, %r13d
pushq $0x1
popq %rbx
cmpq $0x11, %rbx
je 0x2238
movzbl %bl, %ecx
movq 0x10(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
leaq 0x18(%rsp), %r8
xorl %r9d, %r9d
callq 0x1d64
testb %al, %al
je 0x21b1
movq 0x50(%rsp), %rsi
movl $0x100, %edx            # imm = 0x100
movl 0xc(%rsp), %edi
callq 0x1050
cmpb $0x0, 0x69(%rsp)
je 0x212e
cmpb $0x0, 0x49(%rsp)
jne 0x2197
movq 0x7ea3(%rip), %rdi      # 0x9fd8
leaq 0x52e3(%rip), %rsi      # 0x741f
callq 0x1120
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10a0
movq %rax, %rdi
leaq 0x52da(%rip), %rsi      # 0x7430
callq 0x1120
movq %rax, %rdi
movq %r12, %rsi
callq 0x10a0
movq %rax, %rdi
leaq 0x52cb(%rip), %rsi      # 0x743b
callq 0x1120
movq %rax, %rdi
movq %rbp, %rsi
callq 0x10a0
movq %rax, %rdi
leaq 0x5437(%rip), %rsi      # 0x75c1
callq 0x1120
movq %rax, %rdi
callq 0x1070
cmpl $0x100, 0x58(%rsp)      # imm = 0x100
leaq 0x5279(%rip), %rsi      # 0x741f
leaq 0x5446(%rip), %r14      # 0x75f3
jne 0x21d2
jmp 0x2230
movl $0x100, %edx            # imm = 0x100
movl 0xc(%rsp), %edi
leaq 0x70(%rsp), %rsi
callq 0x1050
leaq 0x5278(%rip), %rsi      # 0x7443
leaq 0x53bf(%rip), %r14      # 0x7591
movq 0x7dff(%rip), %rdi      # 0x9fd8
callq 0x1120
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10a0
movq %rax, %rdi
leaq 0x523d(%rip), %rsi      # 0x7430
callq 0x1120
movq %rax, %rdi
movq %r12, %rsi
callq 0x10a0
movq %rax, %rdi
leaq 0x522e(%rip), %rsi      # 0x743b
callq 0x1120
movq %rax, %rdi
movq %rbp, %rsi
callq 0x10a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x1120
movq %rax, %rdi
callq 0x1070
incq %rbx
jmp 0x20e0
incq %rbp
jmp 0x20c4
incq %r12
jmp 0x20a9
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq