// File: /workspace/github_c_makefile_star2_O3/jsh58[P]Genrich/Genrich.c
// Function: readSAM
uint64_t readSAM(File in, bool gz, char* line, Aln** aln,
    char* readName, double* totalLen, uint64_t* unmapped,
    uint64_t* paired, uint64_t* single, uint64_t* pairedPr,
    uint64_t* singlePr, uint64_t* supp, uint64_t* skipped,
    uint64_t* lowMapQ, int minMapQ, int xcount,
    char** xchrList, int xBedLen, Bed* xBed,
    uint64_t* secPair, uint64_t* secSingle,
    uint64_t* orphan, int* chromLen, Chrom** chrom,
    bool singleOpt, bool extendOpt, int extend,
    bool avgExtOpt, Aln*** unpair, int* unpairMem,
    float asDiff, bool atacOpt, int atacLen5, int atacLen3,
    bool atacAdj, File bed, bool bedOpt, bool gzOut,
    bool ctrl, int sample, bool dupsOpt, File dups,
    bool dupsVerb, Read*** readPr, int* readMemPr,
    Read*** readDc, int* readMemDc, Read*** readSn,
    int* readMemSn, HashAln*** table, uint32_t* tableMem,
    HashAln*** tableSn, uint32_t* tableSnMem,
    uint32_t** order, uint32_t** order0, uint32_t** order1,
    uint32_t** order2, uint16_t** qualA, uint16_t** qual0,
    uint16_t** qual1, uint16_t** qual2, uint32_t* arrMem,
    uint64_t* countPr, uint64_t* dupsPr, uint64_t* countDc,
    uint64_t* dupsDc, uint64_t* countSn, uint64_t* dupsSn,
    uint64_t* errCount, bool sortOpt, bool verbose) {

  // SAM fields to save
  char* qname, *rname, *cigar, *rnext, *seq, *qual, *extra;
  uint16_t flag;
  uint32_t pos, pnext;
  int32_t tlen;
  uint8_t mapq;

  int alnLen = 0;     // number of alignments for this read
  int unpairIdx = 0;  // \ indexes into unpaired array(s)
  int unpairLen = 0;  // /   (with avgExtOpt)
  int readIdxPr = 0;  // \ indexes into read array readPr
  int readLenPr = 0;  // /   (with dupsOpt)
  int readIdxDc = 0;  // \ indexes into read array readDc
  int readLenDc = 0;  // /   (with dupsOpt)
  int readIdxSn = 0;  // \ indexes into read array readSn
  int readLenSn = 0;  // /   (with dupsOpt)
  uint16_t qualR1 = 0, qualR2 = 0; // sums of quality scores
  bool pastHeader = false;    // to check for misplaced header lines
  uint64_t count = 0;
  while (getLine(line, MAX_SIZE, in, gz) != NULL) {

    if (line[0] == '@') {
      if (pastHeader)
        exit(error(line, ERRHEAD));
      checkHeader(line, chromLen, chrom, xcount, xchrList,
        xBedLen, xBed, ctrl, sortOpt, verbose);
      continue;
    }
    pastHeader = true;

    // parse SAM record
    qname = strtok(line, TAB);
    if (qname == NULL)
      exit(error(line, ERRSAM));
    if (! loadFields(&flag, &rname, &pos, &mapq, &cigar,
        &rnext, &pnext, &tlen, &seq, &qual, &extra))
      exit(error(qname, ERRSAM));

    count++;
    if (flag & 0x4) {
      // skip unmapped
      (*unmapped)++;
      continue;
    }
    if (! strcmp(qname, "*") || ! strcmp(rname, "*")
        || pos < 0)
      // insufficient alignment info
      exit(error(qname, ERRSAM));
    if (flag & 0xE00) {
      // skip supplementary/PCR dups/low quality
      (*supp)++;
      continue;
    }
    // find matching Chrom (reference sequence)
    Chrom* ref = NULL;
    for (int i = 0; i < *chromLen; i++)
      if (! strcmp((*chrom + i)->name, rname)) {
        ref = *chrom + i;
        break;
      }
    if (ref == NULL)
      // cannot find reference sequence
      exit(error(rname, ERRCHROM));
    if (mapq < minMapQ) {
      // skip low MAPQ alignments
      (*lowMapQ)++;
      continue;
    }

    // process previous set of alns, if starting a new set
    if (readName[0] == '\0' || strcmp(qname, readName)) {
      if (readName[0] != '\0')
        processAlns(readName, *aln, alnLen, totalLen,
          pairedPr, singlePr, orphan, singleOpt,
          extendOpt, extend, avgExtOpt, unpair,
          &unpairIdx, &unpairLen, unpairMem, asDiff,
          atacOpt, atacLen5, atacLen3, atacAdj,
          bed, bedOpt, gzOut, ctrl, sample, dupsOpt,
          readPr, &readIdxPr, &readLenPr, readMemPr,
          readDc, &readIdxDc, &readLenDc, readMemDc,
          readSn, &readIdxSn, &readLenSn, readMemSn,
          qualR1, qualR2, errCount, verbose);
      alnLen = 0;
      qualR1 = qualR2 = 0;
      strncpy(readName, qname, MAX_ALNS);
    }

    // save alignment information
    int length = calcDist(qname, seq, cigar); // distance to 3' end
    float score = getScore(extra);
    if (! parseAlign(aln, &alnLen, flag, ref, pos, length,
        pnext, paired, single, secPair, secSingle, skipped,
        singleOpt, score, dupsOpt, qual, strlen(qual),
        SAMQUAL, &qualR1, &qualR2) && verbose)
      fprintf(stderr, "Warning! Read %s has more than %d alignments\n",
        qname, MAX_ALNS);
    // NOTE: the following SAM fields are ignored:
    //   rnext, tlen
  }

  // process last set of alns
  if (readName[0] != '\0')
    processAlns(readName, *aln, alnLen, totalLen,
      pairedPr, singlePr, orphan, singleOpt,
      extendOpt, extend, avgExtOpt, unpair,
      &unpairIdx, &unpairLen, unpairMem, asDiff,
      atacOpt, atacLen5, atacLen3, atacAdj,
      bed, bedOpt, gzOut, ctrl, sample, dupsOpt,
      readPr, &readIdxPr, &readLenPr, readMemPr,
      readDc, &readIdxDc, &readLenDc, readMemDc,
      readSn, &readIdxSn, &readLenSn, readMemSn,
      qualR1, qualR2, errCount, verbose);

  if (dupsOpt)
    // remove duplicates and process all alignments
    findDups(*readPr, readIdxPr, readLenPr, *readDc,
      readIdxDc, readLenDc, *readSn, readIdxSn, readLenSn,
      table, tableMem, tableSn, tableSnMem, order, order0,
      order1, order2, qualA, qual0, qual1, qual2, arrMem,
      countPr, dupsPr, countDc, dupsDc, countSn, dupsSn,
      singleOpt, pairedPr, singlePr, totalLen, extendOpt,
      extend, avgExtOpt, asDiff, atacOpt, atacLen5,
      atacLen3, atacAdj, bed, bedOpt, gzOut, dups,
      dupsVerb, ctrl, sample, errCount, verbose);

  else if (avgExtOpt)
    // process single alignments w/ avgExtOpt
    processAvgExt(*unpair, unpairIdx, unpairLen,
      *totalLen, *pairedPr, bed, bedOpt, gzOut,
      ctrl, sample, errCount, verbose);

  return count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movss %xmm0, 0x20(%rsp)
movq %r9, 0x60(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r13
xorl %ecx, %ecx
leaq 0x14(%rsp), %rax
movl %ecx, (%rax)
leaq 0x40(%rsp), %rax
movl %ecx, (%rax)
leaq 0x3c(%rsp), %rax
movl %ecx, (%rax)
leaq 0x38(%rsp), %rax
movl %ecx, (%rax)
leaq 0x34(%rsp), %rax
movl %ecx, (%rax)
leaq 0x30(%rsp), %rax
movl %ecx, (%rax)
leaq 0x2c(%rsp), %rax
movl %ecx, (%rax)
leaq 0x28(%rsp), %rax
movl %ecx, (%rax)
leaq 0x24(%rsp), %rax
movl %ecx, (%rax)
leaq 0x4(%rsp), %rax
movw %cx, (%rax)
leaq 0x2(%rsp), %rax
movw %cx, (%rax)
movb 0x318(%rsp), %bpl
movl %ebp, %eax
xorb $0x1, %al
movb %al, 0x50(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
testb %r12b, %r12b
je 0xd094
movq %r13, %rdi
movq %r15, %rsi
movl $0xfff0, %edx           # imm = 0xFFF0
callq 0x2090
jmp 0xd0a4
movq %r15, %rdi
movl $0xfff0, %esi           # imm = 0xFFF0
movq %r13, %rdx
callq 0x21a0
testq %rax, %rax
je 0xd58b
cmpb $0x40, (%r15)
jne 0xd116
testb $0x1, %bl
jne 0xd97d
movzbl %bpl, %eax
movzbl 0x310(%rsp), %r10d
movzbl 0x218(%rsp), %r11d
movq %r15, %rdi
movq 0x1a0(%rsp), %rsi
movq 0x1a8(%rsp), %rdx
movl 0x168(%rsp), %ecx
movq 0x170(%rsp), %r8
movl 0x178(%rsp), %r9d
pushq %rax
pushq %r10
pushq %r11
pushq 0x198(%rsp)
callq 0xcb4f
addq $0x20, %rsp
jmp 0xd07d
movq %r15, %rdi
leaq 0x6a41(%rip), %rsi      # 0x13b61
callq 0x2280
testq %rax, %rax
je 0xd995
movq %rax, %rbx
subq $0x8, %rsp
leaq 0x4e(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x9c(%rsp), %rdx
leaq 0xf(%rsp), %rcx
leaq 0xd0(%rsp), %r8
leaq 0xe8(%rsp), %r9
leaq 0xb8(%rsp), %rax
pushq %rax
leaq 0xc8(%rsp), %rax
pushq %rax
leaq 0xd8(%rsp), %rax
pushq %rax
leaq 0xfc(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0xcc72
addq $0x30, %rsp
testb %al, %al
je 0xd98d
incq %r14
movzwl 0x46(%rsp), %ecx
testb $0x4, %cl
jne 0xd1ec
movq %rbx, 0x8(%rsp)
cmpb $0x2a, (%rbx)
jne 0xd1c3
movq 0x8(%rsp), %rax
cmpb $0x0, 0x1(%rax)
je 0xd99d
movq 0xd0(%rsp), %rbx
cmpb $0x2a, (%rbx)
jne 0xd1da
cmpb $0x0, 0x1(%rbx)
je 0xd99d
testl $0xe00, %ecx            # imm = 0xE00
je 0xd1fe
movq 0x148(%rsp), %rax
jmp 0xd1f4
movq 0x120(%rsp), %rax
incq (%rax)
movb $0x1, %bl
jmp 0xd07d
movl %ecx, 0x88(%rsp)
movq %r14, 0x58(%rsp)
movq 0x1a0(%rsp), %rax
movslq (%rax), %rbp
testq %rbp, %rbp
jle 0xd985
movq 0x1a8(%rsp), %rax
movq (%rax), %r14
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x21b0
testl %eax, %eax
je 0xd246
addq $0x68, %r14
decq %rbp
jne 0xd229
jmp 0xd985
movzbl 0x7(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0xd273
movq 0x158(%rsp), %rax
incq (%rax)
movb $0x1, %bl
movq 0x58(%rsp), %r14
movb 0x318(%rsp), %bpl
jmp 0xd07d
movq 0x48(%rsp), %rsi
cmpb $0x0, (%rsi)
movzbl 0x228(%rsp), %eax
movq %rax, 0x98(%rsp)
movzbl 0x1b0(%rsp), %ebp
je 0xd451
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x21b0
testl %eax, %eax
je 0xd47a
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movl 0x14(%rsp), %edx
movq %rbp, %r10
movzwl 0x4(%rsp), %ebp
movzwl 0x2(%rsp), %ebx
subq $0x8, %rsp
movzbl 0x320(%rsp), %eax
movzbl 0x220(%rsp), %r11d
movzbl 0x218(%rsp), %ecx
movq %rcx, 0xa8(%rsp)
movzbl 0x210(%rsp), %ecx
movq %rcx, 0xb0(%rsp)
movzbl 0x200(%rsp), %ecx
movq %rcx, 0x70(%rsp)
movzbl 0x1e8(%rsp), %ecx
movq %rcx, 0x78(%rsp)
movzbl 0x1d0(%rsp), %ecx
movq %rcx, 0x80(%rsp)
movzbl 0x1c0(%rsp), %ecx
movq %rcx, 0x88(%rsp)
movq 0x50(%rsp), %rdi
movq 0x68(%rsp), %rcx
movq 0x140(%rsp), %r8
movq 0x148(%rsp), %r9
movss 0x28(%rsp), %xmm0
pushq %rax
pushq 0x318(%rsp)
pushq %rbx
pushq %rbp
movq %r10, %rbp
pushq 0x290(%rsp)
leaq 0x54(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
pushq 0x2a0(%rsp)
pushq 0x2a0(%rsp)
leaq 0x7c(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
pushq 0x2b0(%rsp)
pushq 0x2b0(%rsp)
leaq 0xa4(%rsp), %rax
pushq %rax
leaq 0xb0(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq 0x120(%rsp)
movl 0x2b0(%rsp), %eax
pushq %rax
pushq %r11
pushq 0x140(%rsp)
pushq 0x150(%rsp)
pushq 0x2b0(%rsp)
pushq 0x120(%rsp)
movl 0x2b0(%rsp), %eax
pushq %rax
movl 0x2b0(%rsp), %eax
pushq %rax
pushq 0x140(%rsp)
pushq 0x2b0(%rsp)
leaq 0x11c(%rsp), %rax
pushq %rax
leaq 0x128(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq 0x170(%rsp)
movl 0x2c0(%rsp), %eax
pushq %rax
pushq 0x188(%rsp)
pushq %r10
pushq 0x2b0(%rsp)
callq 0x9f32
movq 0x168(%rsp), %rsi
addq $0x120, %rsp            # imm = 0x120
movl $0x0, 0x14(%rsp)
xorl %eax, %eax
movw %ax, 0x2(%rsp)
movw %ax, 0x4(%rsp)
movl $0x80, %edx
movq %rsi, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2050
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq %rbx, %rdi
callq 0xcf66
movl %eax, 0x78(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xcda3
movss %xmm0, 0x70(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x68(%rsp)
movl 0x90(%rsp), %eax
movq %rax, 0x80(%rsp)
movq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0x20f0
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
movl 0x90(%rsp), %edx
movq %r14, %rcx
movl 0x70(%rsp), %r8d
movl 0x80(%rsp), %r9d
movss 0x78(%rsp), %xmm0
leaq 0xa(%rsp), %r10
pushq %r10
leaq 0x14(%rsp), %r10
pushq %r10
pushq $0x21
pushq %rax
pushq %rbx
pushq 0xc8(%rsp)
pushq %rbp
pushq 0x190(%rsp)
pushq 0x1d8(%rsp)
pushq 0x1d8(%rsp)
pushq 0x188(%rsp)
pushq 0x188(%rsp)
pushq 0xe8(%rsp)
callq 0xc5c6
addq $0x70, %rsp
orb 0x50(%rsp), %al
movb $0x1, %bl
movq 0x58(%rsp), %r14
movb 0x318(%rsp), %bpl
jne 0xd07d
movq 0xca8d(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
leaq 0x6605(%rip), %rsi      # 0x13b7a
movq 0x8(%rsp), %rdx
movl $0x80, %ecx
xorl %eax, %eax
callq 0x21d0
jmp 0xd07d
movq 0x48(%rsp), %rdi
cmpb $0x0, (%rdi)
movb 0x228(%rsp), %cl
movq %r14, 0x58(%rsp)
je 0xd732
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movl 0x14(%rsp), %edx
movzwl 0x4(%rsp), %eax
movzwl 0x2(%rsp), %r10d
subq $0x8, %rsp
movzbl %bpl, %r11d
movl %ebp, %ebx
movzbl %cl, %ebp
movzbl 0x220(%rsp), %r13d
movzbl 0x218(%rsp), %r12d
movzbl 0x210(%rsp), %r15d
movzbl 0x200(%rsp), %r14d
movzbl 0x1e8(%rsp), %ecx
movq %rcx, 0x90(%rsp)
movzbl 0x1d0(%rsp), %ecx
movq %rcx, 0x10(%rsp)
movzbl 0x1c0(%rsp), %ecx
movq %rcx, 0x58(%rsp)
movzbl 0x1b8(%rsp), %ecx
movq %rcx, 0x20(%rsp)
movq 0x68(%rsp), %rcx
movq 0x140(%rsp), %r8
movq 0x148(%rsp), %r9
movss 0x28(%rsp), %xmm0
pushq %r11
pushq 0x318(%rsp)
pushq %r10
pushq %rax
pushq 0x290(%rsp)
leaq 0x54(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
pushq 0x2a0(%rsp)
pushq 0x2a0(%rsp)
leaq 0x7c(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
pushq 0x2b0(%rsp)
pushq 0x2b0(%rsp)
leaq 0xa4(%rsp), %rax
pushq %rax
leaq 0xb0(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq %rbp
movl %ebx, %ebp
movl 0x2b0(%rsp), %eax
pushq %rax
pushq %r13
pushq %r12
pushq %r15
pushq 0x2b0(%rsp)
pushq %r14
movq 0x118(%rsp), %r14
movl 0x2b0(%rsp), %eax
pushq %rax
movl 0x2b0(%rsp), %eax
pushq %rax
pushq 0x158(%rsp)
pushq 0x2b0(%rsp)
leaq 0x11c(%rsp), %rax
pushq %rax
leaq 0x128(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq 0x100(%rsp)
movl 0x2c0(%rsp), %eax
pushq %rax
pushq 0x158(%rsp)
pushq 0x128(%rsp)
pushq 0x2b0(%rsp)
callq 0x9f32
movb 0x348(%rsp), %cl
addq $0x120, %rsp            # imm = 0x120
testb %cl, %cl
je 0xd8ef
movq 0x240(%rsp), %rax
movq (%rax), %rdi
movl 0x38(%rsp), %esi
movl 0x34(%rsp), %edx
movq 0x250(%rsp), %rax
movq (%rax), %rcx
movl 0x30(%rsp), %r8d
movl 0x2c(%rsp), %r9d
movl 0x28(%rsp), %eax
movq %rax, 0x48(%rsp)
movl 0x24(%rsp), %eax
movq %rax, 0x18(%rsp)
movzbl %bpl, %eax
movzbl 0x218(%rsp), %r10d
movzbl 0x238(%rsp), %r11d
movzbl 0x210(%rsp), %ebp
movzbl 0x208(%rsp), %r13d
movzbl 0x1f8(%rsp), %r12d
movzbl 0x1e0(%rsp), %r15d
movzbl 0x1c8(%rsp), %r14d
movzbl 0x1b8(%rsp), %ebx
movq %rbx, 0x8(%rsp)
movzbl 0x1b0(%rsp), %ebx
movq %rbx, 0x50(%rsp)
movss 0x20(%rsp), %xmm0
pushq %rax
pushq 0x310(%rsp)
movl 0x230(%rsp), %eax
pushq %rax
pushq %r10
pushq %r11
pushq 0x258(%rsp)
pushq %rbp
pushq %r13
pushq 0x240(%rsp)
pushq %r12
movl 0x240(%rsp), %eax
pushq %rax
movl 0x240(%rsp), %eax
pushq %rax
pushq %r15
pushq %r14
movq 0xc8(%rsp), %r14
movl 0x230(%rsp), %eax
pushq %rax
pushq 0x80(%rsp)
pushq 0xe0(%rsp)
pushq 0x1c8(%rsp)
pushq 0x1c8(%rsp)
pushq 0xe8(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x3a0(%rsp)
pushq 0x150(%rsp)
pushq 0x188(%rsp)
movq 0x3a8(%rsp), %rax
pushq (%rax)
callq 0xbdaa
addq $0x150, %rsp            # imm = 0x150
jmp 0xd968
cmpb $0x0, 0x1c8(%rsp)
je 0xd968
movq 0x1d0(%rsp), %rax
movq (%rax), %rdi
movl 0x40(%rsp), %esi
movl 0x3c(%rsp), %edx
movq 0x60(%rsp), %rax
movsd (%rax), %xmm0
movq 0x138(%rsp), %rax
movq (%rax), %rcx
subq $0x8, %rsp
movzbl %bpl, %eax
movzbl 0x220(%rsp), %r10d
movzbl 0x218(%rsp), %r11d
movzbl 0x210(%rsp), %r9d
movq 0x208(%rsp), %r8
pushq %rax
pushq 0x318(%rsp)
movl 0x238(%rsp), %eax
pushq %rax
pushq %r10
pushq %r11
callq 0x8bff
addq $0x30, %rsp
movq %r14, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x304f
movq %rbx, %rdi
callq 0x301c
movq %rbx, %rdi
callq 0x300b
movq %r15, %rdi
callq 0x303e
movq 0x8(%rsp), %rdi
callq 0x302d