// File: /workspace/github_c_makefile_star2_O2/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 0x7c37(%rip), %rdi      # 0x9010
leaq 0x7dbb(%rip), %rsi      # 0x919b
callq 0x19c4
leaq 0xcdac(%rip), %rcx      # 0xe198
movq %rax, (%rcx)
cmpl $0x2, %ebx
jge 0x141b
movq 0xcbfd(%rip), %rcx      # 0xdff8
movq (%rcx), %rdi
leaq 0x7c14(%rip), %rsi      # 0x9019
leaq 0x7dcb(%rip), %rcx      # 0x91d7
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
jmp 0x18cf
movl %ebx, %eax
movq %rax, 0x8(%rsp)
pushq $0x1
popq %r12
leaq 0x68(%rsp), %rbx
movq %r15, (%rsp)
cmpq 0x8(%rsp), %r12
je 0x180e
movq (%r15,%r12,8), %rdi
movq %rbx, %rsi
callq 0x27ac
testl %eax, %eax
js 0x18cf
cmpl $0x1, %eax
je 0x1824
movq %rbx, %rdi
callq 0x3052
movl 0xa0(%rsp), %esi
movq 0xb0(%rsp), %rbx
testl %esi, %esi
je 0x14ce
leaq 0x7d6c(%rip), %rdi      # 0x91e5
movq %rdi, %rdx
callq 0x1cca
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x7bc3(%rip), %rdx      # 0x9051
leaq 0x7bc1(%rip), %rcx      # 0x9056
callq 0x1ba3
movq %rax, %rdi
leaq 0x7bb8(%rip), %rsi      # 0x905c
callq 0x19c4
testq %rax, %rax
je 0x18cf
movq %rax, %rbx
movq %rax, %rdi
leaq 0x8865(%rip), %rsi      # 0x9d24
callq 0x1250
testq %rax, %rax
jne 0x151e
jmp 0x1882
movq %rbx, %rdi
leaq 0x7d0d(%rip), %rsi      # 0x91e5
leaq 0x7b72(%rip), %rdx      # 0x9051
leaq 0x7b70(%rip), %rcx      # 0x9056
callq 0x1ba3
movq %rax, %rdi
leaq 0x7b67(%rip), %rsi      # 0x905c
callq 0x19c4
testq %rax, %rax
je 0x18cf
movq %rax, %rbx
movq %rax, %rdi
leaq 0x8814(%rip), %rsi      # 0x9d24
callq 0x1250
testq %rax, %rax
je 0x18ad
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
pushq $0x2
popq %r13
movl %r13d, %edx
callq 0x1240
movq %r14, %rdi
callq 0x11c0
pushq $0x8
popq %rcx
subl %eax, %ecx
movslq %ecx, %rsi
movq %r14, %rdi
movl %r13d, %edx
callq 0x1240
andl $0x0, 0x2c(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x28(%rsp), %rdx
callq 0x50a5
testl %eax, %eax
jne 0x1848
andl $0x0, 0x4c(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x48(%rsp), %rdx
callq 0x50a5
testl %eax, %eax
jne 0x1865
movq %r14, %rdi
callq 0x10d0
movq %r12, 0x18(%rsp)
movq (%r15,%r12,8), %rdi
leaq 0x7b90(%rip), %rsi      # 0x912f
callq 0x1adf
movq %rax, %rbp
movslq 0x98(%rsp), %r13
movq 0x90(%rsp), %rbx
movq 0x60(%rsp), %rax
movl (%rax), %r14d
movq 0x40(%rsp), %r12
movslq 0x2c(%rsp), %r15
leaq 0x7b63(%rip), %rdi      # 0x9133
xorl %eax, %eax
callq 0x1110
testl %r14d, %r14d
movq %rbp, 0x10(%rsp)
jle 0x1649
leaq 0x7b55(%rip), %rdi      # 0x913d
movl %r14d, %esi
xorl %eax, %eax
callq 0x1110
leaq 0x7b4a(%rip), %rdi      # 0x9143
movq %rbp, %rsi
xorl %eax, %eax
callq 0x1110
movl 0x98(%rsp), %ecx
movq 0xc8(%rsp), %rax
testl %ecx, %ecx
movl $0x0, %r8d
cmovlel %r8d, %ecx
imulq $0x28, %rcx, %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x165a
movl 0x4(%rax,%rdx), %esi
xorl %edi, %edi
cmpl %r14d, %esi
setl %dil
cmovgel %r8d, %esi
subq %rdi, %r13
movslq %esi, %rsi
subq %rsi, %rbx
addq $0x28, %rdx
jmp 0x1624
leaq 0x7af3(%rip), %rdi      # 0x9143
movq %rbp, %rsi
xorl %eax, %eax
callq 0x1110
leaq 0x7ae8(%rip), %rdi      # 0x9149
xorl %eax, %eax
callq 0x1110
movq 0xc969(%rip), %rbp      # 0xdfd8
movq (%rbp), %rdx
movq %r13, %rdi
pushq $0x7
popq %rsi
callq 0x1d99
leaq 0x7ace(%rip), %rdi      # 0x9153
xorl %eax, %eax
callq 0x1110
movq (%rbp), %rdx
movq %rbx, %rdi
pushq $0xc
popq %rsi
callq 0x1d99
leaq 0x7abb(%rip), %rdi      # 0x915d
xorl %eax, %eax
callq 0x1110
testl %r14d, %r14d
jle 0x16e0
leaq 0x7aaf(%rip), %rdi      # 0x9164
xorl %eax, %eax
callq 0x1110
movslq 0x98(%rsp), %rdi
subq %r13, %rdi
movq (%rbp), %rdx
xorl %esi, %esi
callq 0x1d99
leaq 0x7a96(%rip), %rdi      # 0x916f
xorl %eax, %eax
callq 0x1110
leaq -0x1(%r15), %r13
pushq $0xa
popq %rdi
callq 0x1040
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
xorl %ecx, %ecx
xorl %r14d, %r14d
leaq 0x7a98(%rip), %rbp      # 0x919c
cmpq %rcx, %rax
je 0x1712
addq (%r12,%rcx,8), %r14
incq %rcx
jmp 0x1704
leaq 0x7ace(%rip), %rdi      # 0x91e7
callq 0x10a0
movq -0x8(%r12,%r15,8), %rbx
testq %rbx, %rbx
jle 0x1752
cvtsi2sd %rbx, %xmm0
mulsd 0x78d3(%rip), %xmm0     # 0x9008
cvtsi2sd %r14, %xmm1
divsd %xmm1, %xmm0
leaq 0x7a3c(%rip), %rdi      # 0x9181
movl %r13d, %esi
movq %rbx, %rdx
movb $0x1, %al
callq 0x1110
subq %rbx, %r14
addl $-0x2, %r15d
cvtsi2sd %r14, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %ebx, %ebx
testl %r15d, %r15d
js 0x179f
movl %r15d, %eax
movq (%r12,%rax,8), %rdx
testq %rdx, %rdx
jle 0x179a
addq %rdx, %rbx
cvtsi2sd %rbx, %xmm0
mulsd 0x7881(%rip), %xmm0     # 0x9008
divsd 0x20(%rsp), %xmm0
movq %rbp, %rdi
movl %r15d, %esi
movb $0x1, %al
callq 0x1110
decl %r15d
jmp 0x1766
movq (%r12), %rcx
xorl %eax, %eax
movq 0x8(%r12,%rax,8), %rdx
incq %rax
cmpq %rcx, %rdx
movq %rdx, %rcx
jl 0x17a5
leal -0x1(%rax), %esi
movq (%rsp), %r15
movq 0x10(%rsp), %rbx
cmpq %r13, %rax
jge 0x17de
movslq %esi, %rcx
movq (%r12,%rcx,8), %rdx
movl %eax, %ecx
cmpq (%r12,%rax,8), %rdx
jl 0x17d7
movl %esi, %ecx
incq %rax
movl %ecx, %esi
jmp 0x17c1
leaq 0x79d1(%rip), %rdi      # 0x91b6
xorl %eax, %eax
callq 0x1110
movq %rbx, %rdi
callq 0x1030
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x380b
movq 0x18(%rsp), %r12
incq %r12
jmp 0x142f
leaq 0xc983(%rip), %rax      # 0xe198
movq (%rax), %rdi
callq 0x1030
xorl %edi, %edi
callq 0x1280
movq 0xc7cd(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xc963(%rip), %rax      # 0xe198
movq (%rax), %rdx
movq 0x8(%r15), %rcx
leaq 0x77e4(%rip), %rsi      # 0x9027
jmp 0x140f
movq 0xc7a9(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xc93f(%rip), %rax      # 0xe198
movq (%rax), %rdx
leaq 0x7869(%rip), %rsi      # 0x90cc
jmp 0x18c8
movq 0xc78c(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xc922(%rip), %rax      # 0xe198
movq (%rax), %rdx
leaq 0x787b(%rip), %rsi      # 0x90fb
jmp 0x18c8
movq 0xc76f(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xc905(%rip), %rax      # 0xe198
movq (%rax), %rdx
movl 0xa0(%rsp), %ecx
leaq 0x77cd(%rip), %rsi      # 0x9071
xorl %eax, %eax
callq 0x11b0
jmp 0x18cf
movq 0xc744(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xc8da(%rip), %rax      # 0xe198
movq (%rax), %rdx
leaq 0x77d8(%rip), %rsi      # 0x90a0
xorl %eax, %eax
callq 0x11b0
pushq $0x1
popq %rdi
callq 0x1280
nop