// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/dosmt.c
// Function: dosmtCloseFile
static void dosmtCloseFile(
  void *filep
)
{
  struct dosmtOpenFile *file = filep;
  struct mountedFS *mount = file->mount;
  struct DOSMTdata *data = &mount->dosmtdata;
  uint32_t status;

  if (file->mode == M_RD) {
    if (file->tm == 0) {
      /*
       * Tape mark not seen, skip to end of current file.
       */
      do {
        if ((status = tapeReadRecordLength(mount->container)) == ST_FAIL) {
          fprintf(stderr,
                  "Error positioning \"%s\", rewinding\n", mount->name);
          tapeRewind(mount->container);
          status = ST_TM;
        }
      } while ((status != ST_EOM) && (status != ST_TM));

      if (status == ST_EOM)
        tapeSkipRecordR(mount->container);
    }
  } else {
    if (file->nextb != 0) {
      /*
       * The are some pending output byte(s), flush a final record to the tape.
       */
      if (tapeWriteRecord(mount->container, file->buf, DOSMTRCLNT) == 0)
        file->error = 1;
    }
    if (tapeWriteTM(mount->container) == 0)
      file->error = 1;

    data->eot = tapeGetPosition(mount->container);

    if (tapeWriteEOM(mount->container, 1) == 0)
      file->error = 1;

    if (file->error != 0) {
      ERROR("Panic: Error writing on \"%s\"\n", mount->name);
      exit(3);
    }
  }

  free(file);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x11c52
movq -0x10(%rbp), %rax
movzbl 0x212(%rax), %eax
cmpl $0x0, %eax
jne 0x11c4d
jmp 0x11bcf
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6290
movl %eax, -0x24(%rbp)
cmpl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
jne 0x11c1a
movq 0xc40b(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x8, %rdx
leaq 0x8a9a(%rip), %rsi      # 0x1a699
movb $0x0, %al
callq 0x31c0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x68d0
movl $0x0, -0x24(%rbp)
jmp 0x11c1c
xorl %eax, %eax
cmpl $-0x1, -0x24(%rbp)
movb %al, -0x25(%rbp)
je 0x11c31
cmpl $0x0, -0x24(%rbp)
setne %al
movb %al, -0x25(%rbp)
movb -0x25(%rbp), %al
testb $0x1, %al
jne 0x11bcf
cmpl $-0x1, -0x24(%rbp)
jne 0x11c4b
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6350
jmp 0x11c4d
jmp 0x11d67
movq -0x10(%rbp), %rax
movzwl 0x210(%rax), %eax
cmpl $0x0, %eax
je 0x11c8e
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x10, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x65e0
cmpl $0x0, %eax
jne 0x11c8c
movq -0x10(%rbp), %rax
movb $0x1, 0x213(%rax)
jmp 0x11c8e
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6720
cmpl $0x0, %eax
jne 0x11cab
movq -0x10(%rbp), %rax
movb $0x1, 0x213(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6210
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x200(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movl $0x1, %esi
callq 0x66a0
cmpl $0x0, %eax
jne 0x11ce8
movq -0x10(%rbp), %rax
movb $0x1, 0x213(%rax)
movq -0x10(%rbp), %rax
movzbl 0x213(%rax), %eax
cmpl $0x0, %eax
je 0x11d65
movq 0xc2f9(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x8, %rdx
leaq 0x89ab(%rip), %rsi      # 0x1a6bc
movb $0x0, %al
callq 0x31c0
leaq 0xd4c9(%rip), %rax      # 0x1f1e8
cmpq $0x0, (%rax)
je 0x11d5b
leaq 0xd4bc(%rip), %rax      # 0x1f1e8
movq (%rax), %rax
movq 0xc28a(%rip), %rcx      # 0x1dfc0
cmpq (%rcx), %rax
je 0x11d5b
leaq 0xd4a6(%rip), %rax      # 0x1f1e8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
addq $0x8, %rdx
leaq 0x8968(%rip), %rsi      # 0x1a6bc
movb $0x0, %al
callq 0x31c0
movl $0x3, %edi
callq 0x32a0
jmp 0x11d67
movq -0x10(%rbp), %rdi
callq 0x3040
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)