// File: /workspace/github_c_makefile_star2_O1/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 0x9ec4(%rip), %rax      # 0x18fc8
movl (%rax), %ebp
leaq 0x9cb3(%rip), %rbx      # 0x18dc0
btl $0x13, %ebp
jae 0xf153
movq 0x9ca6(%rip), %rsi      # 0x18dc0
testq %rsi, %rsi
je 0xf153
leaq 0x9eaa(%rip), %rax      # 0x18fd0
movq 0x98(%rax), %r14
leaq 0x9c8c(%rip), %r15      # 0x18dc0
movq %r15, %rbx
movq %r14, %rdi
callq 0x31c0
testl %eax, %eax
je 0xf153
movq 0x48(%rbx), %rsi
addq $0x48, %rbx
testq %rsi, %rsi
jne 0xf137
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 0xf222
cmpb $0x0, 0x8(%rbx)
je 0xf25b
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 0xda0d
testl %eax, %eax
je 0xf261
incl %ebp
cmpl $0x7, %ebp
jne 0xf1a5
incq %r15
movzbl 0x8(%rbx), %eax
movl $0x1, %r13d
cmpq %rax, %r15
jb 0xf18a
jmp 0xf261
leaq 0x9da7(%rip), %rax      # 0x18fd0
movq 0x20(%rax), %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x3290
movq %rax, %r14
testl $0xffc0, %r14d          # imm = 0xFFC0
jne 0xf256
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0xf173
xorl %r13d, %r13d
jmp 0xf261
movl $0x1, %r13d
movl %r13d, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq