// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/os8.c
// Function: os8MergeEmptyRegions
static int os8MergeEmptyRegions(
  struct mountedFS *mount
)
{
  struct OS8data *data = &mount->os8data;
  uint16_t i, entrysz, entries, off = OS8_DH_SIZE;

  entrysz = OS8_DI_SIZE + (-os8SXT(le16toh(data->buf[OS8_DH_EXTRA])));
  entries = os8Neg(le16toh(data->buf[OS8_DH_ENTRIES]));

  if (entries > 1) {
    for (i = 0; i < (entries - 1); i++) {
      if (os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) == 0) {
        if (os8Word(le16toh(data->buf[off + OS8_ED_SIZE + OS8_DI_FNAME1])) == 0) {
          data->buf[off + OS8_ED_LENGTH] =
            htole16(os8Value(le16toh(data->buf[off + OS8_ED_LENGTH]) +
                             le16toh(data->buf[off + OS8_ED_SIZE + OS8_ED_LENGTH])));
          data->buf[OS8_DH_ENTRIES] = htole16(os8Value(-(entries - 1)));

          os8SlideUp(mount, off + OS8_ED_SIZE,
                     off + (2 * OS8_ED_SIZE), entrysz, entries - 2);
          return 1;
        }
      } else off += entrysz;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x18(%rbp)
movw $0x5, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x1c(%rax), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x148b0
movzwl %ax, %ecx
xorl %eax, %eax
subl %ecx, %eax
addl $0x5, %eax
movw %ax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x14(%rax), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14860
movw %ax, -0x1e(%rbp)
movzwl -0x1e(%rbp), %eax
cmpl $0x1, %eax
jle 0x1751e
movw $0x0, -0x1a(%rbp)
movzwl -0x1a(%rbp), %eax
movzwl -0x1e(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x1751c
movq -0x18(%rbp), %rax
movzwl -0x20(%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
jne 0x174fb
movq -0x18(%rbp), %rax
movzwl -0x20(%rbp), %ecx
addl $0x2, %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
jne 0x174f9
movq -0x18(%rbp), %rax
movzwl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %eax
movl %eax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movzwl -0x20(%rbp), %ecx
addl $0x2, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movw %ax, %cx
movl -0x24(%rbp), %eax
movzwl %cx, %ecx
addl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, %dx
movq -0x18(%rbp), %rax
movzwl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, 0x14(%rax,%rcx,2)
movzwl -0x1e(%rbp), %ecx
subl $0x1, %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rdi
movzwl -0x20(%rbp), %eax
addl $0x2, %eax
movw %ax, %si
movzwl -0x20(%rbp), %eax
addl $0x4, %eax
movw %ax, %dx
movw -0x1c(%rbp), %cx
movzwl -0x1e(%rbp), %eax
subl $0x2, %eax
movzwl %si, %esi
movzwl %dx, %edx
movzwl %cx, %ecx
movzwl %ax, %r8d
callq 0x15150
movl $0x1, -0x4(%rbp)
jmp 0x17525
jmp 0x17509
movzwl -0x1c(%rbp), %ecx
movzwl -0x20(%rbp), %eax
addl %ecx, %eax
movw %ax, -0x20(%rbp)
jmp 0x1750b
movw -0x1a(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x1a(%rbp)
jmp 0x173bd
jmp 0x1751e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq