// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/fsio/rt11.c
// Function: rt11OpenFileW
void *rt11OpenFileW(
  struct mountedFS *mount,
  uint8_t unit,
  char *fname,
  off_t size
)
{
  struct rt11OpenFile *file;
  struct rt11FileSpec spec;
  uint16_t blocks = 0;

  if (size != 0)
    blocks = (size + (RT11_BLOCKSIZE - 1)) / RT11_BLOCKSIZE;

  if (rt11ParseFilespec(fname, &spec, RT11_M_NONE) == 0) {
    fprintf(stderr, "Failed to parse filename \"%s\"\n", fname);
    return NULL;
  }

  if ((file = malloc(sizeof(struct rt11OpenFile))) != NULL) {
    memset(file, 0, sizeof(struct rt11OpenFile));

    if (rt11LookupFile(mount, unit, &spec, file) == 0) {
      /*
       * Allocate local buffer space for the file.
       */
      if ((file->buffer = malloc(mount->blocksz)) != NULL) {
        if (rt11CreateFile(mount, unit, &spec, file, blocks) == 0) {
          ERROR("Failed to create file \"%s\"\n", fname);
          free(file->buffer);
          free(file);
          return NULL;
        } else file->mode = M_WR;
      } else {
        ERROR("Buffer allocation failure for \"%s\"\n", fname);
        free(file);
        return NULL;
      }
    } else {
      ERROR("File \"%s\" already exists\n", fname);
      free(file);
      return NULL;
    }
  } else ERROR("Memory allocation failure\n");
  return file;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
testq %rcx, %rcx
je 0x97bd
addq $0x1ff, %rcx            # imm = 0x1FF
movl $0x200, %esi            # imm = 0x200
movq %rcx, %rax
cqto
idivq %rsi
movq %rax, %r12
jmp 0x97c0
xorl %r12d, %r12d
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x82f4
testl %eax, %eax
je 0x9857
pushq $0x1
popq %rdi
pushq $0x38
popq %rsi
callq 0x31c0
testq %rax, %rax
je 0x9876
movq %rax, %rbx
movzbl %bpl, %ebp
leaq 0xe(%rsp), %rdx
movq %r15, %rdi
movl %ebp, %esi
movq %rax, %rcx
callq 0x9391
testl %eax, %eax
jne 0x98c6
movq 0x28(%r15), %rdi
callq 0x3220
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x990d
movzwl %r12w, %r8d
leaq 0xe(%rsp), %rdx
movq %r15, %rdi
movl %ebp, %esi
movq %rbx, %rcx
callq 0x8bd4
testl %eax, %eax
je 0x9956
movl $0x1, 0x10(%rbx)
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0xd79a(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x756f(%rip), %rsi      # 0x10dd7
xorl %ebx, %ebx
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
jmp 0x9847
movq 0xd77b(%rip), %rax      # 0x16ff8
movq (%rax), %rcx
leaq 0x75fb(%rip), %rdi      # 0x10e82
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
leaq 0xe72f(%rip), %rax      # 0x17fc8
movq (%rax), %rcx
xorl %ebx, %ebx
testq %rcx, %rcx
je 0x9847
movq 0xd716(%rip), %rax      # 0x16fc0
cmpq (%rax), %rcx
je 0x9847
leaq 0x75cc(%rip), %rdi      # 0x10e82
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
jmp 0x99ae
movq 0xd72b(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x7591(%rip), %rsi      # 0x10e68
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
leaq 0xe6e0(%rip), %rax      # 0x17fc8
movq (%rax), %rdi
testq %rdi, %rdi
je 0x99a6
movq 0xd6c5(%rip), %rax      # 0x16fc0
cmpq (%rax), %rdi
je 0x99a6
leaq 0x755d(%rip), %rsi      # 0x10e68
jmp 0x994a
movq 0xd6e4(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x7526(%rip), %rsi      # 0x10e44
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
leaq 0xe699(%rip), %rax      # 0x17fc8
movq (%rax), %rdi
testq %rdi, %rdi
je 0x99a6
movq 0xd682(%rip), %rax      # 0x16fc0
cmpq (%rax), %rdi
je 0x99a6
leaq 0x74fa(%rip), %rsi      # 0x10e44
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
jmp 0x99a6
movq 0xd69b(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x74c1(%rip), %rsi      # 0x10e28
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
leaq 0xe650(%rip), %rax      # 0x17fc8
movq (%rax), %rdi
testq %rdi, %rdi
je 0x999d
movq 0xd639(%rip), %rax      # 0x16fc0
cmpq (%rax), %rdi
je 0x999d
leaq 0x7495(%rip), %rsi      # 0x10e28
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
movq 0x28(%rbx), %rdi
callq 0x3050
movq %rbx, %rdi
callq 0x3050
xorl %ebx, %ebx
jmp 0x9847