// File: /workspace/github_c_makefile_star2_O3/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 0x8d77(%rip), %rdi      # 0xb010
leaq 0x8efb(%rip), %rsi      # 0xb19b
callq 0x28b2
leaq 0xdeec(%rip), %rcx      # 0x10198
movq %rax, (%rcx)
cmpl $0x2, %ebx
jge 0x22db
movq 0xdd3d(%rip), %rcx      # 0xfff8
movq (%rcx), %rdi
leaq 0x8d54(%rip), %rsi      # 0xb019
leaq 0x8f0b(%rip), %rcx      # 0xb1d7
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
jmp 0x27b5
movl %ebx, %eax
movq %rax, 0x18(%rsp)
movl $0x1, %r12d
leaq 0x68(%rsp), %rbx
movq %r15, 0x20(%rsp)
movq (%r15,%r12,8), %rdi
movq %rbx, %rsi
callq 0x387b
testl %eax, %eax
js 0x27b5
cmpl $0x1, %eax
je 0x270a
movq %rbx, %rdi
callq 0x4084
movl 0xa0(%rsp), %esi
movq 0xb0(%rsp), %rbx
testl %esi, %esi
je 0x2386
leaq 0x8eb4(%rip), %rdi      # 0xb1e5
movq %rdi, %rdx
callq 0x2b9e
movq %rbx, %rdi
movq %rax, %rsi
leaq 0x8d0b(%rip), %rdx      # 0xb051
leaq 0x8d09(%rip), %rcx      # 0xb056
callq 0x2a97
movq %rax, %rdi
leaq 0x8d00(%rip), %rsi      # 0xb05c
callq 0x28b2
testq %rax, %rax
je 0x27b5
movq %rax, %rbx
movq %rax, %rdi
leaq 0x9a15(%rip), %rsi      # 0xbd8c
callq 0x1250
testq %rax, %rax
jne 0x23d6
jmp 0x2768
movq %rbx, %rdi
leaq 0x8e55(%rip), %rsi      # 0xb1e5
leaq 0x8cba(%rip), %rdx      # 0xb051
leaq 0x8cb8(%rip), %rcx      # 0xb056
callq 0x2a97
movq %rax, %rdi
leaq 0x8caf(%rip), %rsi      # 0xb05c
callq 0x28b2
testq %rax, %rax
je 0x27b5
movq %rax, %rbx
movq %rax, %rdi
leaq 0x99c4(%rip), %rsi      # 0xbd8c
callq 0x1250
testq %rax, %rax
je 0x2793
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 0x618f
testl %eax, %eax
jne 0x272e
movl $0x0, 0x4c(%rsp)
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x48(%rsp), %rdx
callq 0x618f
testl %eax, %eax
jne 0x274b
movq %r14, %rdi
callq 0x10d0
movq (%r15,%r12,8), %rdi
leaq 0x8cd5(%rip), %rsi      # 0xb12f
callq 0x29cf
movq %r12, 0x8(%rsp)
movq %rax, %r12
movslq 0x98(%rsp), %r15
movq 0x90(%rsp), %rbx
movq 0x60(%rsp), %rax
movl (%rax), %r14d
movq 0x40(%rsp), %r13
movl 0x2c(%rsp), %ebp
leaq 0x8ca4(%rip), %rdi      # 0xb133
xorl %eax, %eax
callq 0x1110
testl %r14d, %r14d
movq %r12, 0x10(%rsp)
jle 0x2509
leaq 0x8c96(%rip), %rdi      # 0xb13d
movl %r14d, %esi
xorl %eax, %eax
callq 0x1110
leaq 0x8c8b(%rip), %rdi      # 0xb143
movq %r12, %rsi
xorl %eax, %eax
callq 0x1110
movslq 0x98(%rsp), %rcx
testq %rcx, %rcx
jle 0x251a
movq 0xc8(%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 0x24e4
jmp 0x251a
leaq 0x8c33(%rip), %rdi      # 0xb143
movq %r12, %rsi
xorl %eax, %eax
callq 0x1110
leaq 0x8c28(%rip), %rdi      # 0xb149
xorl %eax, %eax
callq 0x1110
movq 0xdaa9(%rip), %r12      # 0xffd8
movq (%r12), %rdx
movq %r15, %rdi
movl $0x7, %esi
callq 0x2c4d
leaq 0x8c0c(%rip), %rdi      # 0xb153
xorl %eax, %eax
callq 0x1110
movq (%r12), %rdx
movq %rbx, %rdi
movl $0xc, %esi
callq 0x2c4d
leaq 0x8bf7(%rip), %rdi      # 0xb15d
xorl %eax, %eax
callq 0x1110
testl %r14d, %r14d
jle 0x25a4
leaq 0x8beb(%rip), %rdi      # 0xb164
xorl %eax, %eax
callq 0x1110
movslq 0x98(%rsp), %rdi
subq %r15, %rdi
movq (%r12), %rdx
xorl %esi, %esi
callq 0x2c4d
leaq 0x8bd2(%rip), %rdi      # 0xb16f
xorl %eax, %eax
callq 0x1110
movl $0xa, %edi
callq 0x1040
testl %ebp, %ebp
jle 0x25cb
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x8(%rsp), %r12
addq (%r13,%rax,8), %r15
incq %rax
cmpq %rax, %rbp
jne 0x25bc
jmp 0x25d3
xorl %r15d, %r15d
movq 0x8(%rsp), %r12
leal -0x1(%rbp), %ebx
leaq 0x8c0a(%rip), %rdi      # 0xb1e7
callq 0x10a0
movslq %ebx, %rax
movq (%r13,%rax,8), %r14
testq %r14, %r14
jle 0x2618
cvtsi2sd %r14, %xmm0
mulsd 0x8a0c(%rip), %xmm0     # 0xb008
cvtsi2sd %r15, %xmm1
divsd %xmm1, %xmm0
leaq 0x8b75(%rip), %rdi      # 0xb181
movl %ebx, %esi
movq %r14, %rdx
movb $0x1, %al
callq 0x1110
cmpl $0x2, %ebp
jl 0x2673
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 0x2667
addq %rdx, %r14
xorps %xmm0, %xmm0
cvtsi2sd %r14, %xmm0
mulsd 0x89b7(%rip), %xmm0     # 0xb008
divsd 0x8(%rsp), %xmm0
leaq 0x8b3e(%rip), %rdi      # 0xb19c
movl %ebp, %esi
movb $0x1, %al
callq 0x1110
leaq -0x1(%rbp), %rax
testq %rbp, %rbp
movq %rax, %rbp
jg 0x2634
movq (%r13), %rcx
xorl %eax, %eax
movq 0x8(%r13,%rax,8), %rdx
incq %rax
cmpq %rcx, %rdx
movq %rdx, %rcx
jl 0x2679
leaq -0x1(%rax), %rsi
cmpl %eax, %ebx
movq 0x20(%rsp), %r15
jle 0x26be
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 0x26b2
movl %edx, %esi
incq %rax
movl %esi, %edx
cmpq %rax, %rcx
jne 0x269f
jmp 0x26c3
movq 0x10(%rsp), %rbx
leaq 0x8aec(%rip), %rdi      # 0xb1b6
xorl %eax, %eax
callq 0x1110
movq %rbx, %rdi
callq 0x1030
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x4862
incq %r12
cmpq 0x18(%rsp), %r12
jne 0x22f2
leaq 0xda9d(%rip), %rax      # 0x10198
movq (%rax), %rdi
callq 0x1030
xorl %edi, %edi
callq 0x1280
movq 0xd8e7(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xda7d(%rip), %rax      # 0x10198
movq (%rax), %rdx
movq 0x8(%r15), %rcx
leaq 0x88fe(%rip), %rsi      # 0xb027
jmp 0x22cf
movq 0xd8c3(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xda59(%rip), %rax      # 0x10198
movq (%rax), %rdx
leaq 0x8983(%rip), %rsi      # 0xb0cc
jmp 0x27ae
movq 0xd8a6(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xda3c(%rip), %rax      # 0x10198
movq (%rax), %rdx
leaq 0x8995(%rip), %rsi      # 0xb0fb
jmp 0x27ae
movq 0xd889(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xda1f(%rip), %rax      # 0x10198
movq (%rax), %rdx
movl 0xa0(%rsp), %ecx
leaq 0x88e7(%rip), %rsi      # 0xb071
xorl %eax, %eax
callq 0x11b0
jmp 0x27b5
movq 0xd85e(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xd9f4(%rip), %rax      # 0x10198
movq (%rax), %rdx
leaq 0x88f2(%rip), %rsi      # 0xb0a0
xorl %eax, %eax
callq 0x11b0
movl $0x1, %edi
callq 0x1280
nop