// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movl %edi, %ebp
leaq 0x8c50(%rip), %rdi      # 0xb0ac
leaq 0x94f7(%rip), %rsi      # 0xb95a
callq 0x2c42
leaq 0x10479(%rip), %rcx     # 0x128e8
movq %rax, (%rcx)
leaq 0x50(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x1130
movq %rbx, %rcx
movl $0x1, %r13d
cmpl $0x2, %ebp
movq %rbx, (%rsp)
jl 0x2501
movl %ebp, %r15d
movl $0x1, %r13d
movl $0x1, %r12d
leaq 0x8c06(%rip), %r14      # 0xb0b1
movq (%rcx,%r12,8), %rbx
cmpb $0x2d, (%rbx)
jne 0x24ef
movb 0x1(%rbx), %al
testb %al, %al
je 0x24f9
addq $0x2, %rbx
movsbl %al, %ebp
movq %r14, %rdi
movl %ebp, %esi
callq 0x1140
testq %rax, %rax
je 0x255b
movslq %ebp, %rax
movl $0x1, 0x50(%rsp,%rax,4)
movb (%rbx), %al
incq %rbx
testb %al, %al
jne 0x24bf
movq (%rsp), %rcx
jmp 0x24f9
movslq %r13d, %rax
incl %r13d
movq %rbx, (%rcx,%rax,8)
incq %r12
cmpq %r15, %r12
jne 0x24ab
cmpl $0x1, %r13d
jg 0x2584
movq 0xdaea(%rip), %rbx      # 0xfff8
movq (%rbx), %rdi
leaq 0x103d0(%rip), %rax     # 0x128e8
movq (%rax), %rdx
leaq 0x8baf(%rip), %rsi      # 0xb0d1
leaq 0xdc47(%rip), %rcx      # 0x10170
xorl %eax, %eax
callq 0x11a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x1170
movq (%rbx), %rcx
leaq 0x8b98(%rip), %rdi      # 0xb0df
movl $0x2b, %esi
movl $0x1, %edx
callq 0x1280
jmp 0x263c
movq 0xda96(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x1037c(%rip), %rax     # 0x128e8
movq (%rax), %rdx
leaq 0x8b3d(%rip), %rsi      # 0xb0b3
movl %ebp, %ecx
xorl %eax, %eax
callq 0x11a0
jmp 0x263c
leaq 0x50(%rsp), %rsi
movl 0x1c0(%rsi), %r15d
movq 0x8(%rcx), %rdi
callq 0x3b40
testl %eax, %eax
js 0x263c
cmpl $0x1, %eax
jne 0x25cb
movq 0xda4b(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x10331(%rip), %rax     # 0x128e8
movq (%rax), %rdx
movq (%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0x8b42(%rip), %rsi      # 0xb10b
jmp 0x2635
cmpl $0x0, 0x88(%rsp)
jne 0x2612
leaq 0x8ad3(%rip), %rsi      # 0xb0af
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x57a2
cmpl $-0x1, %eax
je 0x2646
cmpl $-0x2, %eax
jne 0x266a
movq 0xd9fc(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x102e2(%rip), %rax     # 0x128e8
movq (%rax), %rdx
leaq 0x8b4a(%rip), %rsi      # 0xb15a
jmp 0x2661
movq 0xd9df(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x102c5(%rip), %rax     # 0x128e8
movq (%rax), %rdx
movq (%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0x8b00(%rip), %rsi      # 0xb135
xorl %eax, %eax
callq 0x11a0
movl $0x1, %edi
callq 0x1270
movq 0xd9ab(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x10291(%rip), %rax     # 0x128e8
movq (%rax), %rdx
leaq 0x8b15(%rip), %rsi      # 0xb176
xorl %eax, %eax
callq 0x11a0
jmp 0x263c
leaq 0x8a3e(%rip), %rsi      # 0xb0af
leaq 0x50(%rsp), %rdi
callq 0x59ab
movq %rax, %rbx
movq %rax, %rdi
callq 0x62b5
movb $0x1, %r12b
cmpl $0x3, %r13d
jne 0x26e6
movq (%rsp), %rdx
movq 0x10(%rdx), %rdi
cmpb $0x24, (%rdi)
jne 0x26a6
cmpb $0x0, 0x1(%rdi)
je 0x272f
leaq 0x28(%rsp), %r14
movq %r14, %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rsp), %rdx
movq (%r14), %r14
movb $0x1, %r12b
cmpq 0x10(%rdx), %r14
jbe 0x272b
testl %eax, %eax
jle 0x272b
movb (%r14), %al
cmpb $0x2d, %al
jne 0x26ec
cmpb $0x24, 0x1(%r14)
jne 0x26f4
cmpb $0x0, 0x2(%r14)
jne 0x26f4
xorl %r12d, %r12d
jmp 0x272b
movq (%rsp), %rdx
jmp 0x272f
testb %al, %al
setne %r12b
jmp 0x272b
incq %r14
leaq 0x38(%rsp), %r12
movq %r14, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rsp), %rdx
movq (%r12), %rcx
movb $0x1, %r12b
cmpq %r14, %rcx
jbe 0x272b
cmpb $0x0, (%rcx)
setne %cl
testl %eax, %eax
setle %r12b
orb %cl, %r12b
xorb $0x1, %r12b
testb %r12b, %r12b
movl %r15d, 0x10(%rsp)
movl %r12d, 0xc(%rsp)
je 0x278e
leal -0x1(%r13), %edi
shlq $0x3, %rdi
leaq 0x8a57(%rip), %rsi      # 0xb1a4
callq 0x2b85
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x263c
cmpl $0x2, %r13d
jne 0x29d1
movq 0x18(%rsp), %rcx
movl $0x1, (%rcx)
movl 0x80(%rsp), %eax
movl %eax, 0x4(%rcx)
movl $0x2, %eax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
jmp 0x27bc
movq 0x10(%rdx), %rdi
leaq 0x95b8(%rip), %rsi      # 0xbd51
callq 0x2ca1
testq %rax, %rax
je 0x263c
movq %rax, 0x48(%rsp)
movq %rax, %rdi
callq 0x235c
movq %rax, %r13
movq %rax, 0x30(%rsp)
movq 0x18(%rbx), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rbx), %rbx
leaq 0x88a6(%rip), %rbp      # 0xb076
leaq 0x8a54(%rip), %r14      # 0xb22b
movl $0x0, 0x14(%rsp)
movq %r13, 0x40(%rsp)
testb %r12b, %r12b
je 0x2822
movl 0x14(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x29a2
movl 0x14(%rsp), %esi
movslq %esi, %rcx
movq 0x18(%rsp), %rdx
movl (%rdx,%rcx,4), %eax
movl 0x4(%rdx,%rcx,4), %ecx
movl 0x80(%rsp), %edx
cmpl %edx, %ecx
cmovll %ecx, %edx
movl %edx, (%rsp)
addl $0x2, %esi
movl %esi, 0x14(%rsp)
jmp 0x2839
movq %r13, %rdi
callq 0x2394
testl %eax, %eax
jne 0x29a2
movl 0xc(%r13), %eax
movl %eax, (%rsp)
leal -0x1(%rax), %ecx
testl %r15d, %r15d
je 0x28e3
cmpl (%rsp), %eax
jg 0x27e4
movslq %ecx, %r12
movq 0x20(%rsp), %rcx
movq (%rcx,%r12,8), %rax
movq 0x8(%rcx,%r12,8), %r15
movq %rax, %r13
sarq $0x2, %r13
incq %r12
sarq $0x2, %r15
andq $-0x4, %rax
movl (%rbx,%rax), %edx
movl 0x4(%rbx,%rax), %ecx
incl %edx
leaq 0x89a0(%rip), %rdi      # 0xb21d
movl %r12d, %esi
xorl %eax, %eax
callq 0x1100
leaq 0x2(%r13), %rax
cmpq %r15, %rax
jge 0x28ca
addq $0x4, %r13
movl -0x8(%rbx,%r13,4), %esi
movl -0x4(%rbx,%r13,4), %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
cmpq %r15, %r13
jge 0x28bb
movl (%rbx,%r13,4), %esi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0x3(%r13), %rax
incq %r13
cmpq %r15, %r13
movq %rax, %r13
jl 0x2894
movl $0xa, %edi
callq 0x1040
cmpl %r12d, (%rsp)
jne 0x284d
jmp 0x298e
cmpl (%rsp), %eax
jg 0x27e4
movslq %ecx, %r12
movq 0x20(%rsp), %rcx
movq (%rcx,%r12,8), %rax
movq 0x8(%rcx,%r12,8), %r15
movq %rax, %r13
sarq $0x2, %r13
incq %r12
sarq $0x2, %r15
andq $-0x4, %rax
movl (%rbx,%rax), %edx
movl 0x4(%rbx,%rax), %ecx
incl %edx
movq %r15, %r8
subq %r13, %r8
addq $-0x2, %r8
leaq 0x890b(%rip), %rdi      # 0xb234
movl %r12d, %esi
xorl %eax, %eax
callq 0x1100
leaq 0x2(%r13), %rax
cmpq %r15, %rax
jge 0x297a
addq $0x4, %r13
movl -0x8(%rbx,%r13,4), %esi
movl -0x4(%rbx,%r13,4), %edx
leaq 0x8722(%rip), %rdi      # 0xb073
xorl %eax, %eax
callq 0x1100
cmpq %r15, %r13
jge 0x296b
movl (%rbx,%r13,4), %esi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0x3(%r13), %rax
incq %r13
cmpq %r15, %r13
movq %rax, %r13
jl 0x2940
movl $0xa, %edi
callq 0x1040
cmpl %r12d, (%rsp)
jne 0x28ef
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r12d
movq 0x40(%rsp), %r13
jmp 0x27e4
testb %r12b, %r12b
jne 0x29b6
movq 0x48(%rsp), %rdi
callq 0x10c0
movq %r13, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x1030
leaq 0x50(%rsp), %rdi
callq 0x4b18
xorl %edi, %edi
callq 0x1270
movq %rbx, 0x20(%rsp)
cmpl $0x4, %r13d
movl $0x3, %eax
cmovgel %r13d, %eax
leaq -0x4(,%rax,2), %r15
xorl %ebx, %ebx
leaq 0x38(%rsp), %r14
leaq 0x28(%rsp), %r12
movq (%rsp), %rsi
movq 0x10(%rsi,%rbx,4), %rdi
cmpb $0x24, (%rdi)
jne 0x2a17
movl 0x80(%rsp), %r13d
incq %rdi
movq %rdi, 0x28(%rsp)
jmp 0x2a2b
movq %r12, %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rsp), %rsi
movq %rax, %r13
movq 0x28(%rsp), %rcx
cmpq 0x10(%rsi,%rbx,4), %rcx
jbe 0x2ae2
testl %r13d, %r13d
jle 0x2b07
movzbl (%rcx), %eax
cmpl $0x2d, %eax
je 0x2a64
testl %eax, %eax
jne 0x2ae2
movq 0x18(%rsp), %rax
movl %r13d, (%rax,%rbx,4)
movl %r13d, 0x4(%rax,%rbx,4)
jmp 0x2ab9
leaq 0x1(%rcx), %rbp
cmpb $0x24, 0x1(%rcx)
jne 0x2a80
movl 0x80(%rsp), %eax
addq $0x2, %rcx
movq %rcx, 0x38(%rsp)
jmp 0x2a94
movq %rbp, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rsp), %rsi
movq 0x38(%rsp), %rcx
cmpq %rbp, %rcx
jbe 0x2ae2
cmpb $0x0, (%rcx)
jne 0x2ae2
testl %eax, %eax
jle 0x2ae2
movq 0x18(%rsp), %rcx
movl %r13d, (%rcx,%rbx,4)
movl %eax, 0x4(%rcx,%rbx,4)
cmpl %eax, %r13d
jg 0x2b2a
addq $0x2, %rbx
cmpq %rbx, %r15
jne 0x29fb
movq %rbx, 0x30(%rsp)
xorl %r13d, %r13d
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r12d
movq 0x20(%rsp), %rbx
jmp 0x27bc
movq 0xd50f(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xfdf5(%rip), %rax      # 0x128e8
movq (%rax), %rdx
movq 0x10(%rsi,%rbx,4), %rcx
leaq 0x86f0(%rip), %rsi      # 0xb1f2
jmp 0x2635
movq 0xd4ea(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xfdd0(%rip), %rax      # 0x128e8
movq (%rax), %rdx
leaq 0x869d(%rip), %rsi      # 0xb1bf
movl %r13d, %ecx
jmp 0x2578
movq 0xd4c7(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xfdad(%rip), %rax      # 0x128e8
movq (%rax), %rdx
movq 0x10(%rsi,%rbx,4), %rcx
leaq 0x8692(%rip), %rsi      # 0xb1dc
jmp 0x2635
nop