// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/os8.c
// Function: os8UpdateFile
void os8UpdateFile(
  struct mountedFS *mount,
  uint8_t unit,
  struct os8OpenFile *file
)
{
  struct OS8data *data = &mount->os8data;
  uint16_t off = file->offset;
  uint16_t empty = off + file->extra + OS8_DI_SIZE;
  uint16_t length = file->current == 0 ? 0 : file->current - file->start;
  uint16_t left = file->length - length;
  uint16_t space;

  if (os8ReadBlock(mount, unit, file->segment, NULL) == 0)
    return;

  /*
   * The directory entry is complete except for the # of blocks in use
   * which we can now update.
   */
  data->buf[off + file->extra + OS8_DI_LENGTH] = htole16(os8Value(-length));

  /*
   * Update the remaining space in the following empty file descriptor.
   */
  space = os8Neg(le16toh(data->buf[empty + OS8_ED_LENGTH])) + left;
  data->buf[empty + OS8_ED_LENGTH] = htole16(os8Value(-space));

  if (space == 0)
    /*
     * Remove the empty directory entry since it now occupies 0 blocks
     */
    os8SlideUp(mount, empty, empty + OS8_ED_SIZE, file->entrysz, file->remain);

  os8WriteBlock(mount, unit, file->segment, NULL);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movw 0xe(%rax), %ax
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
addl %ecx, %eax
addl $0x5, %eax
movw %ax, -0x24(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x3a(%rax), %eax
cmpl $0x0, %eax
jne 0x15007
xorl %eax, %eax
movl %eax, -0x30(%rbp)
jmp 0x1501c
movq -0x18(%rbp), %rax
movzwl 0x3a(%rax), %eax
movq -0x18(%rbp), %rcx
movzwl 0x38(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movw %ax, -0x26(%rbp)
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %eax
movzwl -0x26(%rbp), %ecx
subl %ecx, %eax
movw %ax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movb -0x9(%rbp), %al
movq -0x18(%rbp), %rcx
movzbl 0xc(%rcx), %edx
xorl %ecx, %ecx
movzbl %al, %esi
callq 0x132f0
cmpl $0x0, %eax
jne 0x15058
jmp 0x1513e
movzwl -0x26(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, %dx
movq -0x20(%rbp), %rax
movzwl -0x22(%rbp), %ecx
movq -0x18(%rbp), %rsi
movzwl 0x12(%rsi), %esi
addl %esi, %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movw %dx, 0x14(%rax,%rcx,2)
movq -0x20(%rbp), %rax
movzwl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzwl 0x14(%rax,%rcx,2), %edi
callq 0x14890
movzwl %ax, %edi
callq 0x14860
movzwl %ax, %eax
movzwl -0x28(%rbp), %ecx
addl %ecx, %eax
movw %ax, -0x2a(%rbp)
movzwl -0x2a(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, %dx
movq -0x20(%rbp), %rax
movzwl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, 0x14(%rax,%rcx,2)
movzwl -0x2a(%rbp), %eax
cmpl $0x0, %eax
jne 0x15125
movq -0x8(%rbp), %rdi
movw -0x24(%rbp), %si
movzwl -0x24(%rbp), %eax
addl $0x2, %eax
movw %ax, %dx
movq -0x18(%rbp), %rax
movw 0x10(%rax), %cx
movq -0x18(%rbp), %rax
movzwl %si, %esi
movzwl %dx, %edx
movzwl %cx, %ecx
movzwl 0x14(%rax), %r8d
callq 0x15150
movq -0x8(%rbp), %rdi
movb -0x9(%rbp), %al
movq -0x18(%rbp), %rcx
movzbl 0xc(%rcx), %edx
xorl %ecx, %ecx
movzbl %al, %esi
callq 0x13450
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)