// File: /workspace/github_c_makefile_star2_O2/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 0xa264(%rip), %rax      # 0x17fd8
movl (%rax), %ebp
leaq 0xa053(%rip), %rbx      # 0x17dd0
btl $0x13, %ebp
jae 0xddae
leaq 0xa256(%rip), %r15      # 0x17fe0
movq %rbx, %r14
movq (%r14), %rsi
testq %rsi, %rsi
je 0xddae
movq 0x98(%r15), %rdi
callq 0x31d0
testl %eax, %eax
je 0xddab
addq $0x48, %r14
jmp 0xdd8d
movq %r14, %rbx
movq 0x18(%rbx), %rax
movq 0x8(%rsp), %rcx
movq %rax, 0x40(%rcx)
movq %rbx, 0x50(%rcx)
movw $0x1, %r14w
testb $0x10, %bpl
jne 0xde76
negl %r14d
andl $0xfff, %r14d           # imm = 0xFFF
xorl %r15d, %r15d
pushq $0x1
popq %r13
xorl %r12d, %r12d
movzbl 0x8(%rbx), %eax
cmpq %rax, %r15
jae 0xdebf
movl %r13d, %eax
movl %r15d, %ecx
shll %cl, %eax
movq 0x8(%rsp), %rcx
orb %al, 0x59(%rcx)
movzbl %r15b, %ebp
cmpl $0x7, %r13d
je 0xde6a
cmpl $0x1, %r13d
movl $0x0, %eax
movl $0xfff, %ecx            # imm = 0xFFF
cmovel %ecx, %eax
movw %ax, 0x10(%rsp)
movl $0x7, 0x12(%rsp)
andw $0x0, 0x16(%rsp)
movw %r14w, 0x18(%rsp)
andw $0x0, 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 %ebp, %esi
movl %r13d, %edx
leaq 0x10(%rsp), %rcx
callq 0xc6a8
incl %r13d
testl %eax, %eax
jne 0xde03
jmp 0xdeaa
incq %r15
pushq $0x1
popq %r13
jmp 0xdde2
leaq 0xa163(%rip), %rax      # 0x17fe0
movq 0x20(%rax), %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x32a0
movq %rax, %r14
testw $0xffc0, %r14w          # imm = 0xFFC0
jne 0xdea7
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0xddce
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, %r12d
jmp 0xdeaa