// File: /workspace/github_c_makefile_star2_O1/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 0x141ea(%rip), %r14     # 0x190a8
movq 0x8(%r14), %rbx
leaq 0x140f7(%rip), %r15     # 0x18fc0
movq (%r15), %r15
testq %r15, %r15
je 0x4ee3
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0x31c0
testl %eax, %eax
jne 0x4ec9
jmp 0x4ee6
xorl %r15d, %r15d
testq %r15, %r15
je 0x4fd8
cmpq $0x0, 0x40(%r15)
jne 0x4f01
testb $0x4, 0x18(%r15)
je 0x5010
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3250
testl %eax, %eax
je 0x4feb
leaq 0x8(%rsp), %rdi
xorl %ebx, %ebx
movl $0x958, %edx            # imm = 0x958
xorl %esi, %esi
callq 0x3170
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x4f34
callq *%rax
movq %rax, %rbx
movq 0x1416d(%rip), %rax     # 0x190a8
movq (%rax), %rdi
leaq 0xb37c(%rip), %rsi      # 0x102c1
callq 0x3270
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x4ff2
movq $0x0, 0x48(%rsp)
testb $0x4, 0x18(%r15)
jne 0x5003
leaq -0x1(%rbx), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x3260
testl %eax, %eax
jne 0x4ff9
movq 0x40(%rsp), %rcx
leaq 0x7(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x32c0
cmpq $0x1, %rax
jne 0x4ff9
leaq 0x8(%rsp), %r14
movq %r15, 0x20(%r14)
movq 0x20(%r15), %rax
movq %rax, 0x28(%r14)
movq %r14, %rdi
movq %rbx, %rsi
callq *0x40(%r15)
movl %eax, %ebx
movq 0x38(%r14), %rdi
callq 0x3110
testl %ebx, %ebx
jne 0x5003
movq 0x140da(%rip), %rax     # 0x190a8
movq (%rax), %rdi
callq 0x3080
jmp 0x5003
movq 0x13011(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xb317(%rip), %rsi      # 0x10300
jmp 0x5021
callq 0x33f7
jmp 0x5003
callq 0x33d5
jmp 0x5003
leaq 0x40(%rsp), %rdi
callq 0x3397
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
retq
movq 0x12fd9(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xb254(%rip), %rsi      # 0x10275
movq %rbx, %rdx
xorl %eax, %eax
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
jmp 0x31d0