// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/os8.c
// Function: rx01ReadBlock
static int rx01ReadBlock(
  struct mountedFS *mount,
  uint8_t unit,
  unsigned int block,
  void *buf
)
{
  unsigned int base = (block / RX01REPEAT) * RX01REPEAT;
  unsigned int offset = block % RX01REPEAT;
  uint16_t *buffer = buf;
  int i, j, k, status;

#ifdef DEBUG
  if ((mount->flags & FS_DEBUG) != 0)
    fprintf(DEBUGout, "  >>%s%o: rx01ReadBlock, base %u, offset %u\n",
            mount->name, unit, base, offset);
#endif

  /*
   * Convert to sector number
   */
  base *= OS8_BLOCKSIZE / OS8_RX01SS_W;

  /*
   * Read 4 sectors into the buffer
   */
  for (i = 0; i < 4; i++) {
    unsigned int sector = base + rx01interleave[(offset * 4) + i];
    unsigned char temp[OS8_RX01SS];

#ifdef DEBUG
    if ((mount->flags & FS_DEBUG) != 0)
      fprintf(DEBUGout, "  >> %s%o: (os8) Reading %u, track %u sector %u\n",
              mount->name, unit, sector,
              base + ((rx01interleave[(offset * 4) + i] + 1) / OS8_RX01SS),
              (rx01interleave[(offset * 4) + i] + 1) % OS8_RX01SS);
#endif

    if ((status = FSioReadSector(mount, sector, OS8_RX01SS, temp)) == 0) {
      ERROR("I/O error on \"%s%o:\"\n", mount->name, unit);
      return 0;
    }

    /*
     * Unpack 64 words from the temporary buffer
     */
    for (j = 0, k = 0; j < OS8_RX01SS_W; j += 2, k += 3) {
      buffer[j] = ((temp[k] << 4) | ((temp[k + 1] >> 4) & 0xF)) & 0xFFF;
      buffer[j + 1] = (((temp[k + 1] << 8) & 0xF00) | temp[k + 2]) & 0xFFF;
    }
    buffer += OS8_RX01SS_W;
  }
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl -0x18(%rbp), %eax
movl $0xd, %ecx
xorl %edx, %edx
divq %rcx
imulq $0xd, %rax, %rax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl $0xd, %ecx
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x12786
leaq 0xca87(%rip), %rax      # 0x1f1e8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
movl -0x24(%rbp), %r8d
movl -0x28(%rbp), %r9d
leaq 0x810a(%rip), %rsi      # 0x1a889
movb $0x0, %al
callq 0x31c0
movl -0x24(%rbp), %eax
shll $0x2, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x4, -0x34(%rbp)
jge 0x129be
movl -0x24(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x2, %ecx
addl -0x34(%rbp), %ecx
movl %ecx, %ecx
movl %ecx, %edx
leaq 0xc899(%rip), %rcx      # 0x1f050
movzwl (%rcx,%rdx,2), %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x1285c
leaq 0xca0d(%rip), %rax      # 0x1f1e8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xd8(%rbp)
movzbl -0x11(%rbp), %ecx
movl -0x44(%rbp), %r8d
movl -0x24(%rbp), %r9d
movl -0x28(%rbp), %eax
shll $0x2, %eax
addl -0x34(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
leaq 0xc843(%rip), %rax      # 0x1f050
movzwl (%rax,%rdx,2), %eax
addl $0x1, %eax
movl $0x80, %esi
cltd
idivl %esi
addl %eax, %r9d
movl -0x28(%rbp), %eax
shll $0x2, %eax
addl -0x34(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
leaq 0xc81d(%rip), %rax      # 0x1f050
movzwl (%rax,%rdx,2), %eax
addl $0x1, %eax
movl $0x80, %esi
cltd
idivl %esi
movl %edx, %eax
movq -0xd8(%rbp), %rdx
leaq 0x8064(%rip), %rsi      # 0x1a8b6
movl %eax, (%rsp)
movb $0x0, %al
callq 0x31c0
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
leaq -0xd0(%rbp), %rcx
movl $0x80, %edx
callq 0x5620
movl %eax, -0x40(%rbp)
cmpl $0x0, %eax
jne 0x128f3
movq 0xb775(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
leaq 0x778b(%rip), %rsi      # 0x1a024
movb $0x0, %al
callq 0x31c0
leaq 0xc941(%rip), %rax      # 0x1f1e8
cmpq $0x0, (%rax)
je 0x128e7
leaq 0xc934(%rip), %rax      # 0x1f1e8
movq (%rax), %rax
movq 0xb702(%rip), %rcx      # 0x1dfc0
cmpq (%rcx), %rax
je 0x128e7
leaq 0xc91e(%rip), %rax      # 0x1f1e8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
movzbl -0x11(%rbp), %ecx
leaq 0x7744(%rip), %rsi      # 0x1a024
movb $0x0, %al
callq 0x31c0
movl $0x0, -0x4(%rbp)
jmp 0x129c5
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
cmpl $0x40, -0x38(%rbp)
jge 0x129a2
movslq -0x3c(%rbp), %rax
movzbl -0xd0(%rbp,%rax), %eax
shll $0x4, %eax
movl -0x3c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl -0xd0(%rbp,%rcx), %ecx
sarl $0x4, %ecx
andl $0xf, %ecx
orl %ecx, %eax
andl $0xfff, %eax            # imm = 0xFFF
movw %ax, %dx
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
cltq
movzbl -0xd0(%rbp,%rax), %eax
shll $0x8, %eax
andl $0xf00, %eax            # imm = 0xF00
movl -0x3c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl -0xd0(%rbp,%rcx), %ecx
orl %ecx, %eax
andl $0xfff, %eax            # imm = 0xFFF
movw %ax, %dx
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x38(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x3c(%rbp)
jmp 0x12901
movq -0x30(%rbp), %rax
addq $0x80, %rax
movq %rax, -0x30(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x12796
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)