// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/fsio/os8.c
// Function: os8Newfs
static int os8Newfs(
  struct mountedFS *mount,
  size_t UNUSED(size)
)
{
  struct OS8data *data = &mount->os8data;
  uint16_t extra = 1;
  struct OS8device *dev = OS8Devices;
  uint8_t unit;
  uint16_t i;

  if (SWISSET('t')) {
    while (dev->name != NULL) {
      if (strcmp(SWGETVAL('t'), dev->name) == 0)
        goto found;

      dev++;
    }
    dev = OS8Devices;
  }
 found:
  mount->skip = dev->skip;
  data->device = dev;

  if (SWISSET('e')) {
    char *endptr;

    extra = strtoul(SWGETVAL('e'), &endptr, 10);
    if ((extra > 63) || (*endptr != '\0'))
      return 0;
  }

  for (unit = 0; unit < dev->filesys; unit++) {
    data->valid |= (1 << unit);

    for (i = OS8_DSSTART; i <= OS8_DSLAST; i++) {
      uint16_t buf[OS8_BLOCKSIZE];
      uint16_t entries = i == OS8_DSSTART ? 1 : 0;

      buf[OS8_DH_ENTRIES] = htole16(os8Value(-entries));
      buf[OS8_DH_START] = htole16(os8Value(OS8_DATA));
      buf[OS8_DH_NEXT] = htole16(os8Value(0));
      buf[OS8_DH_FLAGWD] = htole16(os8Value(0));
      buf[OS8_DH_EXTRA] = htole16(os8Value(-extra));

      buf[OS8_DH_SIZE + OS8_ED_IND] = htole16(os8Value(0));
      buf[OS8_DH_SIZE + OS8_ED_LENGTH] =
        htole16(os8Value(-(dev->blocks[unit] - OS8_DATA)));

      if (os8WriteBlock(mount, unit, i, buf) == 0)
        return 0;
    }
  }
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdi, 0x8(%rsp)
leaq 0xa1f6(%rip), %rax      # 0x18fd8
movl (%rax), %ebp
leaq 0x9fe5(%rip), %rbx      # 0x18dd0
btl $0x13, %ebp
jae 0xee31
movq 0x9fd8(%rip), %rsi      # 0x18dd0
testq %rsi, %rsi
je 0xee31
leaq 0xa1dc(%rip), %rax      # 0x18fe0
movq 0x98(%rax), %r14
leaq 0x9fbe(%rip), %r15      # 0x18dd0
movq %r15, %rbx
movq %r14, %rdi
callq 0x31d0
testl %eax, %eax
je 0xee31
movq 0x48(%rbx), %rsi
addq $0x48, %rbx
testq %rsi, %rsi
jne 0xee15
movq %r15, %rbx
movq 0x18(%rbx), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x40(%rcx)
movq %rbx, 0x50(%rcx)
movw $0x1, %r14w
testb $0x10, %bpl
jne 0xef00
cmpb $0x0, 0x8(%rbx)
je 0xef39
negl %r14d
andl $0xfff, %r14d           # imm = 0xFFF
xorl %r15d, %r15d
movl $0x1, %ebp
movl $0x1, %eax
movl %r15d, %ecx
shll %cl, %eax
movq 0x8(%rsp), %rcx
orb %al, 0x59(%rcx)
movzbl %r15b, %r12d
xorl %r13d, %r13d
cmpl $0x1, %ebp
movl $0x0, %eax
movl $0xfff, %ecx            # imm = 0xFFF
cmovel %ecx, %eax
movw %ax, 0x10(%rsp)
movl $0x7, 0x12(%rsp)
movw %r13w, 0x16(%rsp)
movw %r14w, 0x18(%rsp)
movw %r13w, 0x1a(%rsp)
movw $0x7, %ax
subw 0x20(%rbx,%r15,2), %ax
andl $0xfff, %eax            # imm = 0xFFF
movw %ax, 0x1c(%rsp)
movq 0x8(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
leaq 0x10(%rsp), %rcx
callq 0xd79b
testl %eax, %eax
je 0xef3f
incl %ebp
cmpl $0x7, %ebp
jne 0xee83
incq %r15
movzbl 0x8(%rbx), %eax
movl $0x1, %r13d
cmpq %rax, %r15
jb 0xee68
jmp 0xef3f
leaq 0xa0d9(%rip), %rax      # 0x18fe0
movq 0x20(%rax), %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x32a0
movq %rax, %r14
testl $0xffc0, %r14d          # imm = 0xFFC0
jne 0xef34
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0xee51
xorl %r13d, %r13d
jmp 0xef3f
movl $0x1, %r13d
movl %r13d, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq