// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movw $0x0, -0x44(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xdebf
movq -0x28(%rbp), %rax
addq $0x1ff, %rax            # imm = 0x1FF
movl $0x200, %ecx            # imm = 0x200
cqto
idivq %rcx
movw %ax, -0x44(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x42(%rbp), %rsi
xorl %edx, %edx
callq 0xb930
cmpl $0x0, %eax
jne 0xdefc
movq 0x1011e(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xc014(%rip), %rsi      # 0x19efc
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0xe14f
movl $0x38, %edi
callq 0x3200
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xe0f2
movq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x3170
movq -0x10(%rbp), %rdi
movb -0x11(%rbp), %al
movq -0x30(%rbp), %rcx
leaq -0x42(%rbp), %rdx
movzbl %al, %esi
callq 0xd550
cmpl $0x0, %eax
jne 0xe082
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3200
movq -0x30(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
je 0xe00f
movq -0x10(%rbp), %rdi
movb -0x11(%rbp), %al
movq -0x30(%rbp), %rcx
leaq -0x42(%rbp), %rdx
movzbl %al, %esi
movzwl -0x44(%rbp), %r8d
callq 0xc830
cmpl $0x0, %eax
jne 0xe002
movq 0x1006d(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbfb4(%rip), %rsi      # 0x19f4d
movb $0x0, %al
callq 0x31c0
leaq 0x11241(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xdfdf
leaq 0x11234(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x10002(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xdfdf
leaq 0x1121e(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbf75(%rip), %rsi      # 0x19f4d
movb $0x0, %al
callq 0x31c0
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3040
movq -0x30(%rbp), %rdi
callq 0x3040
movq $0x0, -0x8(%rbp)
jmp 0xe14f
movq -0x30(%rbp), %rax
movl $0x1, 0x10(%rax)
jmp 0xe080
movq 0xffe2(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbf45(%rip), %rsi      # 0x19f69
movb $0x0, %al
callq 0x31c0
leaq 0x111b6(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xe06a
leaq 0x111a9(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0xff77(%rip), %rcx      # 0x1dfc0
cmpq (%rcx), %rax
je 0xe06a
leaq 0x11193(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbf06(%rip), %rsi      # 0x19f69
movb $0x0, %al
callq 0x31c0
movq -0x30(%rbp), %rdi
callq 0x3040
movq $0x0, -0x8(%rbp)
jmp 0xe14f
jmp 0xe0f0
movq 0xff6f(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbef6(%rip), %rsi      # 0x19f8d
movb $0x0, %al
callq 0x31c0
leaq 0x11143(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xe0dd
leaq 0x11136(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0xff04(%rip), %rcx      # 0x1dfc0
cmpq (%rcx), %rax
je 0xe0dd
leaq 0x11120(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xbeb7(%rip), %rsi      # 0x19f8d
movb $0x0, %al
callq 0x31c0
movq -0x30(%rbp), %rdi
callq 0x3040
movq $0x0, -0x8(%rbp)
jmp 0xe14f
jmp 0xe147
movq 0xfeff(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0xbea4(%rip), %rsi      # 0x19fa7
movb $0x0, %al
callq 0x31c0
leaq 0x110d7(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xe145
leaq 0x110ca(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0xfe98(%rip), %rcx      # 0x1dfc0
cmpq (%rcx), %rax
je 0xe145
leaq 0x110b4(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
leaq 0xbe69(%rip), %rsi      # 0x19fa7
movb $0x0, %al
callq 0x31c0
jmp 0xe147
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)