// File: /workspace/github_c_makefile_star2_O3/thegenemyers[P]DASCRUBBER/DB.c
// Function: Open_Track
DAZZ_TRACK *Open_Track(DAZZ_DB *db, char *track)
{ FILE       *afile, *dfile;
  int         tracklen, size;
  int         nreads, ispart;
  int         treads, ureads;
  int64       dmax;
  void       *anno;
  int        *alen;
  void       *data;
  char       *name;
  DAZZ_TRACK *record;

  if (track[0] == '.')
    { EPRINTF(EPLACE,"%s: Track name, '%s', cannot begin with a .\n",Prog_Name,track);
      EXIT(NULL);
    }

  for (record = db->tracks; record != NULL; record = record->next)
    if (strcmp(record->name,track) == 0)
      return (record);

  afile = NULL;
  if (db->part)
    { afile  = fopen(MyCatenate(db->path,MyNumbered_Suffix(".",db->part,"."),track,".anno"),"r");
      ispart = 1;
    }
  if (afile == NULL)
    { afile = fopen(MyCatenate(db->path,".",track,".anno"),"r");
      ispart = 0;
    }
  if (afile == NULL)
    { EPRINTF(EPLACE,"%s: Track '%s' does not exist\n",Prog_Name,track);
      return (NULL);
    }

  dfile  = NULL;
  anno   = NULL;
  alen   = NULL;
  data   = NULL;
  record = NULL;

  if (ispart)
    name = MyCatenate(db->path,MyNumbered_Suffix(".",db->part,"."),track,".data");
  else
    name = MyCatenate(db->path,".",track,".data");
  if (name == NULL)
    goto error;
  dfile = fopen(name,"r");

  if (fread(&tracklen,sizeof(int),1,afile) != 1)
    { EPRINTF(EPLACE,"%s: Track '%s' annotation file is junk\n",Prog_Name,track);
      goto error;
    }
  if (fread(&size,sizeof(int),1,afile) != 1)
    { EPRINTF(EPLACE,"%s: Track '%s' annotation file is junk\n",Prog_Name,track);
      goto error;
    }

  if (size < 0)
    { EPRINTF(EPLACE,"%s: Track '%s' annotation file is junk\n",Prog_Name,track);
      goto error;
    }
  if (size == 0)
    size = 8;

  if (ispart)
    { ureads = ((int *) (db->reads))[-1];
      treads = ((int *) (db->reads))[-2];
    }
  else
    { ureads = db->ureads;
      treads = db->treads;
    }

  if (db->trimmed)
    { if (tracklen != treads && tracklen != ureads)
        { EPRINTF(EPLACE,"%s: Track '%s' not same size as database !\n",Prog_Name,track);
          goto error;
        }
      if ( ! ispart && db->part > 0)
        { if (tracklen == treads)
            fseeko(afile,size*db->tfirst,SEEK_CUR);
          else
            fseeko(afile,size*db->ufirst,SEEK_CUR);
        }
    }
  else
    { if (tracklen != ureads)
        { if (tracklen == treads)
            EPRINTF(EPLACE,"%s: Track '%s' is for a trimmed DB !\n",Prog_Name,track);
          else
            EPRINTF(EPLACE,"%s: Track '%s' not same size as database !\n",Prog_Name,track);
          goto error;
        }
      if ( ! ispart && db->part > 0)
        fseeko(afile,size*db->ufirst,SEEK_CUR);
    }
  if (tracklen == treads)
    nreads = ((int *) (db->reads))[-2];
  else
    nreads = ((int *) (db->reads))[-1];

  anno = (void *) Malloc(size*(nreads+1),"Allocating Track Anno Vector");
  if (anno == NULL)
    goto error;

  if (dfile != NULL)
    { int64 *anno8;
      int   *anno4;
      int64  x, y;
      int    i;

      alen = (int *)  Malloc(sizeof(int)*nreads,"Allocating Track Anno Lengths");
      if (alen == NULL)
        goto error;

      if (fread(anno,size,nreads+1,afile) != (size_t) (nreads+1))
        { EPRINTF(EPLACE,"%s: Track '%s' annotation file is junk\n",Prog_Name,track);
          goto error;
        }

      dmax = 0;
      if (size == 4)
        { anno4 = (int *) anno;
          y = anno4[0];
          for (i = 1; i <= nreads; i++)
            { x = anno4[i];
              y = x-y;
              if (y > dmax)
                dmax = y; 
              alen[i-1] = y;
              y = x;
            }
        }
      else
        { anno8 = (int64 *) anno;
          y = anno8[0];
          for (i = 1; i <= nreads; i++)
            { x = anno8[i];
              y = x-y;
              if (y > dmax)
                dmax = y; 
              alen[i-1] = y;
              y = x;
            }
        }
    }
  else
    { dmax = 0;
      if (fread(anno,size,nreads,afile) != (size_t) nreads)
        { EPRINTF(EPLACE,"%s: Track '%s' annotation file is junk\n",Prog_Name,track);
          goto error;
        }
    }

  fclose(afile);

  record = (DAZZ_TRACK *) Malloc(sizeof(DAZZ_TRACK),"Allocating Track Record");
  if (record == NULL)
    goto error;
  record->name = Strdup(track,"Allocating Track Name");
  if (record->name == NULL)
    goto error;
  if (dfile == NULL)
    record->data = NULL;
  else
    record->data = (void *) dfile;
  record->anno   = anno;
  record->alen   = alen;
  record->size   = size;
  record->nreads = nreads;
  record->loaded = 0;
  record->dmax   = dmax;

  if (db->trimmed && tracklen != treads)
    { if (Late_Track_Trim(db,record,ispart))
        goto error;
    }

  if (db->tracks != NULL && (db->tracks->name == qtrack_name || db->tracks->name == atrack_name))
    { record->next     = db->tracks->next;
      db->tracks->next = record;
    }
  else
    { record->next = db->tracks;
      db->tracks   = record;
    }

  return (record);

error:
  if (record != NULL)
    free(record);
  if (data != NULL)
    free(data);
  if (alen != NULL)
    free(alen);
  if (anno != NULL)
    free(anno);
  if (dfile != NULL)
    fclose(dfile);
  fclose(afile);
  EXIT (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r12
cmpb $0x2e, (%rsi)
je 0x61ae
movq %rdi, %rbx
leaq 0x68(%rdi), %r15
movq %r15, %rbp
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x5a2a
movq 0x8(%rbp), %rdi
movq %r12, %rsi
callq 0x1190
testl %eax, %eax
jne 0x5a0c
jmp 0x6146
movl 0x38(%rbx), %esi
testl %esi, %esi
je 0x5a9f
movq 0x48(%rbx), %r14
leaq 0x5b12(%rip), %rdi      # 0xb54e
movq %rdi, %rdx
callq 0x5939
leaq 0x5e78(%rip), %rcx      # 0xb8c3
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x427d
leaq 0x6351(%rip), %rsi      # 0xbdb1
movq %rax, %rdi
callq 0x1240
testq %rax, %rax
je 0x5a9f
movq %rax, %r13
movq 0x48(%rbx), %r14
movl 0x38(%rbx), %esi
leaq 0x5ad0(%rip), %rdi      # 0xb54e
movq %rdi, %rdx
callq 0x5939
leaq 0x5eae(%rip), %rcx      # 0xb93b
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x427d
xorl %ebp, %ebp
jmp 0x5af1
movq 0x48(%rbx), %rdi
leaq 0x5aa4(%rip), %rsi      # 0xb54e
leaq 0x5e12(%rip), %rcx      # 0xb8c3
movq %r12, %rdx
callq 0x427d
leaq 0x62f1(%rip), %rsi      # 0xbdb1
movq %rax, %rdi
callq 0x1240
testq %rax, %rax
je 0x6058
movq %rax, %r13
movq 0x48(%rbx), %rdi
leaq 0x5a6f(%rip), %rsi      # 0xb54e
leaq 0x5e55(%rip), %rcx      # 0xb93b
movq %r12, %rdx
callq 0x427d
movb $0x1, %bpl
testq %rax, %rax
je 0x619c
leaq 0x62b0(%rip), %rsi      # 0xbdb1
movq %rax, %rdi
callq 0x1240
movq %rax, 0x18(%rsp)
leaq 0x44(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
movq %r13, 0x8(%rsp)
jne 0x5fb8
leaq 0x40(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x603e
movl 0x40(%rsp), %r14d
testl %r14d, %r14d
js 0x604b
movl $0x8, %eax
cmovel %eax, %r14d
testb %bpl, %bpl
movl %ebp, 0x34(%rsp)
je 0x5b7e
leaq 0x4(%rbx), %rcx
movq %rbx, %rax
jmp 0x5b8a
movq 0x60(%rbx), %rcx
leaq -0x4(%rcx), %rax
addq $-0x8, %rcx
movl (%rax), %eax
movl (%rcx), %r13d
cmpl $0x0, 0x34(%rbx)
movl 0x44(%rsp), %ebp
movq %rbx, 0x38(%rsp)
je 0x5bee
cmpl %r13d, %ebp
sete %cl
cmpl %eax, %ebp
sete %al
orb %cl, %al
je 0x6067
cmpb $0x0, 0x34(%rsp)
je 0x5c1f
cmpl $0x0, 0x38(%rbx)
jle 0x5c1f
cmpl %r13d, %ebp
jne 0x5c05
movslq 0x40(%rbx), %rax
movq %r14, %rbx
movslq %r14d, %rsi
imulq %rax, %rsi
movq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x1230
movb $0x1, 0x20(%rsp)
movq $-0x8, %rcx
jmp 0x5c38
cmpl %eax, %ebp
jne 0x6158
cmpb $0x0, 0x34(%rsp)
je 0x5c21
cmpl $0x0, 0x38(%rbx)
movl %eax, %ebp
jle 0x5c21
movslq 0x3c(%rbx), %rax
movslq %r14d, %rsi
imulq %rax, %rsi
movq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x1230
movl %ebp, %eax
movq %r14, %rbx
xorl %ecx, %ecx
cmpl %r13d, %eax
sete 0x20(%rsp)
setne %cl
shll $0x2, %ecx
orq $-0x8, %rcx
movq 0x38(%rsp), %rax
movq 0x60(%rax), %rax
movl (%rax,%rcx), %eax
movl %eax, 0x14(%rsp)
movslq %eax, %r13
leaq 0x1(%r13), %rbp
movl %ebx, %eax
imull %ebp, %eax
movslq %eax, %rdi
leaq 0x5d5d(%rip), %rsi      # 0xb9bb
callq 0x2af5
testq %rax, %rax
je 0x6188
movq %rax, %r14
movq %r15, 0x48(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x5cfa
shlq $0x2, %r13
leaq 0x5d51(%rip), %rsi      # 0xb9d8
movq %r13, %rdi
callq 0x2af5
testq %rax, %rax
je 0x6084
movq %rax, %r15
movq %rbx, %r13
movl %r13d, %esi
movq %r14, %rdi
movq %rbp, %rdx
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq %rbp, %rax
jne 0x6074
cmpl $0x4, %r13d
jne 0x5d33
cmpl $0x0, 0x14(%rsp)
jle 0x5d69
movslq (%r14), %rdx
movl %ebp, %eax
decq %rax
xorl %ecx, %ecx
xorl %ebx, %ebx
movslq 0x4(%r14,%rcx,4), %rsi
movq %rsi, %rdi
subq %rdx, %rdi
cmpq %rbx, %rdi
cmovgq %rdi, %rbx
movl %edi, (%r15,%rcx,4)
incq %rcx
movq %rsi, %rdx
cmpq %rcx, %rax
jne 0x5cd7
jmp 0x5d6b
movq %rbx, 0x28(%rsp)
movl %ebx, %esi
movq %r14, %rdi
movq %r13, %rdx
movq 0x8(%rsp), %rbp
movq %rbp, %rcx
callq 0x10b0
xorl %ebx, %ebx
movl $0x0, %r15d
cmpq %r13, %rax
movq 0x28(%rsp), %r13
je 0x5d70
movq %r12, %rdi
callq 0x195f
jmp 0x6084
cmpl $0x0, 0x14(%rsp)
jle 0x5d69
movq (%r14), %rdx
movl %ebp, %eax
decq %rax
xorl %ecx, %ecx
xorl %ebx, %ebx
movq 0x8(%r14,%rcx,8), %rsi
movq %rsi, %rdi
subq %rdx, %rdi
cmpq %rbx, %rdi
cmovgq %rdi, %rbx
movl %edi, (%r15,%rcx,4)
incq %rcx
movq %rsi, %rdx
cmpq %rcx, %rax
jne 0x5d46
jmp 0x5d6b
xorl %ebx, %ebx
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x10c0
leaq 0x5c77(%rip), %rsi      # 0xb9f6
movl $0x40, %edi
callq 0x2af5
testq %rax, %rax
je 0x61eb
movq %rax, %rbp
leaq 0x5c72(%rip), %rsi      # 0xba0e
movq %r12, %rdi
callq 0x2bb2
movq %rax, 0x8(%rbp)
testq %rax, %rax
je 0x61e3
movq 0x18(%rsp), %rax
movq %rax, 0x28(%rbp)
movq %r14, 0x18(%rbp)
movq %r15, 0x20(%rbp)
movl %r13d, 0x10(%rbp)
movl 0x14(%rsp), %eax
movl %eax, 0x14(%rbp)
movl $0x0, 0x30(%rbp)
movq %rbx, 0x38(%rbp)
movq 0x38(%rsp), %rbx
cmpl $0x0, 0x34(%rbx)
sete %al
orb 0x20(%rsp), %al
jne 0x6104
movq %r13, 0x28(%rsp)
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %r13d
movl %eax, 0x14(%rsp)
testl %eax, %eax
setg %al
testb $0x1, %r13b
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x6104
notl %r13d
andl $0x1, %r13d
movq 0x48(%rbx), %r12
movq %r12, %rdi
movl $0x2f, %esi
callq 0x1250
movq %rax, 0x20(%rsp)
leaq 0x5b81(%rip), %rdx      # 0xb9ba
leaq 0x5710(%rip), %rcx      # 0xb550
movq %r12, %rdi
movq %rdx, %rsi
callq 0x427d
leaq 0x5f5f(%rip), %rsi      # 0xbdb1
movq %rax, %rdi
callq 0x2c15
movq %rax, %rdi
movslq 0x3c(%rbx), %rax
leaq (%rax,%rax,4), %rax
leaq 0x70(,%rax,8), %rsi
movq %rdi, 0x8(%rsp)
xorl %edx, %edx
callq 0x1230
cmpb $0x0, 0x34(%rsp)
jne 0x5e88
movq 0x60(%rbx), %rbx
addq $-0x4, %rbx
movq 0x18(%rsp), %rax
shll $0xb, %r13d
movq 0x20(%rsp), %rcx
addq $0x2, %rcx
movl (%rbx), %ebx
testq %rax, %rax
je 0x5f2c
movq 0x28(%rsp), %rax
cmpl $0x4, %eax
jne 0x5fc5
testl %ebx, %ebx
jle 0x609c
movq %rcx, 0x20(%rsp)
movl %r13d, 0x18(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x28, %esi
movl $0x1, %edx
leaq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x61c5
movl 0x70(%rsp), %eax
movl $0x800, %ecx            # imm = 0x800
andl %ecx, %eax
cmpl 0x18(%rsp), %eax
jb 0x5f1f
movl 0x14(%rsp), %eax
cmpl %eax, 0x54(%rsp)
jl 0x5f1f
movl (%r14,%r12,4), %eax
movslq %r13d, %r13
movl %eax, (%r14,%r13,4)
movl (%r15,%r12,4), %eax
movl %eax, (%r15,%r13,4)
incl %r13d
incq %r12
cmpq %r12, %rbx
jne 0x5ecb
jmp 0x609f
testl %ebx, %ebx
jle 0x6091
movq %rcx, 0x20(%rsp)
movq 0x28(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0x38(%rsp)
addl %eax, %eax
movl %eax, 0x18(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
movl $0x28, %esi
movl $0x1, %edx
leaq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x61b6
movl 0x70(%rsp), %eax
movl $0x800, %ecx            # imm = 0x800
andl %ecx, %eax
cmpl %r13d, %eax
jb 0x5faa
movl 0x14(%rsp), %eax
cmpl %eax, 0x54(%rsp)
jl 0x5faa
movslq %r15d, %r15
leaq (%r14,%r15), %rdi
movslq %r12d, %rsi
addq %r14, %rsi
movq 0x38(%rsp), %rdx
callq 0x1220
addl 0x28(%rsp), %r15d
addl 0x18(%rsp), %r12d
decl %ebx
jne 0x5f51
jmp 0x6094
movq %r12, %rdi
callq 0x18d7
jmp 0x6188
testl %ebx, %ebx
jle 0x60c2
movq %rcx, 0x20(%rsp)
movl %r13d, 0x18(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x28, %esi
movl $0x1, %edx
leaq 0x50(%rsp), %rdi
movq 0x8(%rsp), %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x61d4
movl 0x70(%rsp), %eax
movl $0x800, %ecx            # imm = 0x800
andl %ecx, %eax
cmpl 0x18(%rsp), %eax
jb 0x6031
movl 0x14(%rsp), %eax
cmpl %eax, 0x54(%rsp)
jl 0x6031
movq (%r14,%r12,8), %rax
movslq %r13d, %r13
movq %rax, (%r14,%r13,8)
movl (%r15,%r12,4), %eax
movl %eax, (%r15,%r13,4)
incl %r13d
incq %r12
cmpq %r12, %rbx
jne 0x5fdd
jmp 0x60c5
movq %r12, %rdi
callq 0x18f9
jmp 0x6188
movq %r12, %rdi
callq 0x1a23
jmp 0x6188
movq %r12, %rdi
callq 0x1a45
xorl %ebp, %ebp
jmp 0x6146
movq %r12, %rdi
callq 0x191b
jmp 0x6188
movq %r12, %rdi
callq 0x193d
movq %r15, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
jmp 0x6188
xorl %r15d, %r15d
imull 0x28(%rsp), %r15d
jmp 0x60e9
xorl %r13d, %r13d
movslq %r13d, %rbx
leaq (,%rbx,4), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2b4d
movq %rax, 0x20(%rbp)
leal 0x4(,%rbx,4), %r15d
jmp 0x60e9
xorl %r13d, %r13d
movslq %r13d, %rbx
leaq (,%rbx,4), %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x2b4d
movq %rax, 0x20(%rbp)
incl %ebx
movq 0x28(%rsp), %r15
imull %ebx, %r15d
movslq %r15d, %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x2b4d
movq %rax, 0x18(%rbp)
movq 0x8(%rsp), %rdi
callq 0x10c0
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x613f
movq 0x8(%rax), %rcx
leaq 0x5547(%rip), %rdx      # 0xb663
cmpq %rdx, %rcx
setne %dl
leaq 0x5d8d(%rip), %rsi      # 0xbeb6
cmpq %rsi, %rcx
setne %cl
testb %cl, %dl
jne 0x613f
movq (%rax), %rcx
movq %rcx, (%rbp)
movq %rbp, (%rax)
jmp 0x6146
movq %rax, (%rbp)
movq %rbp, (%rdi)
movq %rbp, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9e99(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0xc77f(%rip), %rdx      # 0x128e8
cmpl %r13d, %ebp
jne 0x6177
leaq 0x5820(%rip), %rsi      # 0xb995
jmp 0x617e
leaq 0x57eb(%rip), %rsi      # 0xb969
movq %r12, %rcx
xorl %eax, %eax
callq 0x11a0
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %r13
je 0x619c
callq 0x10c0
movq %r13, %rdi
callq 0x10c0
movl $0x1, %edi
callq 0x1270
movq %r12, %rdi
callq 0x1a67
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x19ed
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x19b7
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1981
movq %rbp, %rdi
callq 0x1030
testq %r15, %r15
jne 0x607c
jmp 0x6084