// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/fsio.c
// Function: doCopy
static void doCopy(void)
{
  struct mountedFS *mountSrc, *mountDest;
  struct FSdef *fsSrc, *fsDest;
  uint8_t unitSrc, unitDest, presentSrc, presentDest;
  char *fnameSrc, *fnameDest;
  void *fileSrc, *fileDest;
  char *endptr;

  mountSrc = findMount("copy", words[0], &unitSrc, &presentSrc, &fnameSrc);
  mountDest = findMount("copy", words[1], &unitDest, &presentDest, &fnameDest);

  if ((mountSrc != NULL) && (mountDest != NULL)) {
    fsSrc = mountSrc->filesys;
    fsDest = mountDest->filesys;

    if (mountSrc == mountDest) {
      if ((fsDest->flags & FS_1OPENFILE) != 0) {
        fprintf(stderr,
                "copy: \"%s\" does not allow simultaneous read/write access\n",
                mountDest->name);
        return;
      }
    }

    if ((mountDest->flags & FS_READONLY) != 0) {
      fprintf(stderr, "copy: \"%s\" is mounted read-only\n", mountDest->name);
      return;
    }
    fsSrc = mountSrc->filesys;
    fsDest = mountDest->filesys;

    if ((fileSrc = (*fsSrc->openFileR)(mountSrc, unitSrc, fnameSrc)) != NULL) {
      off_t size = (*fsSrc->fileSize)(fileSrc);
      unsigned long contig;

      if (SWISSET('c')) {
        contig = strtoul(SWGETVAL('c'), &endptr, 10);
        if (*endptr != '\0') {
          fprintf(stderr, "copy: Invalid character in '-c' argument\n");
          (*fsSrc->closeFile)(fileSrc);
          return;
        }
        if (contig != 0)
          size = MAX(size, (long)(contig * mountDest->blocksz));
      }

      if ((fileDest = (*fsDest->openFileW)(mountDest, unitDest, fnameDest, size)) != NULL) {
        char buf[BFRSIZ];
        size_t len;

        while ((len = (*fsSrc->readFile)(fileSrc, buf, BFRSIZ)) != 0) {
          if ((*fsDest->writeFile)(fileDest, buf, len) == 0) {
            fprintf(stderr, "copy: Error writing \"%s\"\n", fnameDest);
            break;
          }
        }
        (*fsDest->closeFile)(fileDest);
        (*fsSrc->closeFile)(fileSrc);
      } else {
        fprintf(stderr,
                "copy: failed to open \"%s\" for write\n", fnameDest);
        (*fsSrc->closeFile)(fileSrc);
      }
    } else fprintf(stderr,
                   "copy: failed to open \"%s\" for read\n", fnameSrc);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq 0x1b1a6(%rip), %rax     # 0x1f2d8
movq (%rax), %rsi
leaq 0x13f7d(%rip), %rdi     # 0x180b9
leaq -0x21(%rbp), %rdx
leaq -0x23(%rbp), %rcx
leaq -0x30(%rbp), %r8
callq 0x58f0
movq %rax, -0x8(%rbp)
movq 0x1b180(%rip), %rax     # 0x1f2d8
movq 0x8(%rax), %rsi
leaq 0x13f56(%rip), %rdi     # 0x180b9
leaq -0x22(%rbp), %rdx
leaq -0x24(%rbp), %rcx
leaq -0x38(%rbp), %r8
callq 0x58f0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x441e
cmpq $0x0, -0x10(%rbp)
je 0x441e
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
cmpq -0x10(%rbp), %rax
jne 0x41e7
movq -0x20(%rbp), %rax
movzwl 0x18(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x41e5
movq 0x19e31(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
leaq 0x1437a(%rip), %rsi     # 0x18553
movb $0x0, %al
callq 0x31c0
jmp 0x441e
jmp 0x41e7
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x421c
movq 0x19dfa(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x8, %rdx
leaq 0x1437d(%rip), %rsi     # 0x1858d
movb $0x0, %al
callq 0x31c0
jmp 0x441e
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x8(%rbp), %rdi
movb -0x21(%rbp), %cl
movq -0x30(%rbp), %rdx
movzbl %cl, %esi
callq *%rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x4400
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
movq %rax, -0x58(%rbp)
movl 0x1af86(%rip), %eax     # 0x1f1f8
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4319
movq 0x1af8b(%rip), %rdi     # 0x1f210
leaq -0x50(%rbp), %rsi
movl $0xa, %edx
callq 0x3280
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x42ce
movq 0x19d4e(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
leaq 0x142fa(%rip), %rsi     # 0x185ae
movb $0x0, %al
callq 0x31c0
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
jmp 0x441e
cmpq $0x0, -0x60(%rbp)
je 0x4317
movq -0x58(%rbp), %rax
movq -0x60(%rbp), %rcx
movq -0x10(%rbp), %rdx
imulq 0x28(%rdx), %rcx
cmpq %rcx, %rax
jle 0x42f8
movq -0x58(%rbp), %rax
movq %rax, -0x270(%rbp)
jmp 0x430c
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
imulq 0x28(%rcx), %rax
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x4319
movq -0x20(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rdi
movb -0x22(%rbp), %sil
movq -0x38(%rbp), %rdx
movq -0x58(%rbp), %rcx
movzbl %sil, %esi
callq *%rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x43d4
jmp 0x4347
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x40(%rbp), %rdi
leaq -0x260(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq *%rax
movq %rax, -0x268(%rbp)
cmpq $0x0, %rax
je 0x43b6
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x48(%rbp), %rdi
leaq -0x260(%rbp), %rsi
movq -0x268(%rbp), %rdx
callq *%rax
cmpq $0x0, %rax
jne 0x43b4
movq 0x19c5b(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x1422d(%rip), %rsi     # 0x185d8
movb $0x0, %al
callq 0x31c0
jmp 0x43b6
jmp 0x4347
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x48(%rbp), %rdi
callq *%rax
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
jmp 0x43fe
movq 0x19c1d(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x38(%rbp), %rdx
leaq 0x14209(%rip), %rsi     # 0x185f2
movb $0x0, %al
callq 0x31c0
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
jmp 0x441c
movq 0x19bf1(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x30(%rbp), %rdx
leaq 0x14202(%rip), %rsi     # 0x18617
movb $0x0, %al
callq 0x31c0
jmp 0x441e
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw (%rax,%rax)