// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %r9, %rbp
movq %r8, %r14
movq %rcx, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %r12
leaq 0x336c6(%rip), %rsi     # 0x109530
movl $0x18, %edi
movl $0x106, %edx            # imm = 0x106
callq 0x35ee2
movq %rax, %rbx
testq %rbp, %rbp
je 0xd5e91
movq %rbp, %rdi
callq 0x3566a
testb %al, %al
jne 0xd6095
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq *%r12
leaq 0x3367c(%rip), %rdx     # 0x109530
leaq 0x20(%rsp), %rsi
movq 0x10(%rsp), %rdi
movl $0x10f, %ecx            # imm = 0x10F
movq %rbp, %r8
callq 0x7460e
movq %rbp, %rcx
movq %rax, (%r14)
testq %rax, %rax
movq %rbp, 0x8(%rsp)
je 0xd600f
movq %rax, %rbp
movq (%rbx), %rdi
xorl %r15d, %r15d
movq %rax, %rsi
xorl %edx, %edx
callq 0xd5db5
movl $0x0, %r12d
movl $0x0, %r14d
testl %eax, %eax
jne 0xd6015
movq (%rbx), %r13
movq 0x10(%rbx), %rax
testq %rax, %rax
jle 0xd5f46
leaq (%rax,%rax,4), %rax
leaq (,%rax,8), %rax
addq %r13, %rax
xorl %r8d, %r8d
movq %r13, %rcx
movq 0x20(%rcx), %rdx
imulq 0x18(%rcx), %rdx
addq %rdx, %r8
addq $0x7, %r8
andq $-0x8, %r8
addq $0x28, %rcx
cmpq %rax, %rcx
jb 0xd5f27
jmp 0xd5f49
xorl %r8d, %r8d
movq 0x20(%rsp), %rdx
cmpq %rdx, %r8
jne 0xd5ff4
testq %r13, %r13
je 0xd609a
movq 0x20(%r13), %r14
imulq 0x18(%r13), %r14
movl %r14d, %eax
andl $0x7, %eax
movl $0x8, %r12d
subq %rax, %r12
testq %rax, %rax
cmoveq %rax, %r12
addq %r12, %r14
addq $0x28, %r13
movq 0x10(%rbx), %rax
leaq (%rax,%rax,4), %rax
shlq $0x3, %rax
addq (%rbx), %rax
movb $0x1, %r15b
cmpq %rax, %r13
jae 0xd6015
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
callq 0xd5db5
testl %eax, %eax
sete %r15b
jne 0xd6015
movq 0x20(%r13), %rax
imulq 0x18(%r13), %rax
addq %r14, %rax
movl %eax, %ecx
andl $0x7, %ecx
movl $0x8, %r14d
subq %rcx, %r14
testq %rcx, %rcx
cmoveq %rcx, %r14
addq %r14, %r12
addq %rax, %r14
addq $0x28, %r13
movq 0x10(%rbx), %rax
leaq (%rax,%rax,4), %rax
shlq $0x3, %rax
addq (%rbx), %rax
jmp 0xd5f98
leaq 0x335c5(%rip), %rsi     # 0x1095c0
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x3559f
xorl %r12d, %r12d
xorl %r14d, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %r15b, %r15b
je 0xd6049
movq 0x18(%rsp), %rdx
addq %rdx, %r12
xorl %ebp, %ebp
cmpq %r14, %r12
je 0xd6049
leaq 0x335b4(%rip), %rsi     # 0x1095e9
movq 0x8(%rsp), %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x3559f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%rbx), %rdi
testq %rdi, %rdi
je 0xd6070
leaq 0x334d8(%rip), %rsi     # 0x109530
movl $0x159, %edx            # imm = 0x159
callq 0x362a0
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
leaq 0x334b9(%rip), %rsi     # 0x109530
movq %rbx, %rdi
movl $0x15a, %edx            # imm = 0x15A
callq 0x362a0
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31d41
callq 0x31d7a