// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movl %edi, %ebp
leaq 0x18b49(%rip), %rdi     # 0x1b038
leaq 0x19977(%rip), %rsi     # 0x1be6d
callq 0x131d6
leaq 0x1eed6(%rip), %r13     # 0x213d8
movq %rax, (%r13)
movl $0x320, 0x1ec8c(%rip)   # imm = 0x320
cmpl $0x2, %ebp
jl 0x2621
movl %ebp, %r13d
movl $0x1, %r14d
movl $0x1, %ebx
leaq 0x18b15(%rip), %r15     # 0x1b043
movq 0x8(%rsp), %rbp
movq (%rbp,%rbx,8), %r12
cmpb $0x2d, (%r12)
jne 0x25b9
movzbl 0x1(%r12), %eax
testl %eax, %eax
je 0x25c4
addq $0x2, %r12
cmpl $0x6c, %eax
jne 0x2591
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x11c0
movl %eax, 0x1ec32(%rip)     # 0x2119c
movq 0x10(%rsp), %rcx
cmpb $0x0, (%rcx)
movq (%rbp,%rbx,8), %r8
jne 0x26b3
cmpb $0x0, 0x2(%r8)
je 0x26b3
testl %eax, %eax
jg 0x25c4
jmp 0x26e0
movsbl %al, %ebp
movq %r15, %rdi
movl %ebp, %esi
callq 0x1140
testq %rax, %rax
je 0x2685
movb (%r12), %al
incq %r12
testb %al, %al
jne 0x2591
movq 0x8(%rsp), %rbp
jmp 0x25c4
movslq %r14d, %rax
incl %r14d
movq %r12, (%rbp,%rax,8)
incq %rbx
cmpq %r13, %rbx
jne 0x2533
cmpl $0x5, %r14d
leaq 0x1edfd(%rip), %r13     # 0x213d8
jne 0x2621
movq 0x8(%rsp), %rbx
movq 0x8(%rbx), %rdi
leaq 0x1ec0b(%rip), %rsi     # 0x211f8
callq 0x1419f
testl %eax, %eax
js 0x26a9
cmpl $0x1, %eax
jne 0x270e
movq 0x1e9ee(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
movq (%r13), %rdx
movq 0x8(%rbx), %rcx
leaq 0x18b21(%rip), %rsi     # 0x1b13d
jmp 0x2730
movq 0x1e9d0(%rip), %rbx     # 0x20ff8
movq (%rbx), %rdi
movq (%r13), %rdx
leaq 0x18a96(%rip), %rsi     # 0x1b0cc
leaq 0x18bb0(%rip), %rcx     # 0x1b1ed
xorl %eax, %eax
callq 0x11a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x1170
movq (%rbx), %rcx
leaq 0x18a7f(%rip), %rdi     # 0x1b0da
movl $0x36, %esi
movl $0x1, %edx
callq 0x1280
movq (%rbx), %rcx
leaq 0x18a9d(%rip), %rdi     # 0x1b111
movl $0x2b, %esi
movl $0x1, %edx
callq 0x1280
jmp 0x26a9
movq 0x1e96c(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
leaq 0x1ed42(%rip), %rax     # 0x213d8
movq (%rax), %rdx
leaq 0x189a5(%rip), %rsi     # 0x1b045
movl %ebp, %ecx
xorl %eax, %eax
callq 0x11a0
movl $0x1, %edi
callq 0x1270
movq 0x1e93e(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
leaq 0x1ed14(%rip), %rax     # 0x213d8
movq (%rax), %rdx
movsbl 0x1(%r8), %ecx
addq $0x2, %r8
leaq 0x1898c(%rip), %rsi     # 0x1b063
xorl %eax, %eax
callq 0x11a0
jmp 0x26a9
movq 0x1e911(%rip), %rcx     # 0x20ff8
movq (%rcx), %rdi
leaq 0x1ece7(%rip), %rcx     # 0x213d8
movq (%rcx), %rdx
leaq 0x18991(%rip), %rsi     # 0x1b08c
leaq 0x189a8(%rip), %rcx     # 0x1b0aa
movl %eax, %r8d
xorl %eax, %eax
callq 0x11a0
jmp 0x26a9
cmpl $0x0, 0x1eb1b(%rip)     # 0x21230
jne 0x273c
movq 0x1e8da(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
movq (%r13), %rdx
movq 0x8(%rbx), %rcx
leaq 0x18a37(%rip), %rsi     # 0x1b167
xorl %eax, %eax
callq 0x11a0
jmp 0x26a9
leaq 0x1eab5(%rip), %r15     # 0x211f8
movq %r15, %rdi
callq 0x149a8
movq %r15, %rdi
xorl %esi, %esi
callq 0x15880
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %r14
movq %r14, %rsi
callq 0x1190
testl %eax, %eax
jne 0x27c2
movq %r15, 0x1e9f8(%rip)     # 0x21168
leaq 0x1ea81(%rip), %r14     # 0x211f8
movl 0x1eabb(%rip), %eax     # 0x21238
movl %eax, 0x1ea1d(%rip)     # 0x211a0
movl 0x40(%r15), %eax
movl %eax, 0x1ea17(%rip)     # 0x211a4
leaq 0x189fe(%rip), %rsi     # 0x1b192
movq %r14, %rdi
callq 0x1600c
testq %rax, %rax
jne 0x2812
movq 0x1e850(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
movq (%r13), %rdx
leaq 0x189e0(%rip), %rsi     # 0x1b196
xorl %eax, %eax
callq 0x11a0
jmp 0x26a9
movq 0x1e99f(%rip), %rsi     # 0x21168
movq %r14, %rdi
callq 0x1419f
testl %eax, %eax
js 0x26a9
cmpl $0x1, %eax
je 0x2603
movq 0x1e97f(%rip), %rdi     # 0x21168
cmpl $0x0, 0x38(%rdi)
je 0x2717
callq 0x149a8
movq 0x1e969(%rip), %rdi     # 0x21168
xorl %esi, %esi
callq 0x15880
movq 0x1e95b(%rip), %r15     # 0x21168
jmp 0x2770
movq %rax, %r15
movq %rax, %rdi
callq 0x168e7
movq 0x18(%r15), %rax
movq %rax, 0x1e980(%rip)     # 0x211a8
movq 0x28(%r15), %rcx
movq %rcx, 0x1e97d(%rip)     # 0x211b0
movl 0x1e9ef(%rip), %edx     # 0x21228
testl %edx, %edx
js 0x2850
leaq 0x1(%rdx), %rsi
xorl %edi, %edi
shrq $0x2, (%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x2843
movq (%rax), %rsi
movl (%rcx,%rsi,4), %esi
movl %esi, 0x1e95c(%rip)     # 0x211b8
movslq %edx, %rdx
movq -0x8(%rax,%rdx,8), %rax
movl (%rcx,%rax,4), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1e94c(%rip)     # 0x211bc
subl %esi, %eax
addl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x18907(%rip), %rsi     # 0x1b18a
callq 0x13119
movslq 0x1e929(%rip), %rcx     # 0x211b8
shlq $0x2, %rcx
subq %rcx, %rax
movq %rax, 0x1e923(%rip)     # 0x211c0
movslq 0x1e984(%rip), %rcx     # 0x21228
movslq 0x1e911(%rip), %r8      # 0x211bc
movl %ecx, (%rax,%r8,4)
testq %rcx, %rcx
jle 0x2904
movq 0x1e8f5(%rip), %rdx     # 0x211b0
movq 0x1e8e6(%rip), %rsi     # 0x211a8
movq -0x8(%rsi,%rcx,8), %rdi
movslq (%rdx,%rdi,4), %rdi
cmpl %edi, %r8d
jle 0x28ed
leal -0x1(%r8), %r9d
cmpl %edi, %r9d
jle 0x28f0
movslq %r8d, %r9
decq %r9
movl %ecx, (%rax,%r9,4)
decq %r9
cmpq %rdi, %r9
jg 0x28df
jmp 0x28f0
movl %r8d, %r9d
leaq -0x1(%rcx), %r10
movl %r10d, (%rax,%rdi,4)
movl %r9d, %r8d
cmpq $0x1, %rcx
movq %r10, %rcx
jg 0x28c2
movq 0x1e85d(%rip), %rdi     # 0x21168
cmpq %r14, %rdi
jne 0x2b3e
movq 0x1e88d(%rip), %rcx     # 0x211a8
movq %rcx, 0x1e8a6(%rip)     # 0x211c8
movq 0x1e887(%rip), %rdx     # 0x211b0
movq %rdx, 0x1e8a0(%rip)     # 0x211d0
movq %rax, 0x1e8a9(%rip)     # 0x211e0
movq 0x1e872(%rip), %rax     # 0x211b0
movq 0x1e863(%rip), %rsi     # 0x211a8
movq (%rsi), %rdi
movl (%rax,%rdi,4), %edi
movl %edi, 0x1e867(%rip)     # 0x211b8
movq (%rcx), %rdi
movl (%rdx,%rdi,4), %edi
movl %edi, 0x1e87b(%rip)     # 0x211d8
movslq 0x1e8c4(%rip), %rdi     # 0x21228
movq -0x8(%rsi,%rdi,8), %rsi
movl (%rax,%rsi,4), %eax
incl %eax
movl %eax, 0x1e848(%rip)     # 0x211bc
movslq 0x30(%r14), %rax
movq -0x8(%rcx,%rax,8), %rax
movl (%rdx,%rax,4), %eax
incl %eax
movl %eax, 0x1e854(%rip)     # 0x211dc
movq 0x18(%rbx), %rdi
leaq 0x1882d(%rip), %r12     # 0x1b1c0
movq %r12, %rsi
callq 0x132f3
movq %rax, %r14
movq 0x18(%rbx), %rdi
callq 0x13299
movq %rax, %rbp
movq 0x20(%rbx), %rdi
movq %r12, %rsi
callq 0x132f3
movq %rax, %r12
movq 0x20(%rbx), %rdi
callq 0x13299
movq %rax, %r15
movq %r14, %rdi
movq %r12, %rsi
callq 0x1190
testl %eax, %eax
jne 0x29fd
movq %rbp, %rdi
movq %r15, %rsi
callq 0x1190
testl %eax, %eax
jne 0x29fd
movq 0x1e60e(%rip), %rax     # 0x20ff8
movq (%rax), %rdi
movq (%r13), %rdx
leaq 0x187cd(%rip), %rsi     # 0x1b1c5
jmp 0x27b6
movq %rbp, %rdi
leaq 0x187e4(%rip), %rbp     # 0x1b1eb
leaq 0x187b2(%rip), %r13     # 0x1b1c0
movq %rdi, 0x8(%rsp)
movq %rbp, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x133bb
leaq 0x1985c(%rip), %rsi     # 0x1c284
movq %rax, %rdi
callq 0x13239
movq %rax, %rbx
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x133bb
leaq 0x19233(%rip), %rsi     # 0x1bc7e
movq %rax, %rdi
callq 0x13239
movq %rax, 0x1e78e(%rip)     # 0x211e8
testq %rbx, %rbx
je 0x26a9
movq %rax, %r12
testq %rax, %rax
je 0x26a9
movq 0x8(%rsp), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq $0x0, 0x1e764(%rip) # 0x211f0
leaq 0x1e75d(%rip), %r14     # 0x211f0
movl $0x0, 0x1e6fb(%rip)     # 0x21198
leaq 0x1e6f4(%rip), %r15     # 0x21198
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rcx
callq 0x1280
movq 0x1e728(%rip), %rcx     # 0x211e8
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
callq 0x1280
leaq 0x10(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x10b0
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rcx
callq 0x10b0
movq %rbx, %rdi
callq 0x2c56
movq 0x1e6db(%rip), %rdi     # 0x211e8
callq 0x1110
movq 0x1e6cf(%rip), %rcx     # 0x211e8
movl $0x8, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x1280
movq 0x1e6b6(%rip), %rdi     # 0x211e8
callq 0x10c0
xorl %edi, %edi
callq 0x1270
leaq 0x1864d(%rip), %rsi     # 0x1b192
callq 0x1600c
testq %rax, %rax
je 0x27a1
movq %rax, %r14
movq %rax, %rdi
callq 0x168e7
movq 0x18(%r14), %rax
movq %rax, 0x1e65f(%rip)     # 0x211c8
movq 0x28(%r14), %rcx
movq %rcx, 0x1e65c(%rip)     # 0x211d0
movq 0x1e5ed(%rip), %rdx     # 0x21168
movl 0x30(%rdx), %edx
testl %edx, %edx
js 0x2b95
leaq 0x1(%rdx), %rsi
xorl %edi, %edi
shrq $0x2, (%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x2b88
movq (%rax), %rsi
movl (%rcx,%rsi,4), %esi
movl %esi, 0x1e637(%rip)     # 0x211d8
movslq %edx, %rdx
movq -0x8(%rax,%rdx,8), %rax
movl (%rcx,%rax,4), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1e627(%rip)     # 0x211dc
subl %esi, %eax
addl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0x185c2(%rip), %rsi     # 0x1b18a
callq 0x13119
movslq 0x1e604(%rip), %rcx     # 0x211d8
shlq $0x2, %rcx
subq %rcx, %rax
movq %rax, 0x1e5fe(%rip)     # 0x211e0
movq 0x1e57f(%rip), %r14     # 0x21168
movslq 0x30(%r14), %rsi
movslq 0x1e5e8(%rip), %r8      # 0x211dc
movl %esi, (%rax,%r8,4)
movq 0x1e5d1(%rip), %rdx     # 0x211d0
movq 0x1e5c2(%rip), %rcx     # 0x211c8
testq %rsi, %rsi
jle 0x2937
movq -0x8(%rcx,%rsi,8), %rdi
movslq (%rdx,%rdi,4), %rdi
cmpl %edi, %r8d
jle 0x2c3a
leal -0x1(%r8), %r9d
cmpl %edi, %r9d
jle 0x2c3d
movslq %r8d, %r9
decq %r9
movl %esi, (%rax,%r9,4)
decq %r9
cmpq %rdi, %r9
jg 0x2c2c
jmp 0x2c3d
movl %r8d, %r9d
leaq -0x1(%rsi), %r10
movl %r10d, (%rax,%rdi,4)
movl %r9d, %r8d
cmpq $0x1, %rsi
movq %r10, %rsi
jg 0x2c0f
jmp 0x2937