// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/DASrealign.c
// Function: main
int main(int argc, char *argv[])
{ DAZZ_TRACK *map1, *map2;

  //  Process arguments

  { int  i, j, k;
    int  flags[128];
    char *eptr;

    ARG_INIT("DASrealign")

    MIN_LEN = 800;

    j = 1;
    for (i = 1; i < argc; i++)
      if (argv[i][0] == '-')
        switch (argv[i][1])
        { default:
            ARG_FLAGS("v")
            break;
          case 'l':
            ARG_POSITIVE(MIN_LEN,"Minimum piece length to recompute")
            break;
        }
      else
        argv[j++] = argv[i];
    argc = j;

    VERBOSE = flags['v'];

    if (argc != 5)
      { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
        fprintf(stderr,"\n");
        fprintf(stderr,"      -v: Verbose mode, output statistics as proceed.\n");
        fprintf(stderr,"      -l: minimum length alignment length.\n");
        exit (1);
      }
  }

  { int status;

    status = Open_DB(argv[1],ADB);
    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);
      }
    if ( ! ADB->part)
      { fprintf(stderr,"%s: Must be called on a block: %s\n",Prog_Name,argv[1]);
        exit (1);
      }
    Trim_DB(ADB);

    Load_All_Reads(ADB,0);
  }

  if (strcmp(argv[1],argv[2]) == 0)
    BDB = ADB;
  else
    { int status;

      status = Open_DB(argv[2],BDB);
      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);
        }
      if ( ! BDB->part)
        { fprintf(stderr,"%s: Must be called on a block: %s\n",Prog_Name,argv[1]);
          exit (1);
        }
      Trim_DB(BDB);

      Load_All_Reads(BDB,0);
    }
  AFIRST = ADB->tfirst;
  BFIRST = BDB->tfirst;

  map1 = Open_Track(ADB,"map");
  if (map1 != NULL)
    { int i, o, q, n; 

      Load_All_Track_Data(map1);
 
      AMAP_IDX = (int64 *) map1->anno;
      AMAP     = (int *) map1->data;
      for (i = 0; i <= ADB->nreads; i++)
        AMAP_IDX[i] /= sizeof(int);

      ADB_ofirst = AMAP[AMAP_IDX[0]];
      ADB_olast  = AMAP[AMAP_IDX[ADB->nreads-1]]+1;
      IAMAP = (int *) Malloc(sizeof(int)*((ADB_olast-ADB_ofirst)+1),"Inverse map") - ADB_ofirst;

      IAMAP[q = ADB_olast] = n = ADB->nreads;
      for (i = ADB->nreads-1; i >= 0; i--)
        { o = AMAP[AMAP_IDX[i]];
          if (q > o)
            while (--q > o)
              IAMAP[q] = n;
          IAMAP[o] = n = i;
        }
    }
  else
    { fprintf(stderr,"%s: Must have a 'map' track, run DASedit\n",Prog_Name);
      exit (1);
    }

  if (BDB == ADB)
    { map2 = map1;
      BMAP_IDX = AMAP_IDX;
      BMAP = AMAP;
      BDB_ofirst = ADB_ofirst;
      BDB_olast  = ADB_olast ;
      IBMAP = IAMAP;
    }
  else
    { map2 = Open_Track(BDB,"map");
      if (map2 != NULL)
        { int i, o, q, n; 

          Load_All_Track_Data(map2);
     
          BMAP_IDX = (int64 *) map2->anno;
          BMAP     = (int *) map2->data;
          for (i = 0; i <= BDB->nreads; i++)
            BMAP_IDX[i] /= sizeof(int);

          BDB_ofirst = BMAP[BMAP_IDX[0]];
          BDB_olast  = BMAP[BMAP_IDX[BDB->nreads-1]]+1;
          IBMAP = (int *) Malloc(sizeof(int)*((BDB_olast-BDB_ofirst)+1),"Inverse map") - BDB_ofirst;

          IBMAP[q = BDB_olast] = n = BDB->nreads;
          for (i = BDB->nreads-1; i >= 0; i--)
            { o = BMAP[BMAP_IDX[i]];
              if (q > o)
                while (--q > o)
                  IBMAP[q] = n;
              IBMAP[o] = n = i;
            }
        }
      else
        { fprintf(stderr,"%s: Must have a 'map' track, run DASedit\n",Prog_Name);
          exit (1);
        }
    }

  ADB_ofirst = AMAP[AMAP_IDX[0]];
  BDB_ofirst = BMAP[BMAP_IDX[0]];
  ADB_olast  = AMAP[AMAP_IDX[ADB->nreads-1]]+1;
  BDB_olast  = BMAP[BMAP_IDX[BDB->nreads-1]]+1;

  //  Open .las and process piles therein output new piles to F.las

  { FILE *input;
    char *las, *pwd;
    char *lasT, *pwdT;
    int64 novl;

    las = Root(argv[3],".las");
    pwd = PathTo(argv[3]);

    lasT = Root(argv[4],".las");
    pwdT = PathTo(argv[4]);

    if (strcmp(las,lasT) == 0 && strcmp(pwd,pwdT) == 0)
      { fprintf(stderr,"%s: source and target are the same !\n",Prog_Name);
        exit (1);
      }

    input  = Fopen(Catenate(pwd,"/",las,".las"),"r");
    OUTPUT = Fopen(Catenate(pwdT,"/",lasT,".las"),"w");
    if (input == NULL || OUTPUT == NULL)
      exit (1);
    free(pwd);
    free(las);

    WOVLS = 0;
    TRACE_SPACING = 0;
    fwrite(&WOVLS,sizeof(int64),1,OUTPUT);
    fwrite(&TRACE_SPACING,sizeof(int),1,OUTPUT);

    fread(&novl,sizeof(int64),1,input);
    fread(&TRACE_SPACING,sizeof(int),1,input);

    make_a_pass(input,EXTENDER,1);

    rewind(OUTPUT);
    fwrite(&WOVLS,sizeof(int64),1,OUTPUT);
    fclose(OUTPUT);
  }

  exit (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r13
movl %edi, %ebp
leaq 0x17c4b(%rip), %rdi     # 0x19038
leaq 0x18a19(%rip), %rsi     # 0x19e0d
callq 0x11584
leaq 0x1dfd8(%rip), %rcx     # 0x1f3d8
movq %rax, (%rcx)
movl $0x320, 0x1dd8f(%rip)   # imm = 0x320
movslq %ebp, %rbp
pushq $0x1
popq %r14
pushq $0x1
popq %rbx
leaq 0x17c25(%rip), %r15     # 0x19043
movq %rbp, 0x8(%rsp)
cmpq %rbp, %rbx
jge 0x14f0
movq (%r13,%rbx,8), %r12
cmpb $0x2d, (%r12)
jne 0x1481
cmpb $0x6c, 0x1(%r12)
jne 0x148e
addq $0x2, %r12
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x11c0
movl %eax, 0x1dd42(%rip)     # 0x1f19c
movq 0x10(%rsp), %rcx
cmpb $0x0, (%rcx)
movq (%r13,%rbx,8), %r8
jne 0x159d
cmpb $0x0, 0x2(%r8)
je 0x159d
testl %eax, %eax
jg 0x14bb
jmp 0x15cd
movslq %r14d, %rax
incl %r14d
movq %r12, (%r13,%rax,8)
jmp 0x14bb
movq %r13, %rbp
incq %r12
movsbl (%r12), %r13d
testl %r13d, %r13d
je 0x14b3
movq %r15, %rdi
movl %r13d, %esi
callq 0x1140
incq %r12
testq %rax, %rax
jne 0x1494
jmp 0x14c3
movq %rbp, %r13
movq 0x8(%rsp), %rbp
incq %rbx
jmp 0x1423
movq 0x1db2e(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1df04(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
leaq 0x17b67(%rip), %rsi     # 0x19045
movl %r13d, %ecx
xorl %eax, %eax
callq 0x11a0
pushq $0x1
popq %rdi
callq 0x1270
cmpl $0x5, %r14d
jne 0x1537
movq 0x8(%r13), %rdi
leaq 0x1dcf7(%rip), %rsi     # 0x1f1f8
callq 0x1236c
testl %eax, %eax
js 0x14e8
cmpl $0x1, %eax
jne 0x15fe
movq 0x1dade(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1deb4(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
movq 0x8(%r13), %rcx
leaq 0x17c0b(%rip), %rsi     # 0x1913d
jmp 0x1626
movq 0x1daba(%rip), %r14     # 0x1eff8
movq (%r14), %rdi
leaq 0x1de90(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
leaq 0x17b7a(%rip), %rsi     # 0x190cc
leaq 0x17c94(%rip), %rcx     # 0x191ed
xorl %eax, %eax
callq 0x11a0
movq (%r14), %rsi
pushq $0xa
popq %rdi
callq 0x1170
movq (%r14), %rcx
leaq 0x17b65(%rip), %rdi     # 0x190da
pushq $0x36
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x1280
movq (%r14), %rcx
leaq 0x17b84(%rip), %rdi     # 0x19111
pushq $0x2b
popq %rsi
movq %rbx, %rdx
callq 0x1280
jmp 0x14e8
movq 0x1da54(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1de2a(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
movsbl 0x1(%r8), %ecx
addq $0x2, %r8
leaq 0x17aa2(%rip), %rsi     # 0x19063
xorl %eax, %eax
callq 0x11a0
jmp 0x14e8
movq 0x1da24(%rip), %rcx     # 0x1eff8
movq (%rcx), %rdi
leaq 0x1ddfa(%rip), %rcx     # 0x1f3d8
movq (%rcx), %rdx
leaq 0x17aa4(%rip), %rsi     # 0x1908c
leaq 0x17abb(%rip), %rcx     # 0x190aa
movl %eax, %r8d
xorl %eax, %eax
callq 0x11a0
jmp 0x14e8
cmpl $0x0, 0x1dc2b(%rip)     # 0x1f230
jne 0x1632
movq 0x1d9ea(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1ddc0(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
movq 0x8(%r13), %rcx
leaq 0x17b41(%rip), %rsi     # 0x19167
xorl %eax, %eax
callq 0x11a0
jmp 0x14e8
leaq 0x1dbbf(%rip), %r15     # 0x1f1f8
movq %r15, %rdi
callq 0x12c12
movq %r15, %rdi
xorl %esi, %esi
callq 0x13912
movq 0x8(%r13), %rdi
movq 0x10(%r13), %r14
movq %r14, %rsi
callq 0x1190
testl %eax, %eax
jne 0x16d4
movq %r15, 0x1db02(%rip)     # 0x1f168
leaq 0x1db8b(%rip), %r14     # 0x1f1f8
movl 0x1dbc5(%rip), %eax     # 0x1f238
movl %eax, 0x1db27(%rip)     # 0x1f1a0
movl 0x40(%r15), %eax
movl %eax, 0x1db21(%rip)     # 0x1f1a4
leaq 0x17b08(%rip), %rsi     # 0x19192
movq %r14, %rdi
callq 0x1412f
testq %rax, %rax
je 0x17fc
movq %rax, %r15
movq %rax, %rdi
callq 0x14a91
movq 0x18(%r15), %rax
movq %rax, 0x1daf7(%rip)     # 0x1f1a8
movq 0x28(%r15), %rcx
movq %rcx, 0x1daf4(%rip)     # 0x1f1b0
movslq 0x1db65(%rip), %rdx     # 0x1f228
xorl %esi, %esi
cmpq %rdx, %rsi
jg 0x1724
shrq $0x2, (%rax,%rsi,8)
incq %rsi
jmp 0x16c5
movq 0x1da8d(%rip), %rsi     # 0x1f168
movq %r14, %rdi
callq 0x1236c
testl %eax, %eax
js 0x14e8
cmpl $0x1, %eax
je 0x1513
movq 0x1da6d(%rip), %rdi     # 0x1f168
cmpl $0x0, 0x38(%rdi)
je 0x1607
callq 0x12c12
movq 0x1da57(%rip), %rdi     # 0x1f168
xorl %esi, %esi
callq 0x13912
movq 0x1da49(%rip), %r15     # 0x1f168
jmp 0x1666
movq (%rax), %rsi
movl (%rcx,%rsi,4), %esi
movl %esi, 0x1da88(%rip)     # 0x1f1b8
movq -0x8(%rax,%rdx,8), %rax
movl (%rcx,%rax,4), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1da7b(%rip)     # 0x1f1bc
subl %esi, %eax
addl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x17a36(%rip), %rsi     # 0x1918a
callq 0x114c9
movslq 0x1da58(%rip), %rcx     # 0x1f1b8
shlq $0x2, %rcx
subq %rcx, %rax
movq %rax, 0x1da52(%rip)     # 0x1f1c0
movl 0x1dab4(%rip), %edi     # 0x1f228
movslq 0x1da41(%rip), %rsi     # 0x1f1bc
movl %edi, (%rax,%rsi,4)
movq 0x1da2b(%rip), %rcx     # 0x1f1b0
movq 0x1da1c(%rip), %rdx     # 0x1f1a8
testl %edi, %edi
jle 0x17bf
movq %rdi, %r8
decq %r8
movl %r8d, %r9d
movq (%rdx,%r9,8), %r9
movslq (%rcx,%r9,4), %r9
cmpl %r9d, %esi
jle 0x17b6
movslq %esi, %rsi
decq %rsi
cmpq %r9, %rsi
jle 0x17b6
movl %edi, (%rax,%rsi,4)
jmp 0x17a9
movl %r8d, (%rax,%r9,4)
movq %r8, %rdi
jmp 0x178c
movq 0x1d9a2(%rip), %rdi     # 0x1f168
cmpq %r14, %rdi
jne 0x17eb
movq %rdx, 0x1d9f6(%rip)     # 0x1f1c8
movq %rcx, 0x1d9f7(%rip)     # 0x1f1d0
movq %rax, 0x1da00(%rip)     # 0x1f1e0
movq %rdx, %rsi
movq %rcx, %rax
jmp 0x190e
leaq 0x179a0(%rip), %rsi     # 0x19192
callq 0x1412f
testq %rax, %rax
jne 0x1823
movq 0x1d7f5(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1dbcb(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
leaq 0x1797f(%rip), %rsi     # 0x19196
xorl %eax, %eax
callq 0x11a0
jmp 0x14e8
movq %rax, %r14
movq %rax, %rdi
callq 0x14a91
movq 0x18(%r14), %rax
movq %rax, 0x1d98f(%rip)     # 0x1f1c8
movq 0x28(%r14), %rcx
movq %rcx, 0x1d98c(%rip)     # 0x1f1d0
movq 0x1d91d(%rip), %rdx     # 0x1f168
movslq 0x30(%rdx), %rdx
xorl %esi, %esi
cmpq %rdx, %rsi
jg 0x1860
shrq $0x2, (%rax,%rsi,8)
incq %rsi
jmp 0x1851
movq (%rax), %rsi
movl (%rcx,%rsi,4), %esi
movl %esi, 0x1d96c(%rip)     # 0x1f1d8
movq -0x8(%rax,%rdx,8), %rax
movl (%rcx,%rax,4), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1d95f(%rip)     # 0x1f1dc
subl %esi, %eax
addl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x178fa(%rip), %rsi     # 0x1918a
callq 0x114c9
movslq 0x1d93c(%rip), %rcx     # 0x1f1d8
shlq $0x2, %rcx
subq %rcx, %rax
movq %rax, 0x1d936(%rip)     # 0x1f1e0
movq 0x1d8b7(%rip), %r14     # 0x1f168
movl 0x30(%r14), %edi
movslq 0x1d920(%rip), %rsi     # 0x1f1dc
movl %edi, (%rax,%rsi,4)
movq 0x1d90a(%rip), %rcx     # 0x1f1d0
movq 0x1d8fb(%rip), %rdx     # 0x1f1c8
testl %edi, %edi
jle 0x1900
movq %rdi, %r8
decq %r8
movl %r8d, %r9d
movq (%rdx,%r9,8), %r9
movslq (%rcx,%r9,4), %r9
cmpl %r9d, %esi
jle 0x18f7
movslq %esi, %rsi
decq %rsi
cmpq %r9, %rsi
jle 0x18f7
movl %edi, (%rax,%rsi,4)
jmp 0x18ea
movl %r8d, (%rax,%r9,4)
movq %r8, %rdi
jmp 0x18cd
movq 0x1d8a9(%rip), %rax     # 0x1f1b0
movq 0x1d89a(%rip), %rsi     # 0x1f1a8
movq (%rsi), %rdi
movl (%rax,%rdi,4), %edi
movl %edi, 0x1d89e(%rip)     # 0x1f1b8
movq (%rdx), %rdi
movl (%rcx,%rdi,4), %edi
movl %edi, 0x1d8b2(%rip)     # 0x1f1d8
movslq 0x1d8fb(%rip), %rdi     # 0x1f228
movq -0x8(%rsi,%rdi,8), %rsi
movl (%rax,%rsi,4), %eax
incl %eax
movl %eax, 0x1d87f(%rip)     # 0x1f1bc
movslq 0x30(%r14), %rax
movq -0x8(%rdx,%rax,8), %rax
movl (%rcx,%rax,4), %eax
incl %eax
movl %eax, 0x1d88b(%rip)     # 0x1f1dc
movq 0x18(%r13), %rdi
leaq 0x17864(%rip), %r12     # 0x191c0
movq %r12, %rsi
callq 0x1169f
movq %rax, %r14
movq 0x18(%r13), %rdi
callq 0x11647
movq %rax, %rbx
movq 0x20(%r13), %rdi
movq %r12, %rsi
callq 0x1169f
movq %rax, %r12
movq 0x20(%r13), %rdi
callq 0x11647
movq %rax, %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x1190
testl %eax, %eax
jne 0x19cc
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1190
testl %eax, %eax
jne 0x19cc
movq 0x1d645(%rip), %rax     # 0x1eff8
movq (%rax), %rdi
leaq 0x1da1b(%rip), %rax     # 0x1f3d8
movq (%rax), %rdx
leaq 0x177fe(%rip), %rsi     # 0x191c5
jmp 0x1817
leaq 0x17818(%rip), %rbp     # 0x191eb
leaq 0x177e6(%rip), %r15     # 0x191c0
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11763
leaq 0x1882d(%rip), %rsi     # 0x1a224
movq %rax, %rdi
callq 0x115e7
movq %rax, %rbx
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x11763
leaq 0x18204(%rip), %rsi     # 0x19c1e
movq %rax, %rdi
callq 0x115e7
movq %rax, 0x1d7bf(%rip)     # 0x1f1e8
testq %rbx, %rbx
je 0x14e8
movq %rax, %r13
testq %rax, %rax
je 0x14e8
movq 0x8(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
andq $0x0, 0x1d798(%rip)     # 0x1f1f0
leaq 0x1d791(%rip), %r14     # 0x1f1f0
andl $0x0, 0x1d732(%rip)     # 0x1f198
leaq 0x1d72b(%rip), %rbp     # 0x1f198
pushq $0x8
popq %r15
pushq $0x1
popq %r12
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1280
movq 0x1d75b(%rip), %rcx     # 0x1f1e8
pushq $0x4
popq %r13
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1280
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x10b0
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x10b0
movq %rbx, %rdi
callq 0x1aff
movq 0x1d716(%rip), %rdi     # 0x1f1e8
callq 0x1110
movq 0x1d70a(%rip), %rcx     # 0x1f1e8
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1280
movq 0x1d6f5(%rip), %rdi     # 0x1f1e8
callq 0x10c0
xorl %edi, %edi
callq 0x1270