// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/fsio/fsio.c
// Function: doNewfs
static void doNewfs(void)
{
  struct FSdef *filesys;
  struct mountedFS mount;
  char ch = 0;
  int status;
  size_t size = 0;

  if ((filesys = lookupFS(words[1])) != NULL) {
    if ((filesys->newfs == NULL) && ((filesys->flags & FS_EMPTYFILE) == 0)) {
      fprintf(stderr,
              "newfs: \"%s\" does not support the newfs command\n", words[1]);
      return;
    }

    if (access(words[0], F_OK) == 0) {
      fprintf(stderr, "newfs: \"%s\" already exists\n", words[0]);
      return;
    }

    memset(&mount, 0, sizeof(mount));

    /*
     * Get the required container file size.
     */
    if (filesys->size != NULL)
      size = (*filesys->size)();

    if ((mount.container = fopen(words[0], "w+")) != NULL) {
      off_t offset = size - 1;

      mount.skip = 0;

      /*
       * If an empty file is valid, we are all done
       */
      if ((filesys->flags & FS_EMPTYFILE) != 0)
        return;

      if ((fseeko(mount.container, offset + mount.skip, SEEK_SET) == 0) &&
          (fwrite(&ch, 1, 1, mount.container) == 1)) {
        mount.filesys = filesys;
        mount.blocksz = filesys->blocksz;

        status = (*filesys->newfs)(&mount, size);

        fclose(mount.container);
        if (status == 0)
          unlink(words[0]);
      } else {
        fprintf(stderr, "newfs: failed to extend \"%s\"\n", words[0]);
        fclose(mount.container);
        unlink(words[0]);
      }
    } else fprintf(stderr, "newfs: failed to create \"%s\"\n", words[0]);
  } else fprintf(stderr, "newfs: \"%s\" is not a supported file system type\n", words[1]);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x960, %rsp            # imm = 0x960
movb $0x0, 0x7(%rsp)
movq 0x1497e(%rip), %r15     # 0x180b8
movq 0x8(%r15), %r14
movq %r14, %rdi
callq 0x4df3
testq %rax, %rax
je 0x3842
movq %rax, %rbx
cmpq $0x0, 0x40(%rax)
jne 0x3763
testb $0x4, 0x18(%rbx)
je 0x38d7
movq (%r15), %rdi
xorl %esi, %esi
callq 0x3260
testl %eax, %eax
je 0x3858
leaq 0x8(%rsp), %rdi
xorl %r14d, %r14d
movl $0x958, %edx            # imm = 0x958
xorl %esi, %esi
callq 0x3170
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0x3797
callq *%rax
movq %rax, %r14
movq 0x1491a(%rip), %rax     # 0x180b8
movq (%rax), %rdi
leaq 0xbb19(%rip), %rsi      # 0xf2c1
callq 0x3280
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x3875
andq $0x0, 0x48(%rsp)
testb $0x4, 0x18(%rbx)
jne 0x3835
movq %rax, %r15
leaq -0x1(%r14), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x3270
testl %eax, %eax
jne 0x3892
leaq 0x7(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq %r15, %rcx
callq 0x32d0
cmpq $0x1, %rax
jne 0x3892
leaq 0x8(%rsp), %r15
movq %rbx, 0x20(%r15)
movq 0x20(%rbx), %rax
movq %rax, 0x28(%r15)
movq %r15, %rdi
movq %r14, %rsi
callq *0x40(%rbx)
movl %eax, %ebx
movq 0x38(%r15), %rdi
callq 0x3110
testl %ebx, %ebx
jne 0x3835
movq 0x1488b(%rip), %rax     # 0x180b8
movq (%rax), %rdi
callq 0x3080
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
retq
movq 0x137af(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xbaad(%rip), %rsi      # 0xf300
jmp 0x38e8
movq 0x13799(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq 0x1484f(%rip), %rax     # 0x180b8
movq (%rax), %rdx
leaq 0xba32(%rip), %rsi      # 0xf2a5
jmp 0x38eb
movq 0x1377c(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq 0x14832(%rip), %rax     # 0x180b8
movq (%rax), %rdx
leaq 0xba52(%rip), %rsi      # 0xf2e2
jmp 0x38eb
movq 0x1375f(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq 0x14815(%rip), %rax     # 0x180b8
movq (%rax), %rdx
leaq 0xba17(%rip), %rsi      # 0xf2c4
xorl %eax, %eax
callq 0x31e0
movq %r15, %rdi
callq 0x3110
movq 0x147f5(%rip), %rax     # 0x180b8
movq (%rax), %rdi
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
jmp 0x3080
movq 0x1371a(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xb98d(%rip), %rsi      # 0xf275
movq %r14, %rdx
xorl %eax, %eax
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
jmp 0x31e0