// File: /workspace/github_c_makefile_star2_O1/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, 0x28(%rsp)
movq %r9, 0x68(%rsp)
movq %r8, 0x20(%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 0x48(%rsp), %rax
movl %ecx, (%rax)
leaq 0x44(%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 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 0xcf8a
movq %r13, %rdi
movq %r15, %rsi
movl $0xfff0, %edx           # imm = 0xFFF0
callq 0x2090
jmp 0xcf9a
movq %r15, %rdi
movl $0xfff0, %esi           # imm = 0xFFF0
movq %r13, %rdx
callq 0x21a0
testq %rax, %rax
je 0xd49d
cmpb $0x40, (%r15)
jne 0xd00c
testb $0x1, %bl
jne 0xd88f
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 0xca4b
addq $0x20, %rsp
jmp 0xcf73
movq %r15, %rdi
leaq 0x6b4b(%rip), %rsi      # 0x13b61
callq 0x2280
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0xd8ab
subq $0x8, %rsp
leaq 0x56(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x94(%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 0xb0(%rsp), %rax
pushq %rax
callq 0xcb7c
addq $0x30, %rsp
testb %al, %al
leaq 0x6421(%rip), %rbx      # 0x134b7
je 0xd897
incq %r14
movzwl 0x4e(%rsp), %eax
testb $0x4, %al
jne 0xd0f0
movl %eax, 0x60(%rsp)
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x21b0
testl %eax, %eax
je 0xd8a1
movq %rbx, %rsi
movq 0xd0(%rsp), %rbx
movq %rbx, %rdi
callq 0x21b0
testl %eax, %eax
je 0xd8a1
testl $0xe00, 0x60(%rsp)      # imm = 0xE00
je 0xd102
movq 0x148(%rsp), %rax
jmp 0xd0f8
movq 0x120(%rsp), %rax
incq (%rax)
movb $0x1, %bl
jmp 0xcf73
movq %r14, 0x58(%rsp)
movq 0x1a0(%rsp), %rax
movslq (%rax), %rbp
testq %rbp, %rbp
jle 0xd13a
movq 0x1a8(%rsp), %rax
movq (%rax), %r14
movq (%r14), %rdi
movq %rbx, %rsi
callq 0x21b0
testl %eax, %eax
je 0xd13d
addq $0x68, %r14
decq %rbp
jne 0xd122
xorl %r14d, %r14d
movb 0x228(%rsp), %cl
testq %r14, %r14
movq 0x8(%rsp), %rbp
je 0xd8b3
movzbl 0x7(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0xd17f
movq 0x158(%rsp), %rax
incq (%rax)
movb $0x1, %bl
movq 0x58(%rsp), %r14
movb 0x318(%rsp), %bpl
jmp 0xcf73
movq 0x20(%rsp), %rsi
movb (%rsi), %bl
movzbl %cl, %eax
movq %rax, 0x90(%rsp)
movzbl 0x1b0(%rsp), %eax
movq %rax, 0x98(%rsp)
testb %bl, %bl
je 0xd367
movq %rbp, %rdi
callq 0x21b0
testl %eax, %eax
je 0xd38b
testb %bl, %bl
movq 0x20(%rsp), %rsi
je 0xd367
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movl 0x14(%rsp), %edx
movzwl 0x4(%rsp), %ebp
movzwl 0x2(%rsp), %ebx
subq $0x8, %rsp
movzbl 0x320(%rsp), %eax
movzbl 0x220(%rsp), %r11d
movzbl 0x218(%rsp), %r10d
movzbl 0x210(%rsp), %ecx
movq %rcx, 0xa8(%rsp)
movzbl 0x200(%rsp), %ecx
movq %rcx, 0xb0(%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 0x28(%rsp), %rdi
movq 0x70(%rsp), %rcx
movq 0x140(%rsp), %r8
movq 0x148(%rsp), %r9
movss 0x30(%rsp), %xmm0
pushq %rax
pushq 0x318(%rsp)
pushq %rbx
pushq %rbp
movq 0x30(%rsp), %rbp
pushq 0x290(%rsp)
leaq 0x5c(%rsp), %rax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
pushq 0x2a0(%rsp)
pushq 0x2a0(%rsp)
leaq 0x84(%rsp), %rax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
pushq 0x2b0(%rsp)
pushq 0x2b0(%rsp)
leaq 0xac(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq 0x118(%rsp)
movl 0x2b0(%rsp), %eax
pushq %rax
pushq %r11
pushq %r10
pushq 0x148(%rsp)
pushq 0x2b0(%rsp)
pushq 0x160(%rsp)
movl 0x2b0(%rsp), %eax
pushq %rax
movl 0x2b0(%rsp), %eax
pushq %rax
pushq 0x140(%rsp)
pushq 0x2b0(%rsp)
leaq 0x124(%rsp), %rax
pushq %rax
leaq 0x130(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq 0x170(%rsp)
movl 0x2c0(%rsp), %eax
pushq %rax
pushq 0x188(%rsp)
pushq 0x1a8(%rsp)
pushq 0x2b0(%rsp)
callq 0x9d9a
movq 0x140(%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 %rbp, %rsi
callq 0x2050
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq %rbp, %rdi
callq 0xce4d
movl %eax, 0x80(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xccb8
movss %xmm0, 0x78(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x70(%rsp)
movl 0x88(%rsp), %eax
movq %rax, 0x8(%rsp)
movq 0xb8(%rsp), %rbx
movq %rbx, %rdi
callq 0x20f0
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
movl 0x68(%rsp), %edx
movq %r14, %rcx
movl 0x78(%rsp), %r8d
movl 0x88(%rsp), %r9d
movss 0x80(%rsp), %xmm0
leaq 0xa(%rsp), %r10
pushq %r10
leaq 0x14(%rsp), %r10
pushq %r10
pushq $0x21
pushq %rax
pushq %rbx
pushq 0xc0(%rsp)
pushq 0xd0(%rsp)
pushq 0x190(%rsp)
pushq 0x1d8(%rsp)
pushq 0x1d8(%rsp)
pushq 0x188(%rsp)
pushq 0x188(%rsp)
pushq 0x70(%rsp)
callq 0xc396
addq $0x70, %rsp
orb 0x50(%rsp), %al
movb $0x1, %bl
movq 0x58(%rsp), %r14
movq %rbp, %rdx
movb 0x318(%rsp), %bpl
jne 0xcf73
movq 0xcb76(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
leaq 0x66f8(%rip), %rsi      # 0x13b84
movl $0x80, %ecx
xorl %eax, %eax
callq 0x21d0
jmp 0xcf73
movq 0x20(%rsp), %rdi
cmpb $0x0, (%rdi)
movb 0x228(%rsp), %cl
movq %r14, 0x58(%rsp)
je 0xd644
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, 0x68(%rsp)
movzbl 0x1d0(%rsp), %ecx
movq %rcx, 0x58(%rsp)
movzbl 0x1c0(%rsp), %ecx
movq %rcx, 0x10(%rsp)
movzbl 0x1b8(%rsp), %ecx
movq %rcx, 0x20(%rsp)
movq 0x70(%rsp), %rcx
movq 0x140(%rsp), %r8
movq 0x148(%rsp), %r9
movss 0x30(%rsp), %xmm0
pushq %r11
pushq 0x318(%rsp)
pushq %r10
pushq %rax
pushq 0x290(%rsp)
leaq 0x5c(%rsp), %rax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
pushq 0x2a0(%rsp)
pushq 0x2a0(%rsp)
leaq 0x84(%rsp), %rax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
pushq 0x2b0(%rsp)
pushq 0x2b0(%rsp)
leaq 0xac(%rsp), %rax
pushq %rax
leaq 0xb8(%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 0x130(%rsp)
pushq 0x2b0(%rsp)
leaq 0x124(%rsp), %rax
pushq %rax
leaq 0x130(%rsp), %rax
pushq %rax
pushq 0x2c0(%rsp)
pushq 0x148(%rsp)
movl 0x2c0(%rsp), %eax
pushq %rax
pushq 0x110(%rsp)
pushq 0x128(%rsp)
pushq 0x2b0(%rsp)
callq 0x9d9a
movb 0x348(%rsp), %cl
addq $0x120, %rsp            # imm = 0x120
testb %cl, %cl
je 0xd801
movq 0x240(%rsp), %rax
movq (%rax), %rdi
movl 0x40(%rsp), %esi
movl 0x3c(%rsp), %edx
movq 0x250(%rsp), %rax
movq (%rax), %rcx
movl 0x38(%rsp), %r8d
movl 0x34(%rsp), %r9d
movl 0x30(%rsp), %eax
movq %rax, 0x20(%rsp)
movl 0x2c(%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, 0x50(%rsp)
movzbl 0x1b0(%rsp), %ebx
movq %rbx, 0x8(%rsp)
movss 0x28(%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 0xc8(%rsp)
pushq 0xe8(%rsp)
pushq 0x1c8(%rsp)
pushq 0x1c8(%rsp)
pushq 0xa0(%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 0x160(%rsp)
movq 0x3a8(%rsp), %rax
pushq (%rax)
callq 0xbb44
addq $0x150, %rsp            # imm = 0x150
jmp 0xd87a
cmpb $0x0, 0x1c8(%rsp)
je 0xd87a
movq 0x1d0(%rsp), %rax
movq (%rax), %rdi
movl 0x48(%rsp), %esi
movl 0x44(%rsp), %edx
movq 0x68(%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 0x8b22
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 0x3029
movq 0x8(%rsp), %rdi
callq 0x2fe5
movq 0x8(%rsp), %rdi
callq 0x3007
movq %r15, %rdi
callq 0x3018
movq %rbx, %rdi
callq 0x2ff6