// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/dos11.c
// Function: dos11OpenFileW
static void *dos11OpenFileW(
  struct mountedFS *mount,
  uint8_t UNUSED(unit),
  char *fname,
  off_t size
)
{
  struct DOS11data *data = &mount->dos11data;
  struct dos11OpenFile *file;
  struct dos11FileSpec spec;
  unsigned long contig = (size + mount->blocksz - 1) / mount->blocksz;
  uint8_t user = data->user;
  uint8_t group = data->group;

  if (SWISSET('c') && (contig == 0)) {
      fprintf(stderr,"DOS-11 contiguous files must be at least 1 block\n");
      return NULL;
  }

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

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

    if (dos11LookupFile(mount, &spec, file) == 0) {
      /*
       * Allocate local bufferspace for the file.
       */
      if ((file->buffer = malloc(mount->blocksz)) != NULL) {
        if (dos11CreateFile(mount, &spec, file, contig) == 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 fprintf(stderr, "Memory allocation failure\n");
  return file;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %sil, %al
movq %rdi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
addq 0x28(%rcx), %rax
subq $0x1, %rax
movq -0x10(%rbp), %rcx
xorl %edx, %edx
divq 0x28(%rcx)
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
movb 0x90d(%rax), %al
movb %al, -0x51(%rbp)
movq -0x30(%rbp), %rax
movb 0x90c(%rax), %al
movb %al, -0x52(%rbp)
leaq 0x147a3(%rip), %rax     # 0x1f1f8
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xaa8b
cmpq $0x0, -0x50(%rbp)
jne 0xaa8b
movq 0x1358b(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
leaq 0xf4a4(%rip), %rsi      # 0x19f1b
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0xacdc
movq -0x20(%rbp), %rdi
movb -0x51(%rbp), %al
leaq -0x42(%rbp), %rsi
xorl %r8d, %r8d
movzbl %al, %edx
movzbl -0x52(%rbp), %ecx
callq 0x8300
cmpl $0x0, %eax
jne 0xaad3
movq 0x13547(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf43d(%rip), %rsi      # 0x19efc
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0xacdc
movl $0x38, %edi
callq 0x3200
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0xacbc
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x3170
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq -0x42(%rbp), %rsi
callq 0x7a70
cmpl $0x0, %eax
jne 0xac4c
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3200
movq -0x38(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
je 0xabd9
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rcx
leaq -0x42(%rbp), %rsi
callq 0x6c70
cmpl $0x0, %eax
jne 0xabcc
movq 0x134a3(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf3ea(%rip), %rsi      # 0x19f4d
movb $0x0, %al
callq 0x31c0
leaq 0x14677(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xaba9
leaq 0x1466a(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x13438(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xaba9
leaq 0x14654(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf3ab(%rip), %rsi      # 0x19f4d
movb $0x0, %al
callq 0x31c0
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3040
movq -0x38(%rbp), %rdi
callq 0x3040
movq $0x0, -0x8(%rbp)
jmp 0xacdc
movq -0x38(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0xac4a
movq 0x13418(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf37b(%rip), %rsi      # 0x19f69
movb $0x0, %al
callq 0x31c0
leaq 0x145ec(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xac34
leaq 0x145df(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x133ad(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xac34
leaq 0x145c9(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf33c(%rip), %rsi      # 0x19f69
movb $0x0, %al
callq 0x31c0
movq -0x38(%rbp), %rdi
callq 0x3040
movq $0x0, -0x8(%rbp)
jmp 0xacdc
jmp 0xacba
movq 0x133a5(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf32c(%rip), %rsi      # 0x19f8d
movb $0x0, %al
callq 0x31c0
leaq 0x14579(%rip), %rax     # 0x1f1e8
cmpq $0x0, (%rax)
je 0xaca7
leaq 0x1456c(%rip), %rax     # 0x1f1e8
movq (%rax), %rax
movq 0x1333a(%rip), %rcx     # 0x1dfc0
cmpq (%rcx), %rax
je 0xaca7
leaq 0x14556(%rip), %rax     # 0x1f1e8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0xf2ed(%rip), %rsi      # 0x19f8d
movb $0x0, %al
callq 0x31c0
movq -0x38(%rbp), %rdi
callq 0x3040
movq $0x0, -0x8(%rbp)
jmp 0xacdc
jmp 0xacd4
movq 0x13335(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
leaq 0xf2da(%rip), %rsi      # 0x19fa7
movb $0x0, %al
callq 0x31c0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)