// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/core/mapspec.c
// Function: gt_mapspec_read
int  gt_mapspec_read(GtMapspecSetupFunc setup, void *data,
                     const char *filename, GtUword expectedsize,
                     void **mapped, GtError *err)
{
  void *mapptr;
  uint64_t expectedaccordingtomapspec;
  GtUword byteoffset = 0;
  size_t numofbytes;
  GtMapspec *ms = gt_malloc(sizeof (GtMapspec));
  GtMapspecification *mapspecptr;
  int had_err = 0;
  GtUword totalpadunits = 0;

  gt_error_check(err);
  GT_INITARRAY(&ms->mapspectable, GtMapspecification);
  setup(ms, data, false);

  mapptr = gt_fa_mmap_read(filename, &numofbytes, err);
  if (mapptr == NULL)
  {
    had_err = -1;
  }
  *mapped = mapptr;
  if (!had_err)
  {
    if (assigncorrecttype(ms->mapspectable.spaceGtMapspecification,
                          mapptr,0,err) != 0)
    {
      had_err = -1;
    }
  }
  if (!had_err)
  {
    expectedaccordingtomapspec =
                               detexpectedaccordingtomapspec(&ms->mapspectable);
    if (expectedaccordingtomapspec != (uint64_t) numofbytes)
    {
      gt_error_set(err, GT_WU " bytes read from %s, but " Formatuint64_t
                   " expected",
                   (GtUword) numofbytes,
                   filename,
                   PRINTuint64_tcast(expectedaccordingtomapspec));
      had_err = -1;
    }
  }
  if (!had_err)
  {
    mapspecptr = ms->mapspectable.spaceGtMapspecification;
    gt_assert(mapspecptr != NULL);
    byteoffset = CALLCASTFUNC(uint64_t,unsigned_long,
                              (uint64_t) (mapspecptr->sizeofunit *
                                          mapspecptr->numofunits));
    if (byteoffset % (GtUword) GT_WORDSIZE_INBYTES > 0)
    {
      size_t padunits
        = GT_WORDSIZE_INBYTES - (byteoffset % GT_WORDSIZE_INBYTES);
      byteoffset += (GtUword) padunits;
      totalpadunits += (GtUword) padunits;
    }
    for (mapspecptr++;
         mapspecptr < ms->mapspectable.spaceGtMapspecification +
                      ms->mapspectable.nextfreeGtMapspecification; mapspecptr++)
    {
      if (assigncorrecttype(mapspecptr,mapptr,byteoffset,err) != 0)
      {
        had_err = -1;
        break;
      }
      byteoffset = CALLCASTFUNC(uint64_t,unsigned_long,
                                (uint64_t) (byteoffset +
                                            mapspecptr->sizeofunit *
                                            mapspecptr->numofunits));
      if (byteoffset % (GtUword) GT_WORDSIZE_INBYTES > 0)
      {
        size_t padunits
          = GT_WORDSIZE_INBYTES - (byteoffset % GT_WORDSIZE_INBYTES);
        byteoffset += (GtUword) padunits;
        totalpadunits += (GtUword) padunits;
      }
    }
  }
  if (!had_err)
  {
    if (expectedsize + totalpadunits != byteoffset)
    {
      gt_error_set(err,"mapping: expected file size is "GT_WU" bytes, "
                       "but file has "GT_WU" bytes",
                       expectedsize,byteoffset);
      had_err = -1;
    }
  }
  GT_FREEARRAY(&ms->mapspectable,GtMapspecification);
  gt_free(ms);
  return had_err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r14
movq %r8, %r13
movq %rcx, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %rbp
movq %rdi, %r12
leaq 0x32dc7(%rip), %rsi     # 0x109358
movl $0x18, %edi
movl $0x106, %edx            # imm = 0x106
callq 0x35862
movq %rax, %rbx
testq %r14, %r14
je 0xd65b8
movq %r14, %rdi
callq 0x34fea
testb %al, %al
jne 0xd6781
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq *%r12
leaq 0x32d80(%rip), %rdx     # 0x109358
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movl $0x10f, %ecx            # imm = 0x10F
movq %r14, %r8
callq 0x74b73
movq %rax, (%r13)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0xd6734
movq %rax, %r12
movq (%rbx), %rdi
movq %rax, %rsi
xorl %edx, %edx
movq %r14, %rcx
callq 0xd64de
testl %eax, %eax
jne 0xd6734
movq (%rbx), %r13
movq 0x10(%rbx), %rax
testq %rax, %rax
jle 0xd665b
leaq (%rax,%rax,4), %rcx
leaq (,%rcx,8), %rcx
addq %r13, %rcx
xorl %r8d, %r8d
movq %r13, %rdx
movq 0x20(%rdx), %rsi
imulq 0x18(%rdx), %rsi
addq %rsi, %r8
addq $0x7, %r8
andq $-0x8, %r8
addq $0x28, %rdx
cmpq %rcx, %rdx
jb 0xd663c
jmp 0xd665e
xorl %r8d, %r8d
movq 0x10(%rsp), %rdx
cmpq %rdx, %r8
jne 0xd671a
testq %r13, %r13
je 0xd6786
movq 0x20(%r13), %r15
imulq 0x18(%r13), %r15
movl %r15d, %ecx
andl $0x7, %ecx
movl $0x8, %ebp
subq %rcx, %rbp
testq %rcx, %rcx
cmoveq %rcx, %rbp
addq %rbp, %r15
cmpq $0x2, %rax
jl 0xd66f4
addq $0x28, %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0xd64de
testl %eax, %eax
jne 0xd672e
movq 0x20(%r13), %rax
imulq 0x18(%r13), %rax
addq %r15, %rax
movl %eax, %ecx
andl $0x7, %ecx
movl $0x8, %r15d
subq %rcx, %r15
testq %rcx, %rcx
cmoveq %rcx, %r15
addq %r15, %rbp
addq %rax, %r15
addq $0x28, %r13
movq 0x10(%rbx), %rax
leaq (%rax,%rax,4), %rax
shlq $0x3, %rax
addq (%rbx), %rax
cmpq %rax, %r13
jb 0xd66a0
movq 0x8(%rsp), %rdx
addq %rdx, %rbp
xorl %r13d, %r13d
cmpq %r15, %rbp
je 0xd6734
leaq 0x32d06(%rip), %rsi     # 0x109411
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x34f1f
jmp 0xd672e
leaq 0x32cc7(%rip), %rsi     # 0x1093e8
movq %r14, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x34f1f
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xd675b
leaq 0x32c15(%rip), %rsi     # 0x109358
movl $0x159, %edx            # imm = 0x159
callq 0x35c27
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
leaq 0x32bf6(%rip), %rsi     # 0x109358
movq %rbx, %rdi
movl $0x15a, %edx            # imm = 0x15A
callq 0x35c27
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31744
callq 0x3177d