// File: /workspace/github_c_makefile_star2_O1/thegenemyers[P]DASCRUBBER/REPcover.c
// Function: main
int main(int argc, char *argv[])
{ int c;

  //  Process arguments

  Prog_Name = Strdup("REPcover","");

  if (argc < 2)
    { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
      exit (1);
    }

  //  Open trimmed DB and the qual-track

  for (c = 1; c < argc; c++)
    { DAZZ_DB    _DB, *DB  = &_DB;
      DAZZ_EXTRA  ex_hgap, ex_covr;

      //  Load DB

      { int status;

        status = Open_DB(argv[c],DB);
        if (status < 0)
          exit (1);
        if (status == 1)
          { fprintf(stderr,"%s: Cannot be called on a .dam index: %s\n",Prog_Name,argv[1]);
            exit (1);
          }
        Trim_DB(DB);
      }

      //  Get .covr track extras

      { FILE *afile;
        char *aname;
        int   extra;

        afile = NULL;
        if (DB->part)
          { aname = Strdup(Catenate(DB->path,Numbered_Suffix(".",DB->part,"."),"covr",".anno"),
                           "Allocating anno file");
            if (aname == NULL)
              exit (1);
            afile  = fopen(aname,"r");
            if (afile == NULL)
             { fprintf(stderr,"%s: Must have a 'covr.%d' track, run DAScover\n",Prog_Name,DB->part);
               exit (1);
             }
          }
        else
          { aname = Strdup(Catenate(DB->path,".","covr",".anno"),"Allocating anno file");
            if (aname == NULL)
              exit (1);
            afile  = fopen(aname,"r");
            if (afile == NULL)
              { fprintf(stderr,"%s: Must have a 'covr' track, run DAScover\n",Prog_Name);
                exit (1);
              }
          }

        fseeko(afile,0,SEEK_END);
        extra = ftell(afile) - sizeof(int)*2;
        fseeko(afile,-extra,SEEK_END);
        ex_covr.nelem = 0;
        if (Read_Extra(afile,aname,&ex_covr) != 0)
          { fprintf(stderr,"%s: Histogram extra missing from .covr track?\n",Prog_Name);
            exit (1);
          }
        ex_hgap.nelem = 0;
        if (Read_Extra(afile,aname,&ex_hgap) != 0)
          { fprintf(stderr,"%s: Hgap threshold extra missing from .covr track?\n",Prog_Name);
            exit (1);
          }
        fclose(afile);
      }

      //  Generate display

      { char       *root;
        int         i, cmax, hgap_min, cover;
        int64       nreads, totlen;
        int64      *cgram;
        int64       ssum, stotal;

        root   = Root(argv[c],".db");
        nreads = DB->nreads;
        totlen = DB->totlen;

        hgap_min = (int) ((int64 *) (ex_hgap.value))[0];
        cgram    = (int64 *) (ex_covr.value);
        cmax     = ex_covr.nelem - 1;

        printf("\nDAScover");
        if (hgap_min > 0)
          printf(" -H%d",hgap_min);
        printf(" %s\n\n",root);

        if (hgap_min > 0) 
          { for (i = 0; i < DB->nreads; i++)
              if (DB->reads[i].rlen < hgap_min)
                { nreads -= 1;
                  totlen -= DB->reads[i].rlen;
                }
          }

        // Display histogram

        printf("\nInput:  ");
        Print_Number(nreads,7,stdout);
        printf(" reads,  ");
        Print_Number(totlen,12,stdout);
        printf(" bases");
        if (hgap_min > 0)
          { printf(" (another ");
            Print_Number(DB->nreads-nreads,0,stdout);
            printf(" were < H-length)");
          }
        printf("\n");

        stotal = 0;
        for (i = 0; i <= cmax; i++)
          stotal += cgram[i];

        printf("\nCoverage Histogram\n\n");
        ssum = cgram[cmax];
        if (ssum > 0)
          printf("    %4d:  %9lld  %5.1f%%\n\n",
                 cmax,cgram[cmax],(100.*ssum)/stotal);
        stotal -= ssum;
        ssum    = 0;
        for (i = cmax-1; i >= 0; i--)
          if (cgram[i] > 0)
            { ssum += cgram[i];
              printf("    %4d:  %9lld  %5.1f%%\n",
                     i,cgram[i],(100.*ssum)/stotal);
            }

        i = 0;
        while (cgram[i+1] < cgram[i])
          i += 1;
        for (cover = i++; i < cmax; i++)
          if (cgram[cover] < cgram[i])
            cover = i;

        printf("\n  Coverage is estimated at %d\n\n",cover);

        free(root);
        Close_DB(DB);
      }
    }

  free(Prog_Name);
  exit (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r15
movl %edi, %ebx
leaq 0x7d07(%rip), %rdi      # 0xa010
leaq 0x7e8b(%rip), %rsi      # 0xa19b
callq 0x2922
leaq 0xce7c(%rip), %rcx      # 0xf198
movq %rax, (%rcx)
cmpl $0x2, %ebx
jge 0x234b
movq 0xcccd(%rip), %rcx      # 0xeff8
movq (%rcx), %rdi
leaq 0x7ce4(%rip), %rsi      # 0xa019
leaq 0x7e9b(%rip), %rcx      # 0xa1d7
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
jmp 0x2825
movl %ebx, %eax
movq %rax, 0x18(%rsp)
movl $0x1, %r12d
leaq 0x48(%rsp), %rbx
movq %r15, 0x20(%rsp)
movq (%r15,%r12,8), %rdi
movq %rbx, %rsi
callq 0x3820
testl %eax, %eax
js 0x2825
cmpl $0x1, %eax
je 0x277a
movq %rbx, %rdi
callq 0x3fe5
movl 0x80(%rsp), %esi
testl %esi, %esi
je 0x23f6
movq 0x90(%rsp), %rbx
leaq 0x7e44(%rip), %rdi      # 0xa1e5
movq %rdi, %rdx
callq 0x2bed
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x7c9b(%rip), %rdx      # 0xa051
leaq 0x7c99(%rip), %rcx      # 0xa056
callq 0x2afd
movq %rax, %rdi
leaq 0x7c90(%rip), %rsi      # 0xa05c
callq 0x2922
testq %rax, %rax
je 0x2825
movq %rax, %rbx
movq %rax, %rdi
leaq 0x893d(%rip), %rsi      # 0xad24
callq 0x1250
testq %rax, %rax
jne 0x244b
jmp 0x27d8
movq 0x90(%rsp), %rdi
leaq 0x7de0(%rip), %rsi      # 0xa1e5
leaq 0x7c45(%rip), %rdx      # 0xa051
leaq 0x7c43(%rip), %rcx      # 0xa056
callq 0x2afd
movq %rax, %rdi
leaq 0x7c3a(%rip), %rsi      # 0xa05c
callq 0x2922
testq %rax, %rax
je 0x2825
movq %rax, %rbx
movq %rax, %rdi
leaq 0x88e7(%rip), %rsi      # 0xad24
callq 0x1250
testq %rax, %rax
je 0x2803
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1240
movq %r14, %rdi
callq 0x11c0
movl $0x8, %ecx
subl %eax, %ecx
movslq %ecx, %rsi
movq %r14, %rdi
movl $0x2, %edx
callq 0x1240
movl $0x0, 0x2c(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x28(%rsp), %rdx
callq 0x6161
testl %eax, %eax
jne 0x279e
movl $0x0, 0xbc(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0xb8(%rsp), %rdx
callq 0x6161
testl %eax, %eax
jne 0x27bb
movq %r14, %rdi
callq 0x10d0
movq (%r15,%r12,8), %rdi
leaq 0x7c5a(%rip), %rsi      # 0xa12f
callq 0x2a38
movq %r12, 0x8(%rsp)
movq %rax, %r12
movslq 0x78(%rsp), %r15
movq 0x70(%rsp), %rbx
movq 0xd0(%rsp), %rax
movl (%rax), %r14d
movq 0x40(%rsp), %r13
movl 0x2c(%rsp), %ebp
leaq 0x7c2c(%rip), %rdi      # 0xa133
xorl %eax, %eax
callq 0x1110
testl %r14d, %r14d
movq %r12, 0x10(%rsp)
jle 0x257e
leaq 0x7c1e(%rip), %rdi      # 0xa13d
movl %r14d, %esi
xorl %eax, %eax
callq 0x1110
leaq 0x7c13(%rip), %rdi      # 0xa143
movq %r12, %rsi
xorl %eax, %eax
callq 0x1110
movslq 0x78(%rsp), %rcx
testq %rcx, %rcx
jle 0x258f
movq 0xa8(%rsp), %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rcx
xorl %edx, %edx
xorl %r8d, %r8d
movl 0x4(%rax,%rdx), %esi
xorl %edi, %edi
cmpl %r14d, %esi
setl %dil
cmovgel %r8d, %esi
subq %rdi, %r15
movslq %esi, %rsi
subq %rsi, %rbx
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0x2559
jmp 0x258f
leaq 0x7bbe(%rip), %rdi      # 0xa143
movq %r12, %rsi
xorl %eax, %eax
callq 0x1110
leaq 0x7bb3(%rip), %rdi      # 0xa149
xorl %eax, %eax
callq 0x1110
movq 0xca34(%rip), %r12      # 0xefd8
movq (%r12), %rdx
movq %r15, %rdi
movl $0x7, %esi
callq 0x2ca0
leaq 0x7b97(%rip), %rdi      # 0xa153
xorl %eax, %eax
callq 0x1110
movq (%r12), %rdx
movq %rbx, %rdi
movl $0xc, %esi
callq 0x2ca0
leaq 0x7b82(%rip), %rdi      # 0xa15d
xorl %eax, %eax
callq 0x1110
testl %r14d, %r14d
jle 0x2616
leaq 0x7b76(%rip), %rdi      # 0xa164
xorl %eax, %eax
callq 0x1110
movslq 0x78(%rsp), %rdi
subq %r15, %rdi
movq (%r12), %rdx
xorl %esi, %esi
callq 0x2ca0
leaq 0x7b60(%rip), %rdi      # 0xa16f
xorl %eax, %eax
callq 0x1110
movl $0xa, %edi
callq 0x1040
testl %ebp, %ebp
jle 0x263d
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x8(%rsp), %r12
addq (%r13,%rax,8), %r15
incq %rax
cmpq %rax, %rbp
jne 0x262e
jmp 0x2645
xorl %r15d, %r15d
movq 0x8(%rsp), %r12
leal -0x1(%rbp), %ebx
leaq 0x7b98(%rip), %rdi      # 0xa1e7
callq 0x10a0
movslq %ebx, %rax
movq (%r13,%rax,8), %r14
testq %r14, %r14
jle 0x268a
cvtsi2sd %r14, %xmm0
mulsd 0x799a(%rip), %xmm0     # 0xa008
cvtsi2sd %r15, %xmm1
divsd %xmm1, %xmm0
leaq 0x7b03(%rip), %rdi      # 0xa181
movl %ebx, %esi
movq %r14, %rdx
movb $0x1, %al
callq 0x1110
cmpl $0x2, %ebp
jl 0x26e5
addl $-0x2, %ebp
subq %r14, %r15
xorps %xmm0, %xmm0
cvtsi2sd %r15, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
movq (%r13,%rbp,8), %rdx
testq %rdx, %rdx
jle 0x26d9
addq %rdx, %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
mulsd 0x7945(%rip), %xmm0     # 0xa008
divsd 0x8(%rsp), %xmm0
leaq 0x7acc(%rip), %rdi      # 0xa19c
movl %ebp, %esi
movb $0x1, %al
callq 0x1110
leaq -0x1(%rbp), %rax
testq %rbp, %rbp
movq %rax, %rbp
jg 0x26a6
xorl %eax, %eax
movq %rax, %rcx
movq 0x8(%r13,%rax,8), %rdx
incq %rax
cmpq (%r13,%rcx,8), %rdx
jl 0x26e7
leaq -0x1(%rax), %rsi
cmpl %eax, %ebx
movq 0x20(%rsp), %r15
jle 0x272e
movl %ebx, %ecx
movl %esi, %edx
movq 0x10(%rsp), %rbx
movslq %edx, %rsi
movq (%r13,%rsi,8), %rdi
movl %eax, %esi
cmpq (%r13,%rax,8), %rdi
jl 0x2722
movl %edx, %esi
incq %rax
movl %esi, %edx
cmpq %rax, %rcx
jne 0x270f
jmp 0x2733
movq 0x10(%rsp), %rbx
leaq 0x7a7c(%rip), %rdi      # 0xa1b6
xorl %eax, %eax
callq 0x1110
movq %rbx, %rdi
callq 0x1030
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
callq 0x47f8
incq %r12
cmpq 0x18(%rsp), %r12
jne 0x2362
leaq 0xca2d(%rip), %rax      # 0xf198
movq (%rax), %rdi
callq 0x1030
xorl %edi, %edi
callq 0x1280
movq 0xc877(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0xca0d(%rip), %rax      # 0xf198
movq (%rax), %rdx
movq 0x8(%r15), %rcx
leaq 0x788e(%rip), %rsi      # 0xa027
jmp 0x233f
movq 0xc853(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0xc9e9(%rip), %rax      # 0xf198
movq (%rax), %rdx
leaq 0x7913(%rip), %rsi      # 0xa0cc
jmp 0x281e
movq 0xc836(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0xc9cc(%rip), %rax      # 0xf198
movq (%rax), %rdx
leaq 0x7925(%rip), %rsi      # 0xa0fb
jmp 0x281e
movq 0xc819(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0xc9af(%rip), %rax      # 0xf198
movq (%rax), %rdx
movl 0x80(%rsp), %ecx
leaq 0x7877(%rip), %rsi      # 0xa071
xorl %eax, %eax
callq 0x11b0
jmp 0x2825
movq 0xc7ee(%rip), %rax      # 0xeff8
movq (%rax), %rdi
leaq 0xc984(%rip), %rax      # 0xf198
movq (%rax), %rdx
leaq 0x7882(%rip), %rsi      # 0xa0a0
xorl %eax, %eax
callq 0x11b0
movl $0x1, %edi
callq 0x1280
nop