// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/rt11.c
// Function: rt11ReadBlock
int rt11ReadBlock(
  struct mountedFS *mount,
  uint8_t unit,
  unsigned int block,
  void *buf
)
{
  struct RT11data *data = &mount->rt11data;
  char *buffer = buf == NULL ? data->buf : buf;
  int status = 0;

  if (RT11_PARTITIONVALID(data, unit)) {
    if (block > data->maxblk[unit]) {
      ERROR("Attempt to read block (%u) outside file system \"%s%o:\"\n",
            block, mount->name, unit);
      return 0;
    }

#ifdef DEBUG
    if ((mount->flags & FS_DEBUG) != 0)
      fprintf(DEBUGout, ">> %s%o: (rt11) Reading logical block %o\n",
              mount->name, unit, block);
#endif

    if (data->sectorsz != 0) {
      /*
       * The sectors making up the disk are sector-interleaved. The algorithm
       * below is for RX01/RX02 interleave. Note that all such devices are
       * small enough that there can only be a single file system present.
       */
      unsigned int count = RT11_BLOCKSIZE / data->sectorsz;
      unsigned int sectno = block * count;

      do {
        unsigned int sector = MapLogToPhys(sectno);

        status = FSioReadSector(mount, sector, data->sectorsz, buffer);

        count--;
        buffer += data->sectorsz;
        sectno++;
      } while ((count != 0) && (status != 0));
    } else status = FSioReadBlock(mount, (unit << 16) | block, buffer);

    if (status == 0)
      ERROR("I/O error on \"%s%o:\"\n", mount->name, unit);
  } else ERROR("Invalid device \"%s%o:\"\n", mount->name, unit);

  return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xbdfc
movq -0x28(%rbp), %rax
addq $0x42a, %rax            # imm = 0x42A
movq %rax, -0x48(%rbp)
jmp 0xbe04
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
movzbl -0x11(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x58(%rbp), %rax
movslq %ecx, %rcx
movzwl 0xa(%rax,%rcx,2), %eax
movl %eax, -0x4c(%rbp)
movzbl -0x11(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl -0x4c(%rbp), %eax
movl %edx, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xc049
movl -0x18(%rbp), %eax
movq -0x28(%rbp), %rcx
movzbl -0x11(%rbp), %edx
movzwl 0x2a(%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jbe 0xbef0
movq 0x12180(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rcx
addq $0x8, %rcx
movzbl -0x11(%rbp), %r8d
leaq 0xe130(%rip), %rsi      # 0x19fc2
movb $0x0, %al
callq 0x31c0
leaq 0x13348(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xbee4
leaq 0x1333b(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x12109(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xbee4
leaq 0x13325(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rcx
addq $0x8, %rcx
movzbl -0x11(%rbp), %r8d
leaq 0xe0e5(%rip), %rsi      # 0x19fc2
movb $0x0, %al
callq 0x31c0
movl $0x0, -0x4(%rbp)
jmp 0xc0bc
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xbf28
leaq 0x132e1(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
movl -0x18(%rbp), %r8d
leaq 0xe0d9(%rip), %rsi      # 0x19ffa
movb $0x0, %al
callq 0x31c0
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xbfba
movq -0x28(%rbp), %rcx
movl $0x200, %eax            # imm = 0x200
xorl %edx, %edx
divl 0x4(%rcx)
movl %eax, -0x38(%rbp)
movl -0x18(%rbp), %eax
imull -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %edi
callq 0xbd60
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
movq -0x28(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x30(%rbp), %rcx
callq 0x5620
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x38(%rbp)
movb %al, -0x59(%rbp)
je 0xbfb1
cmpl $0x0, -0x34(%rbp)
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0xbf51
jmp 0xbfd4
movq -0x10(%rbp), %rdi
movzbl -0x11(%rbp), %esi
shll $0x10, %esi
orl -0x18(%rbp), %esi
movq -0x30(%rbp), %rdx
callq 0x5520
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0xc047
movq 0x12017(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
leaq 0xe02d(%rip), %rsi      # 0x1a024
movb $0x0, %al
callq 0x31c0
leaq 0x131e3(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xc045
leaq 0x131d6(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x11fa4(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xc045
leaq 0x131c0(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
leaq 0xdfe6(%rip), %rsi      # 0x1a024
movb $0x0, %al
callq 0x31c0
jmp 0xc047
jmp 0xc0b6
movq 0x11fa8(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
leaq 0xdfd4(%rip), %rsi      # 0x1a03a
movb $0x0, %al
callq 0x31c0
leaq 0x13174(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xc0b4
leaq 0x13167(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x11f35(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xc0b4
leaq 0x13151(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
leaq 0xdf8d(%rip), %rsi      # 0x1a03a
movb $0x0, %al
callq 0x31c0
jmp 0xc0b6
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)