// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/DASmap.c
// Function: main
int main(int argc, char *argv[])
{ DAZZ_DB     _db, *db = &_db;
  DAZZ_TRACK *map;

  int            reps, *pts;
  int            input_pts;
  File_Iterator *iter = NULL;
  FILE          *input;

  int PRETTY;

  //  Process arguments

  { int   i, j, k;
    int   flags[128];

    ARG_INIT("DASmap")

    j = 1;
    for (i = 1; i < argc; i++)
      if (argv[i][0] == '-')
        ARG_FLAGS("p")
      else
        argv[j++] = argv[i];
    argc = j;

    PRETTY = flags['p'];

    if (argc <= 1)
      { fprintf(stderr,"Usage: %s %s\n",Prog_Name,Usage);
        fprintf(stderr,"\n");
        fprintf(stderr,"      -p: Pretty print (vs easy to parse).\n");
        exit (1);
      }
  }

  //  Open DB or DAM, and if a DAM open also .hdr file

  { int   status, kind;

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

    status = Check_Track(db,"map",&kind);
    if (status == -2)
      { fprintf(stderr,"%s: 'map' track not found.\n",Prog_Name);
        exit (1);
      }
    else if (status == -1)
      { fprintf(stderr,"%s: Warning: 'map' track not sync'd with db.\n",Prog_Name);
        exit (1);
      }
    map = Open_Track(db,"map");
    Load_All_Track_Data(map);
  }

  //  Process read index arguments into a list of read ranges

  input_pts = 0;
  if (argc == 3)
    { if (argv[2][0] != LAST_READ_SYMBOL || argv[2][1] != '\0')
        { char *eptr, *fptr;
          int   b, e;

          b = strtol(argv[2],&eptr,10);
          if (eptr > argv[2] && b > 0)
            { if (*eptr == '-')
                { if (eptr[1] != LAST_READ_SYMBOL || eptr[2] != '\0')
                    { e = strtol(eptr+1,&fptr,10);
                      input_pts = (fptr <= eptr+1 || *fptr != '\0' || e <= 0);
                    }
                }
              else
                input_pts = (*eptr != '\0');
            }
          else
            input_pts = 1;
        }
    }

  if (input_pts)
    { input = Fopen(argv[2],"r");
      if (input == NULL)
        exit (1);

      iter = init_file_iterator(input);
    }
  else
    { pts  = (int *) Malloc(sizeof(int)*2*(argc-1),"Allocating read parameters");
      if (pts == NULL)
        exit (1);

      reps = 0;
      if (argc > 2)
        { int   c, b, e;
          char *eptr, *fptr;

          for (c = 2; c < argc; c++)
            { if (argv[c][0] == LAST_READ_SYMBOL)
                { b = db->nreads;
                  eptr = argv[c]+1;
                }
              else
                b = strtol(argv[c],&eptr,10);
              if (eptr > argv[c])
                { if (b <= 0)
                    { fprintf(stderr,"%s: %d is not a valid index\n",Prog_Name,b);
                      exit (1);
                    }
                  if (*eptr == 0)
                    { pts[reps++] = b;
                      pts[reps++] = b;
                      continue;
                    }
                  else if (*eptr == '-')
                    { if (eptr[1] == LAST_READ_SYMBOL)
                        { e = db->nreads;
                          fptr = eptr+2;
                        }
                      else
                        e = strtol(eptr+1,&fptr,10);
                      if (fptr > eptr+1 && *fptr == 0 && e > 0)
                        { pts[reps++] = b;
                          pts[reps++] = e;
                          if (b > e)
                            { fprintf(stderr,"%s: Empty range '%s'\n",Prog_Name,argv[c]);
                              exit (1);
                            }
                          continue;
                        }
                    }
                }
              fprintf(stderr,"%s: argument '%s' is not an integer range\n",Prog_Name,argv[c]);
              exit (1);
            }
        }
      else
        { pts[reps++] = 1;
          pts[reps++] = db->nreads;
        }
    }

  //  Display each read (and/or QV streams) in the active DB according to the
  //    range pairs in pts[0..reps) and according to the display options.

  { int         c, b, e, i;
    int64      *anno;
    int        *data;
    int64       s, f, j;

    anno = (int64 *) map->anno;
    data =   (int *) map->data;

    c = 0;
    while (1)
      { if (input_pts)
          { if (next_read(iter))
              break;
            e = iter->read;
            b = e-1;
          }
        else
          { if (c >= reps)
              break;
            b = pts[c]-1;
            e = pts[c+1];
            if (e > db->nreads)
              e = db->nreads;
            c += 2;
          }

        if (PRETTY)
          for (i = b; i < e; i++)
            { s = (anno[i] >> 2);
              f = (anno[i+1] >> 2);
              printf(" %d -> %d(%d)",i+1,data[s]+1,data[s+1]);
              for (j = s+2; j < f; j += 3)
                { printf(" [%d,%d]",data[j],data[j+1]);
                  if (j+2 < f)
                    printf(" %d",data[j+2]);
                }
              printf("\n");
            }
        else
          for (i = b; i < e; i++)
            { s = (anno[i] >> 2);
              f = (anno[i+1] >> 2);
              printf(" %d %d %d %lld",i+1,data[s]+1,data[s+1],(f-s)-2);
              for (j = s+2; j < f; j += 3)
                { printf(" %d %d",data[j],data[j+1]);
                  if (j+2 < f)
                    printf(" %d",data[j+2]);
                }
              printf("\n");
            }
      }
  }

  if (input_pts)
    { fclose(input);
      free(iter);
    }
  else
    free(pts);

  Close_DB(db);

  exit (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, %rbp
movl %edi, %ebx
leaq 0x7ba9(%rip), %rdi      # 0x90ac
leaq 0x8450(%rip), %rsi      # 0x995a
callq 0x1c68
leaq 0xf3d2(%rip), %rcx      # 0x108e8
movq %rax, (%rcx)
xorl %eax, %eax
cmpq $0x80, %rax
je 0x152d
andl $0x0, 0x50(%rsp,%rax,4)
incq %rax
jmp 0x151b
movslq %ebx, %r15
pushq $0x1
popq %r12
pushq $0x1
popq %r13
leaq 0x7b72(%rip), %rbx      # 0x90b1
movq %rbp, (%rsp)
cmpq %r15, %r13
jge 0x15bc
movq (%rbp,%r13,8), %r14
cmpb $0x2d, (%r14)
jne 0x157a
incq %r14
movsbl (%r14), %ebp
testl %ebp, %ebp
je 0x1587
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1140
testq %rax, %rax
je 0x1590
movslq %ebp, %rax
movl $0x1, 0x50(%rsp,%rax,4)
jmp 0x1553
movslq %r12d, %rax
incl %r12d
movq %r14, (%rbp,%rax,8)
jmp 0x158b
movq (%rsp), %rbp
incq %r13
jmp 0x1543
movq 0xca61(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xf347(%rip), %rax      # 0x108e8
movq (%rax), %rdx
leaq 0x7b08(%rip), %rsi      # 0x90b3
movl %ebp, %ecx
xorl %eax, %eax
callq 0x11a0
pushq $0x1
popq %rdi
callq 0x1270
cmpl $0x1, %r12d
jg 0x160d
movq 0xca2f(%rip), %rbx      # 0xdff8
movq (%rbx), %rdi
leaq 0xf315(%rip), %rax      # 0x108e8
movq (%rax), %rdx
leaq 0x7af4(%rip), %rsi      # 0x90d1
leaq 0xcb8c(%rip), %rcx      # 0xe170
xorl %eax, %eax
callq 0x11a0
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x1170
movq (%rbx), %rcx
leaq 0x7adf(%rip), %rdi      # 0x90df
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x1280
jmp 0x15b4
leaq 0x50(%rsp), %rsi
movl 0x1c0(%rsi), %eax
movl %eax, 0x3c(%rsp)
movq 0x8(%rbp), %rdi
callq 0x2a50
testl %eax, %eax
js 0x15b4
cmpl $0x1, %eax
jne 0x164f
movq 0xc9c3(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xf2a9(%rip), %rax      # 0x108e8
movq (%rax), %rdx
movq 0x8(%rbp), %rcx
leaq 0x7abe(%rip), %rsi      # 0x910b
jmp 0x16b5
cmpl $0x0, 0x88(%rsp)
jne 0x1696
leaq 0x7a4f(%rip), %rsi      # 0x90af
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x45ea
cmpl $-0x1, %eax
je 0x16c1
cmpl $-0x2, %eax
jne 0x16e8
movq 0xc978(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xf25e(%rip), %rax      # 0x108e8
movq (%rax), %rdx
leaq 0x7ac6(%rip), %rsi      # 0x915a
jmp 0x16dc
movq 0xc95b(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xf241(%rip), %rax      # 0x108e8
movq (%rax), %rdx
movq 0x8(%rbp), %rcx
leaq 0x7a80(%rip), %rsi      # 0x9135
xorl %eax, %eax
callq 0x11a0
jmp 0x15b4
movq 0xc930(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xf216(%rip), %rax      # 0x108e8
movq (%rax), %rdx
leaq 0x7a9a(%rip), %rsi      # 0x9176
xorl %eax, %eax
callq 0x11a0
jmp 0x15b4
leaq 0x79c0(%rip), %rsi      # 0x90af
leaq 0x50(%rsp), %rdi
callq 0x4813
movq %rax, %rbx
movq %rax, %rdi
callq 0x5175
cmpl $0x3, %r12d
jne 0x176b
movq 0x10(%rbp), %rdi
cmpb $0x24, (%rdi)
jne 0x1719
cmpb $0x0, 0x1(%rdi)
je 0x176b
movq %rbx, %r14
leaq 0x28(%rsp), %rbx
pushq $0xa
popq %rdx
movq %rbx, %rsi
callq 0x11d0
movq (%rbx), %rbx
cmpq 0x10(%rbp), %rbx
jbe 0x1902
testl %eax, %eax
jle 0x1902
movb (%rbx), %al
cmpb $0x2d, %al
jne 0x1760
cmpb $0x24, 0x1(%rbx)
jne 0x18d2
cmpb $0x0, 0x2(%rbx)
jne 0x18d2
movq %r14, %rbx
jmp 0x176b
testb %al, %al
movq %r14, %rbx
jne 0x1905
leal -0x1(%r12), %edi
shlq $0x3, %rdi
leaq 0x7a29(%rip), %rsi      # 0x91a4
callq 0x1bad
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x15b4
cmpl $0x2, %r12d
jne 0x17be
movq 0x10(%rsp), %rcx
movl $0x1, (%rcx)
movl 0x80(%rsp), %eax
movl %eax, 0x4(%rcx)
pushq $0x2
popq %rax
movl %eax, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r15d, %r15d
jmp 0x1946
movq %rbx, 0x20(%rsp)
movl %r12d, %r12d
pushq $0x2
popq %rbx
movl $0x0, 0x8(%rsp)
pushq $0xa
popq %rbp
movq (%rsp), %r14
cmpq %r12, %rbx
jae 0x1938
movq (%r14,%rbx,8), %r15
cmpb $0x24, (%r15)
jne 0x17fd
movl 0x80(%rsp), %r13d
incq %r15
movq %r15, 0x28(%rsp)
jmp 0x181e
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
movl %ebp, %edx
callq 0x11d0
movq 0x28(%rsp), %r15
cmpq (%r14,%rbx,8), %r15
jbe 0x18aa
movq %rax, %r13
testl %r13d, %r13d
jle 0x1b30
movzbl (%r15), %eax
cmpl $0x2d, %eax
je 0x1845
testl %eax, %eax
jne 0x18aa
movq 0x10(%rsp), %rax
movl %r13d, -0x10(%rax,%rbx,8)
movl %r13d, -0xc(%rax,%rbx,8)
jmp 0x189d
cmpb $0x24, 0x1(%r15)
jne 0x1861
movl 0x80(%rsp), %eax
addq $0x2, %r15
movq %r15, 0x30(%rsp)
movq %r15, %rcx
jmp 0x187d
incq %r15
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movl %ebp, %edx
callq 0x11d0
movq 0x30(%rsp), %rcx
cmpq %r15, %rcx
jbe 0x18aa
cmpb $0x0, (%rcx)
jne 0x18aa
testl %eax, %eax
jle 0x18aa
movq 0x10(%rsp), %rcx
movl %r13d, -0x10(%rcx,%rbx,8)
movl %eax, -0xc(%rcx,%rbx,8)
cmpl %eax, %r13d
ja 0x1b53
incq %rbx
addl $0x2, 0x8(%rsp)
jmp 0x17d8
movq 0xc747(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xf02d(%rip), %rax      # 0x108e8
movq (%rax), %rdx
movq (%rsp), %rax
movq (%rax,%rbx,8), %rcx
leaq 0x7925(%rip), %rsi      # 0x91f2
jmp 0x16b5
incq %rbx
leaq 0x30(%rsp), %r15
pushq $0xa
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x11d0
movq (%r15), %rcx
cmpq %rbx, %rcx
jbe 0x1902
cmpb $0x0, (%rcx)
jne 0x1902
testl %eax, %eax
movq %r14, %rbx
jg 0x176b
jmp 0x1905
movq %r14, %rbx
movq 0x10(%rbp), %rdi
leaq 0x8441(%rip), %rsi      # 0x9d51
callq 0x1ccb
testq %rax, %rax
je 0x15b4
movq %rax, 0x48(%rsp)
movq %rax, %rdi
callq 0x13ac
movq %rax, %r15
movl $0x0, 0xc(%rsp)
jmp 0x1946
movb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r15d, %r15d
movq 0x20(%rsp), %rbx
movq 0x18(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rbx), %r12
leaq 0x78d1(%rip), %r14      # 0x922b
movl $0x0, 0x1c(%rsp)
movq %r15, 0x40(%rsp)
cmpb $0x0, 0xc(%rsp)
je 0x19a0
movl 0x1c(%rsp), %esi
cmpl 0x8(%rsp), %esi
jge 0x1b06
movslq %esi, %rcx
movq 0x10(%rsp), %rdx
movl (%rdx,%rcx,4), %eax
movl 0x4(%rdx,%rcx,4), %edx
movl 0x80(%rsp), %ecx
cmpl %ecx, %edx
cmovll %edx, %ecx
addl $0x2, %esi
movl %esi, 0x1c(%rsp)
jmp 0x19b6
movq %r15, %rdi
callq 0x13e2
testl %eax, %eax
jne 0x1b0d
movl 0xc(%r15), %eax
movl %eax, %ecx
decl %eax
movslq %eax, %r15
movslq %ecx, %rax
movq %rax, (%rsp)
cmpl $0x0, 0x3c(%rsp)
je 0x1af2
cmpq (%rsp), %r15
jge 0x1afc
movq 0x20(%rsp), %rcx
movq (%rcx,%r15,8), %rax
movq 0x8(%rcx,%r15,8), %rbx
movq %rax, %rbp
sarq $0x2, %rbp
incq %r15
sarq $0x2, %rbx
andq $-0x4, %rax
movl (%r12,%rax), %edx
movl 0x4(%r12,%rax), %ecx
incl %edx
leaq 0x7814(%rip), %rdi      # 0x921d
movl %r15d, %esi
xorl %eax, %eax
callq 0x1100
addq $0x2, %rbp
cmpq %rbx, %rbp
jge 0x1a53
movl (%r12,%rbp,4), %esi
movl 0x4(%r12,%rbp,4), %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0x2(%rbp), %r13
cmpq %rbx, %r13
jge 0x1a4b
movl 0x8(%r12,%rbp,4), %esi
leaq 0x7632(%rip), %rdi      # 0x9076
xorl %eax, %eax
callq 0x1100
incq %r13
movq %r13, %rbp
jmp 0x1a17
pushq $0xa
popq %rdi
callq 0x1040
jmp 0x19cd
movq 0x20(%rsp), %rcx
movq (%rcx,%r15,8), %rax
movq 0x8(%rcx,%r15,8), %rbx
movq %rax, %r13
sarq $0x2, %r13
incq %r15
sarq $0x2, %rbx
andq $-0x4, %rax
movl (%r12,%rax), %edx
movl 0x4(%r12,%rax), %ecx
incl %edx
movq %rbx, %r8
subq %r13, %r8
addq $-0x2, %r8
leaq 0x7798(%rip), %rdi      # 0x9234
movl %r15d, %esi
xorl %eax, %eax
callq 0x1100
addq $0x2, %r13
cmpq %rbx, %r13
jge 0x1aea
movl (%r12,%r13,4), %esi
movl 0x4(%r12,%r13,4), %edx
leaq 0x75b4(%rip), %rdi      # 0x9073
xorl %eax, %eax
callq 0x1100
leaq 0x2(%r13), %rbp
cmpq %rbx, %rbp
jge 0x1ae2
movl 0x8(%r12,%r13,4), %esi
leaq 0x759b(%rip), %rdi      # 0x9076
xorl %eax, %eax
callq 0x1100
incq %rbp
movq %rbp, %r13
jmp 0x1aaa
pushq $0xa
popq %rdi
callq 0x1040
cmpq (%rsp), %r15
jl 0x1a60
movq 0x40(%rsp), %r15
jmp 0x1967
movq 0x10(%rsp), %r15
jmp 0x1b17
movq 0x48(%rsp), %rdi
callq 0x10c0
movq %r15, %rdi
callq 0x1030
leaq 0x50(%rsp), %rdi
callq 0x3aaf
xorl %edi, %edi
callq 0x1270
movq 0xc4c1(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xeda7(%rip), %rax      # 0x108e8
movq (%rax), %rdx
leaq 0x7674(%rip), %rsi      # 0x91bf
movl %r13d, %ecx
jmp 0x15ad
movq 0xc49e(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0xed84(%rip), %rax      # 0x108e8
movq (%rax), %rdx
movq (%rsp), %rax
movq (%rax,%rbx,8), %rcx
leaq 0x7666(%rip), %rsi      # 0x91dc
jmp 0x16b5
nop