// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x980, %rsp            # imm = 0x980
movb $0x0, -0x961(%rbp)
movq $0x0, -0x970(%rbp)
movq 0x1baa4(%rip), %rax     # 0x1f2d8
movq 0x8(%rax), %rdi
callq 0x5890
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0x3a53
movq -0x8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jne 0x388e
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x388e
movq 0x1a78b(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq 0x1ba61(%rip), %rax     # 0x1f2d8
movq 0x8(%rax), %rdx
leaq 0x14a4f(%rip), %rsi     # 0x182d1
movb $0x0, %al
callq 0x31c0
jmp 0x3a76
movq 0x1ba43(%rip), %rax     # 0x1f2d8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x3240
cmpl $0x0, %eax
jne 0x38cb
movq 0x1a74d(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq 0x1ba23(%rip), %rax     # 0x1f2d8
movq (%rax), %rdx
leaq 0x14a42(%rip), %rsi     # 0x18301
movb $0x0, %al
callq 0x31c0
jmp 0x3a76
leaq -0x960(%rbp), %rdi
xorl %esi, %esi
movl $0x958, %edx            # imm = 0x958
callq 0x3170
movq -0x8(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x38f7
movq -0x8(%rbp), %rax
callq *0x38(%rax)
movq %rax, -0x970(%rbp)
movq 0x1b9da(%rip), %rax     # 0x1f2d8
movq (%rax), %rdi
leaq 0x14a15(%rip), %rsi     # 0x1831d
callq 0x3260
movq %rax, -0x928(%rbp)
cmpq $0x0, %rax
je 0x3a2f
movq -0x970(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x978(%rbp)
movq $0x0, -0x920(%rbp)
movq -0x8(%rbp), %rax
movzwl 0x18(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x3950
jmp 0x3a76
movq -0x928(%rbp), %rdi
movq -0x978(%rbp), %rsi
addq -0x920(%rbp), %rsi
xorl %edx, %edx
callq 0x3250
cmpl $0x0, %eax
jne 0x39f0
movq -0x928(%rbp), %rcx
leaq -0x961(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x32b0
cmpq $0x1, %rax
jne 0x39f0
movq -0x8(%rbp), %rax
movq %rax, -0x940(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x938(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x970(%rbp), %rsi
leaq -0x960(%rbp), %rdi
callq *%rax
movl %eax, -0x968(%rbp)
movq -0x928(%rbp), %rdi
callq 0x3110
cmpl $0x0, -0x968(%rbp)
jne 0x39ee
movq 0x1b8f2(%rip), %rax     # 0x1f2d8
movq (%rax), %rdi
callq 0x3070
jmp 0x3a2d
movq 0x1a601(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq 0x1b8d7(%rip), %rax     # 0x1f2d8
movq (%rax), %rdx
leaq 0x14915(%rip), %rsi     # 0x18320
movb $0x0, %al
callq 0x31c0
movq -0x928(%rbp), %rdi
callq 0x3110
movq 0x1b8b3(%rip), %rax     # 0x1f2d8
movq (%rax), %rdi
callq 0x3070
jmp 0x3a51
movq 0x1a5c2(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq 0x1b898(%rip), %rax     # 0x1f2d8
movq (%rax), %rdx
leaq 0x148f4(%rip), %rsi     # 0x1833e
movb $0x0, %al
callq 0x31c0
jmp 0x3a76
movq 0x1a59e(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq 0x1b874(%rip), %rax     # 0x1f2d8
movq 0x8(%rax), %rdx
leaq 0x148ed(%rip), %rsi     # 0x1835c
movb $0x0, %al
callq 0x31c0
addq $0x980, %rsp            # imm = 0x980
popq %rbp
retq
nop