// File: /workspace/github_c_makefile_star2_O3/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, (%rsp)
movl %edi, %ebx
leaq 0x8cbf(%rip), %rdi      # 0xb0ac
leaq 0x95c6(%rip), %rsi      # 0xb9ba
callq 0x2bb2
leaq 0x104e8(%rip), %r15     # 0x128e8
movq %rax, (%r15)
leaq 0x50(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x1130
cmpl $0x2, %ebx
jl 0x249d
movl %ebx, %r15d
movl $0x1, %r13d
movl $0x1, %r12d
leaq 0x8c7e(%rip), %rbx      # 0xb0b1
movq (%rsp), %rcx
movq (%rcx,%r12,8), %r14
cmpb $0x2d, (%r14)
jne 0x247e
movb 0x1(%r14), %al
testb %al, %al
je 0x2488
addq $0x2, %r14
movsbl %al, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1140
testq %rax, %rax
je 0x24e7
movslq %ebp, %rax
movl $0x1, 0x50(%rsp,%rax,4)
movb (%r14), %al
incq %r14
testb %al, %al
jne 0x244d
movq (%rsp), %rcx
jmp 0x2488
movslq %r13d, %rax
incl %r13d
movq %r14, (%rcx,%rax,8)
incq %r12
cmpq %r15, %r12
jne 0x2437
cmpl $0x1, %r13d
leaq 0x1044d(%rip), %r15     # 0x128e8
jg 0x2515
movq 0xdb54(%rip), %rbx      # 0xfff8
movq (%rbx), %rdi
movq (%r15), %rdx
leaq 0x8c20(%rip), %rsi      # 0xb0d1
leaq 0xdcb8(%rip), %rcx      # 0x10170
xorl %eax, %eax
callq 0x11a0
movq (%rbx), %rsi
movl $0xa, %edi
callq 0x1170
movq (%rbx), %rcx
leaq 0x8c09(%rip), %rdi      # 0xb0df
movl $0x2b, %esi
movl $0x1, %edx
callq 0x1280
jmp 0x250b
movq 0xdb0a(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x103f0(%rip), %rax     # 0x128e8
movq (%rax), %rdx
leaq 0x8bb1(%rip), %rsi      # 0xb0b3
movl %ebp, %ecx
xorl %eax, %eax
callq 0x11a0
movl $0x1, %edi
callq 0x1270
leaq 0x50(%rsp), %rsi
movl 0x1c0(%rsi), %r14d
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3b7b
testl %eax, %eax
js 0x250b
cmpl $0x1, %eax
jne 0x2555
movq 0xdaba(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq (%r15), %rdx
movq (%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0x8bb8(%rip), %rsi      # 0xb10b
jmp 0x25b1
cmpl $0x0, 0x88(%rsp)
jne 0x2595
leaq 0x8b49(%rip), %rsi      # 0xb0af
leaq 0x50(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x57e2
cmpl $-0x1, %eax
je 0x25bd
cmpl $-0x2, %eax
jne 0x25dd
movq 0xda72(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq (%r15), %rdx
leaq 0x8bc7(%rip), %rsi      # 0xb15a
jmp 0x25d1
movq 0xda5c(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq (%r15), %rdx
movq (%rsp), %rax
movq 0x8(%rax), %rcx
leaq 0x8b84(%rip), %rsi      # 0xb135
xorl %eax, %eax
callq 0x11a0
jmp 0x250b
movq 0xda34(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq (%r15), %rdx
leaq 0x8ba5(%rip), %rsi      # 0xb176
xorl %eax, %eax
callq 0x11a0
jmp 0x250b
leaq 0x8acb(%rip), %rsi      # 0xb0af
leaq 0x50(%rsp), %rdi
callq 0x59e8
movq %rax, %r15
movq %rax, %rdi
callq 0x62c3
cmpl $0x3, %r13d
jne 0x268d
movq (%rsp), %rax
movq 0x10(%rax), %rdi
cmpb $0x24, (%rdi)
jne 0x2616
cmpb $0x0, 0x1(%rdi)
je 0x268d
leaq 0x28(%rsp), %rbx
movq %rbx, %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rbx), %rbx
movq (%rsp), %rcx
cmpq 0x10(%rcx), %rbx
jbe 0x2804
testl %eax, %eax
jle 0x2804
movb (%rbx), %al
cmpb $0x2d, %al
jne 0x27fc
cmpb $0x24, 0x1(%rbx)
jne 0x2657
cmpb $0x0, 0x2(%rbx)
je 0x268d
incq %rbx
leaq 0x38(%rsp), %r12
movq %rbx, %rdi
movq %r12, %rsi
movl $0xa, %edx
callq 0x11d0
movq (%r12), %rcx
cmpq %rbx, %rcx
jbe 0x2804
cmpb $0x0, (%rcx)
jne 0x2804
testl %eax, %eax
jle 0x2804
leal -0x1(%r13), %edi
shlq $0x3, %rdi
leaq 0x8b08(%rip), %rsi      # 0xb1a4
callq 0x2af5
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x250b
cmpl $0x2, %r13d
jne 0x26e2
movq 0x10(%rsp), %rcx
movl $0x1, (%rcx)
movl 0x80(%rsp), %eax
movl %eax, 0x4(%rcx)
movl $0x2, %eax
movq %rax, 0x30(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r13d, %r13d
jmp 0x283e
movq %r15, 0x20(%rsp)
movl %r13d, %r15d
addq $-0x2, %r15
xorl %ebx, %ebx
movq (%rsp), %rsi
movq 0x10(%rsi,%rbx,4), %rbp
cmpb $0x24, (%rbp)
jne 0x2714
movq %rbx, %r12
movl 0x80(%rsp), %r13d
incq %rbp
movq %rbp, 0x28(%rsp)
jmp 0x2740
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rsp), %rsi
movq 0x28(%rsp), %rbp
movq %rbx, %r12
cmpq 0x10(%rsi,%rbx,4), %rbp
jbe 0x2a52
movq %rax, %r13
testl %r13d, %r13d
jle 0x2a77
movzbl (%rbp), %eax
cmpl $0x2d, %eax
je 0x276d
testl %eax, %eax
jne 0x2a52
movq 0x10(%rsp), %rax
movq %r12, %rbx
movl %r13d, (%rax,%r12,4)
movl %r13d, 0x4(%rax,%r12,4)
jmp 0x27da
cmpb $0x24, 0x1(%rbp)
jne 0x2788
movl 0x80(%rsp), %eax
addq $0x2, %rbp
movq %rbp, 0x38(%rsp)
movq %rbp, %rcx
jmp 0x27af
incq %rbp
movq %rbp, %rdi
leaq 0x38(%rsp), %rsi
movl $0xa, %edx
callq 0x11d0
movq (%rsp), %rsi
movq 0x38(%rsp), %rcx
cmpq %rbp, %rcx
jbe 0x2a52
cmpb $0x0, (%rcx)
jne 0x2a52
testl %eax, %eax
jle 0x2a52
movq 0x10(%rsp), %rcx
movq %r12, %rbx
movl %r13d, (%rcx,%r12,4)
movl %eax, 0x4(%rcx,%r12,4)
cmpl %eax, %r13d
ja 0x2a9a
addq $0x2, %rbx
decq %r15
jne 0x26f4
movq %rbx, 0x30(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %r13d, %r13d
movq 0x20(%rsp), %r15
jmp 0x283e
testb %al, %al
je 0x268d
movq (%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x959e(%rip), %rsi      # 0xbdb1
callq 0x2c15
testq %rax, %rax
je 0x250b
movq %rax, 0x48(%rsp)
movq %rax, %rdi
callq 0x22ec
movq %rax, %r13
movl $0x0, 0xc(%rsp)
movq %rax, 0x30(%rsp)
movq 0x18(%r15), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%r15), %r12
leaq 0x8824(%rip), %rbp      # 0xb076
leaq 0x89d2(%rip), %rbx      # 0xb22b
movl $0x0, 0x1c(%rsp)
movl %r14d, 0x18(%rsp)
movq %r13, 0x40(%rsp)
movl 0xc(%rsp), %r15d
testb %r15b, %r15b
je 0x28ac
movl 0x1c(%rsp), %eax
cmpl 0x30(%rsp), %eax
jge 0x2a34
movslq %eax, %rcx
movq 0x10(%rsp), %rdx
movl %eax, %esi
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, 0x1c(%rsp)
jmp 0x28c3
movq %r13, %rdi
callq 0x2324
testl %eax, %eax
jne 0x2a28
movl 0xc(%r13), %eax
movl %eax, (%rsp)
leal -0x1(%rax), %ecx
testl %r14d, %r14d
je 0x28d5
cmpl (%rsp), %eax
jg 0x2870
jmp 0x2983
cmpl (%rsp), %eax
jg 0x2870
movslq %ecx, %r14
movq 0x20(%rsp), %rcx
movq (%rcx,%r14,8), %rax
movq 0x8(%rcx,%r14,8), %r15
movq %rax, %r13
sarq $0x2, %r13
incq %r14
sarq $0x2, %r15
andq $-0x4, %rax
movl (%r12,%rax), %edx
movl 0x4(%r12,%rax), %ecx
incl %edx
movq %r15, %r8
subq %r13, %r8
addq $-0x2, %r8
leaq 0x891b(%rip), %rdi      # 0xb234
movl %r14d, %esi
xorl %eax, %eax
callq 0x1100
leaq 0x2(%r13), %rax
cmpq %r15, %rax
jge 0x296a
addq $0x4, %r13
movl -0x8(%r12,%r13,4), %esi
movl -0x4(%r12,%r13,4), %edx
leaq 0x8732(%rip), %rdi      # 0xb073
xorl %eax, %eax
callq 0x1100
cmpq %r15, %r13
jge 0x295b
movl (%r12,%r13,4), %esi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0x3(%r13), %rax
incq %r13
cmpq %r15, %r13
movq %rax, %r13
jl 0x2930
movl $0xa, %edi
callq 0x1040
cmpl %r14d, (%rsp)
jne 0x28dd
jmp 0x2a19
movslq %ecx, %r14
movq 0x20(%rsp), %rcx
movq (%rcx,%r14,8), %rax
movq 0x8(%rcx,%r14,8), %r15
movq %rax, %r13
sarq $0x2, %r13
incq %r14
sarq $0x2, %r15
andq $-0x4, %rax
movl (%r12,%rax), %edx
movl 0x4(%r12,%rax), %ecx
incl %edx
leaq 0x8865(%rip), %rdi      # 0xb21d
movl %r14d, %esi
xorl %eax, %eax
callq 0x1100
leaq 0x2(%r13), %rax
cmpq %r15, %rax
jge 0x2a05
addq $0x4, %r13
movl -0x8(%r12,%r13,4), %esi
movl -0x4(%r12,%r13,4), %edx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1100
cmpq %r15, %r13
jge 0x29f6
movl (%r12,%r13,4), %esi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0x3(%r13), %rax
incq %r13
cmpq %r15, %r13
movq %rax, %r13
jl 0x29cf
movl $0xa, %edi
callq 0x1040
cmpl %r14d, (%rsp)
jne 0x2986
movl 0x18(%rsp), %r14d
movq 0x40(%rsp), %r13
jmp 0x286b
movq 0x48(%rsp), %rdi
callq 0x10c0
jmp 0x2a39
movq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x1030
leaq 0x50(%rsp), %rdi
callq 0x4b62
xorl %edi, %edi
callq 0x1270
movq 0xd59f(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xfe85(%rip), %rax      # 0x128e8
movq (%rax), %rdx
movq 0x10(%rsi,%r12,4), %rcx
leaq 0x8780(%rip), %rsi      # 0xb1f2
jmp 0x25b1
movq 0xd57a(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xfe60(%rip), %rax      # 0x128e8
movq (%rax), %rdx
leaq 0x872d(%rip), %rsi      # 0xb1bf
movl %r13d, %ecx
jmp 0x2504
movq 0xd557(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0xfe3d(%rip), %rax      # 0x128e8
movq (%rax), %rdx
movq 0x10(%rsi,%rbx,4), %rcx
leaq 0x8722(%rip), %rsi      # 0xb1dc
jmp 0x25b1
nop