// File: /workspace/github_c_makefile_star2_O3/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 0x14252(%rip), %r14     # 0x190b8
movq 0x8(%r14), %rbx
leaq 0x1415f(%rip), %r15     # 0x18fd0
movq (%r15), %r15
testq %r15, %r15
je 0x4f77
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0x31d0
testl %eax, %eax
jne 0x4e71
cmpq $0x0, 0x40(%r15)
jne 0x4e9f
testb $0x4, 0x18(%r15)
je 0x4fad
movq (%r14), %rdi
xorl %esi, %esi
callq 0x3260
testl %eax, %eax
je 0x4f8a
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 0x4ed2
callq *%rax
movq %rax, %rbx
movq 0x141df(%rip), %rax     # 0x190b8
movq (%rax), %rdi
leaq 0xb3de(%rip), %rsi      # 0x102c1
callq 0x3280
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x4f91
movq $0x0, 0x48(%rsp)
testb $0x4, 0x18(%r15)
jne 0x4fa0
movq %rax, %r14
leaq -0x1(%rbx), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x3270
testl %eax, %eax
jne 0x4f98
leaq 0x7(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x32d0
cmpq $0x1, %rax
jne 0x4f98
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 0x4fa0
movq 0x1414b(%rip), %rax     # 0x190b8
movq (%rax), %rdi
callq 0x3080
jmp 0x4fa0
movq 0x13072(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xb378(%rip), %rsi      # 0x10300
jmp 0x4fbe
callq 0x3407
jmp 0x4fa0
callq 0x33e5
jmp 0x4fa0
movq %r14, %rdi
callq 0x33a7
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
retq
movq 0x1303c(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0xb2b7(%rip), %rsi      # 0x10275
movq %rbx, %rdx
xorl %eax, %eax
addq $0x960, %rsp            # imm = 0x960
popq %rbx
popq %r14
popq %r15
jmp 0x31e0