// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/os8.c
// Function: os8SlideDown
static void os8SlideDown(
  struct mountedFS *mount,
  uint16_t off,
  uint16_t entries,
  uint16_t entrysz,
  uint16_t *remain
)
{
  struct OS8data *data = &mount->os8data;
  uint16_t i, j, src = OS8_DH_SIZE, dst = OS8_DH_SIZE;
  uint16_t buf[OS8_BLOCKSIZE];

  /*
   * Build an updated directory header
   */
  buf[OS8_DH_ENTRIES] = htole16(os8Value(-(entries + 1)));
  buf[OS8_DH_START] = data->buf[OS8_DH_START];
  buf[OS8_DH_NEXT] = data->buf[OS8_DH_NEXT];
  buf[OS8_DH_FLAGWD] = htole16(os8Value(0));
  buf[OS8_DH_EXTRA] = data->buf[OS8_DH_EXTRA];

  for (i = 0; i < entries; i++) {
    uint16_t len;

    if (src == off) {
      dst += entrysz;
      *remain = entries - (i + 1);
    }

    len = 
      os8Word(le16toh(data->buf[src + OS8_DI_FNAME1])) ? entrysz : OS8_ED_SIZE;

    for (j = 0; j < len; j++)
      buf[dst++] = data->buf[src++];
  }

  /*
   * Now copy the updated directory segment back to the mount speccific buffer
   */
  memcpy(data->buf, buf, sizeof(buf));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movw %cx, %ax
movw %dx, %cx
movw %si, %dx
movq %rdi, -0x8(%rbp)
movw %dx, -0xa(%rbp)
movw %cx, -0xc(%rbp)
movw %ax, -0xe(%rbp)
movq %r8, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x20(%rbp)
movw $0x5, -0x26(%rbp)
movw $0x5, -0x28(%rbp)
movzwl -0xc(%rbp), %ecx
addl $0x1, %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x230(%rbp)
movq -0x20(%rbp), %rax
movw 0x16(%rax), %ax
movw %ax, -0x22e(%rbp)
movq -0x20(%rbp), %rax
movw 0x18(%rax), %ax
movw %ax, -0x22c(%rbp)
xorl %edi, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x22a(%rbp)
movq -0x20(%rbp), %rax
movw 0x1c(%rax), %ax
movw %ax, -0x228(%rbp)
movw $0x0, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
movzwl -0xc(%rbp), %ecx
cmpl %ecx, %eax
jge 0x14aa5
movzwl -0x26(%rbp), %eax
movzwl -0xa(%rbp), %ecx
cmpl %ecx, %eax
jne 0x149ec
movzwl -0xe(%rbp), %ecx
movzwl -0x28(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x28(%rbp)
movzwl -0xc(%rbp), %eax
movzwl -0x22(%rbp), %ecx
addl $0x1, %ecx
subl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, (%rax)
movq -0x20(%rbp), %rax
movzwl -0x26(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14f90
movzwl %ax, %eax
cmpl $0x0, %eax
je 0x14a20
movzwl -0xe(%rbp), %eax
movl %eax, -0x238(%rbp)
jmp 0x14a2d
movl $0x2, %eax
movl %eax, -0x238(%rbp)
jmp 0x14a2d
movl -0x238(%rbp), %eax
movw %ax, -0x232(%rbp)
movw $0x0, -0x24(%rbp)
movzwl -0x24(%rbp), %eax
movzwl -0x232(%rbp), %ecx
cmpl %ecx, %eax
jge 0x14a92
movq -0x20(%rbp), %rax
movw -0x26(%rbp), %cx
movw %cx, %dx
addw $0x1, %dx
movw %dx, -0x26(%rbp)
movzwl %cx, %ecx
movw 0x14(%rax,%rcx,2), %cx
movw -0x28(%rbp), %ax
movw %ax, %dx
addw $0x1, %dx
movw %dx, -0x28(%rbp)
movzwl %ax, %eax
movw %cx, -0x230(%rbp,%rax,2)
movw -0x24(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x24(%rbp)
jmp 0x14a40
jmp 0x14a94
movw -0x22(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x22(%rbp)
jmp 0x149ab
movq -0x20(%rbp), %rdi
addq $0x14, %rdi
leaq -0x230(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x31d0
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
nopw (%rax,%rax)