// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x20(%rbp)
movw $0x1, -0x22(%rbp)
leaq 0x8f64(%rip), %rax      # 0x1ee70
movq %rax, -0x30(%rbp)
leaq 0x92e1(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0x15f69
jmp 0x15f25
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
je 0x15f5e
leaq 0x92ca(%rip), %rax      # 0x1f200
movq 0x98(%rax), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
callq 0x31b0
cmpl $0x0, %eax
jne 0x15f50
jmp 0x15f6b
movq -0x30(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x30(%rbp)
jmp 0x15f25
leaq 0x8f0b(%rip), %rax      # 0x1ee70
movq %rax, -0x30(%rbp)
jmp 0x15f6b
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
leaq 0x926a(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x15fd8
leaq 0x9261(%rip), %rax      # 0x1f200
movq 0x20(%rax), %rdi
leaq -0x40(%rbp), %rsi
movl $0xa, %edx
callq 0x3280
movw %ax, -0x22(%rbp)
movzwl -0x22(%rbp), %eax
cmpl $0x3f, %eax
jg 0x15fca
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x15fd6
movl $0x0, -0x4(%rbp)
jmp 0x1614b
jmp 0x15fd8
movb $0x0, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
movq -0x30(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jge 0x16144
movzbl -0x31(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x20(%rbp), %rax
movzbl 0x11(%rax), %ecx
orl %edx, %ecx
movb %cl, 0x11(%rax)
movw $0x1, -0x34(%rbp)
movzwl -0x34(%rbp), %eax
cmpl $0x6, %eax
jg 0x16135
movzwl -0x34(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
movw %ax, -0x242(%rbp)
movzwl -0x242(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x240(%rbp)
movl $0x7, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x23e(%rbp)
xorl %edi, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x23c(%rbp)
xorl %edi, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x23a(%rbp)
movzwl -0x22(%rbp), %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x238(%rbp)
xorl %edi, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x236(%rbp)
movq -0x30(%rbp), %rax
movzbl -0x31(%rbp), %ecx
movzwl 0x20(%rax,%rcx,2), %ecx
subl $0x7, %ecx
xorl %eax, %eax
subl %ecx, %eax
movzwl %ax, %edi
callq 0x148e0
movzwl %ax, %edi
callq 0x14890
movw %ax, -0x234(%rbp)
movq -0x10(%rbp), %rdi
movb -0x31(%rbp), %al
movzwl -0x34(%rbp), %edx
leaq -0x240(%rbp), %rcx
movzbl %al, %esi
callq 0x13450
cmpl $0x0, %eax
jne 0x16122
movl $0x0, -0x4(%rbp)
jmp 0x1614b
jmp 0x16124
movw -0x34(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x34(%rbp)
jmp 0x1600e
jmp 0x16137
movb -0x31(%rbp), %al
addb $0x1, %al
movb %al, -0x31(%rbp)
jmp 0x15fdc
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopw (%rax,%rax)