// File: /workspace/github_c_makefile_star2_O2/jsh58[P]Genrich/Genrich.c
// Function: readBAM
uint64_t readBAM(gzFile in, 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** qual, 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) {

  // load first line from header
  int32_t l_text = readInt32(in, true);
  int i;
  for (i = 0; i < l_text; i++) {
    int m = gzgetc(in);
    if (m == -1)
      exit(error("", ERRBAM));
    unsigned char n = m;
    if (n == '\n' || n == '\0')
      break;
    line[i] = n;
  }
  line[i] = '\0';
  // check sort order
  char* tag = strtok(line, TAB);
  if (tag == NULL || strcmp(tag, "@HD"))
    exit(error("", ERRBAM));
  char* sortOrder = NULL;
  char* field = strtok(NULL, TAB);
  while (field != NULL) {
    if (!strncmp(field, "SO:", 3))
      sortOrder = field + 3;
    field = strtok(NULL, TAB);
  }
  if (sortOpt && (sortOrder == NULL
      || strcmp(sortOrder, "queryname")))
    exit(error("", ERRSORT));
  if (gzseek(in, l_text - i - 1, SEEK_CUR) == -1)
    exit(error("", ERRBAM));

  // save chromosome lengths
  int32_t n_ref = readInt32(in, true); // number of ref sequences
  int idx[n_ref];  // index of reference sequences into *chrom array
  for (int i = 0; i < n_ref; i++) {
    int32_t len = readInt32(in, true);
    if (len < 1 || len > MAX_SIZE)
      exit(error("", ERRBAM));
    for (int j = 0; j < len; j++) {
      int m = gzgetc(in);
      if (m == -1)
        exit(error("", ERRBAM));
      line[j] = m;
    }
    if (line[len-1] != '\0')
      exit(error("", ERRBAM));
    idx[i] = saveChrom(line, (uint32_t) readInt32(in, true),
      chromLen, chrom, xcount, xchrList, xBedLen, xBed,
      ctrl, verbose);
  }

  return parseBAM(in, line, aln, readName, *chromLen,
    *chrom, n_ref, idx, totalLen, unmapped, paired, single,
    pairedPr, singlePr, supp, skipped, lowMapQ, minMapQ,
    secPair, secSingle, orphan, singleOpt, extendOpt,
    extend, avgExtOpt, unpair, unpairMem, asDiff, atacOpt,
    atacLen5, atacLen3, atacAdj, bed, bedOpt, gzOut, ctrl,
    sample, dupsOpt, dups, dupsVerb, readPr, readMemPr,
    readDc, readMemDc, readSn, readMemSn, table, tableMem,
    tableSn, tableSnMem, order, order0, order1, order2,
    qual, qual0, qual1, qual2, arrMem, countPr, dupsPr,
    countDc, dupsDc, countSn, dupsSn, errCount, verbose);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movss %xmm0, -0x3c(%rbp)
movq %r9, -0x88(%rbp)
movq %r8, %r12
movq %rcx, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
movq %rsi, %r13
movq %rdi, %rbx
pushq $0x1
popq %rsi
callq 0xc185
xorl %r15d, %r15d
testl %eax, %eax
movl $0x0, %r14d
movl %eax, -0x30(%rbp)
cmovgl %eax, %r14d
cmpq %r15, %r14
je 0xcfd9
movl (%rbx), %eax
testl %eax, %eax
je 0xcfaf
decl %eax
movl %eax, (%rbx)
incq 0x10(%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movzbl (%rax), %eax
jmp 0xcfc0
movq %rbx, %rdi
callq 0x20a0
cmpl $-0x1, %eax
je 0xd362
testb %al, %al
je 0xcfd6
movzbl %al, %ecx
cmpl $0xa, %ecx
je 0xcfd6
movb %al, (%r13,%r15)
incq %r15
jmp 0xcf8b
movl %r15d, %r14d
movq %r12, -0x70(%rbp)
movl %r14d, %eax
movb $0x0, (%r13,%rax)
leaq 0x4ac4(%rip), %rsi      # 0x11ab1
movq %r13, %rdi
callq 0x2280
testq %rax, %rax
je 0xd362
leaq 0x4aae(%rip), %rsi      # 0x11ab3
movq %rax, %rdi
callq 0x21a0
testl %eax, %eax
jne 0xd362
xorl %r15d, %r15d
leaq 0x4a92(%rip), %r12      # 0x11ab1
xorl %edi, %edi
movq %r12, %rsi
callq 0x2280
testq %rax, %rax
je 0xd04a
cmpb $0x53, (%rax)
jne 0xd01f
cmpb $0x4f, 0x1(%rax)
jne 0xd01f
movq %rax, %rcx
addq $0x3, %rcx
cmpb $0x3a, 0x2(%rax)
cmoveq %rcx, %r15
jmp 0xd01f
cmpb $0x0, 0x1f8(%rbp)
je 0xd073
testq %r15, %r15
je 0xd379
leaq 0x4a54(%rip), %rsi      # 0x11ab7
movq %r15, %rdi
callq 0x21a0
testl %eax, %eax
jne 0xd379
notl %r14d
movl -0x30(%rbp), %eax
addl %r14d, %eax
movslq %eax, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x2110
cmpq $-0x1, %rax
je 0xd362
pushq $0x1
popq %r14
movq %rbx, %rdi
movl %r14d, %esi
callq 0xc185
movl %eax, %ecx
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0x58(%rbp)
movq %rdx, %rsp
xorl %ecx, %ecx
testl %eax, %eax
movq %rax, -0x68(%rbp)
cmovlel %ecx, %eax
movq %rax, -0x38(%rbp)
movzbl 0x200(%rbp), %eax
movq %rax, -0x48(%rbp)
movzbl 0x100(%rbp), %eax
movq %rax, -0x50(%rbp)
cmpq -0x38(%rbp), %rcx
je 0xd1b7
movq %rcx, -0x30(%rbp)
movq %rbx, %rdi
movl %r14d, %r15d
movl %r14d, %esi
callq 0xc185
leal -0xfff1(%rax), %ecx
cmpl $0xffff0010, %ecx       # imm = 0xFFFF0010
jb 0xd362
movl %eax, %r14d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0xd156
movl (%rbx), %eax
testl %eax, %eax
je 0xd13b
decl %eax
movl %eax, (%rbx)
incq 0x10(%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movzbl (%rax), %eax
jmp 0xd14c
movq %rbx, %rdi
callq 0x20a0
cmpl $-0x1, %eax
je 0xd362
movb %al, (%r13,%r12)
incq %r12
jmp 0xd117
cmpb $0x0, -0x1(%r13,%r14)
jne 0xd362
movq %rbx, %rdi
movl %r15d, %r14d
movl %r15d, %esi
callq 0xc185
movq %r13, %rdi
movl %eax, %esi
movq 0x88(%rbp), %rdx
movq 0x90(%rbp), %rcx
movl 0x50(%rbp), %r8d
movq 0x58(%rbp), %r9
pushq -0x48(%rbp)
pushq -0x50(%rbp)
pushq 0x68(%rbp)
movl 0x60(%rbp), %eax
pushq %rax
callq 0xb12f
addq $0x20, %rsp
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rdx
movl %eax, (%rcx,%rdx,4)
movq %rdx, %rcx
incq %rcx
jmp 0xd0e3
movq 0x88(%rbp), %rax
movl (%rax), %r8d
movq 0x90(%rbp), %rax
movq (%rax), %r9
movzbl 0x120(%rbp), %r15d
movzbl 0x110(%rbp), %r11d
movzbl 0xf8(%rbp), %r10d
movzbl 0xf0(%rbp), %eax
movzbl 0xe0(%rbp), %r12d
movzbl 0xc8(%rbp), %ecx
movq %rcx, -0x60(%rbp)
movzbl 0xb0(%rbp), %ecx
movq %rcx, -0x38(%rbp)
movzbl 0xa0(%rbp), %ecx
movq %rcx, -0x30(%rbp)
movzbl 0x98(%rbp), %r14d
movq %rbx, %rdi
movq %r13, %rsi
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rcx
movss -0x3c(%rbp), %xmm0
pushq -0x48(%rbp)
pushq 0x1f0(%rbp)
pushq 0x1e8(%rbp)
pushq 0x1e0(%rbp)
pushq 0x1d8(%rbp)
pushq 0x1d0(%rbp)
pushq 0x1c8(%rbp)
pushq 0x1c0(%rbp)
pushq 0x1b8(%rbp)
pushq 0x1b0(%rbp)
pushq 0x1a8(%rbp)
pushq 0x1a0(%rbp)
pushq 0x198(%rbp)
pushq 0x190(%rbp)
pushq 0x188(%rbp)
pushq 0x180(%rbp)
pushq 0x178(%rbp)
pushq 0x170(%rbp)
pushq 0x168(%rbp)
pushq 0x160(%rbp)
pushq 0x158(%rbp)
pushq 0x150(%rbp)
pushq 0x148(%rbp)
pushq 0x140(%rbp)
pushq 0x138(%rbp)
pushq 0x130(%rbp)
pushq 0x128(%rbp)
pushq %r15
pushq 0x118(%rbp)
pushq %r11
movl 0x108(%rbp), %r11d
pushq %r11
pushq -0x50(%rbp)
pushq %r10
pushq %rax
pushq 0xe8(%rbp)
pushq %r12
movl 0xd8(%rbp), %eax
pushq %rax
movl 0xd0(%rbp), %eax
pushq %rax
pushq -0x60(%rbp)
pushq 0xc0(%rbp)
pushq 0xb8(%rbp)
pushq -0x38(%rbp)
movl 0xa8(%rbp), %eax
pushq %rax
pushq -0x30(%rbp)
pushq %r14
pushq 0x80(%rbp)
pushq 0x78(%rbp)
pushq 0x70(%rbp)
movl 0x48(%rbp), %eax
pushq %rax
pushq 0x40(%rbp)
pushq 0x38(%rbp)
pushq 0x30(%rbp)
pushq 0x28(%rbp)
pushq 0x20(%rbp)
pushq 0x18(%rbp)
pushq 0x10(%rbp)
pushq -0x88(%rbp)
pushq -0x70(%rbp)
pushq -0x58(%rbp)
pushq -0x68(%rbp)
callq 0xc675
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x47a6(%rip), %rdi      # 0x11b0f
pushq $0x13
popq %rsi
callq 0x2724
pushq $0x1
popq %rdi
callq 0x22a0
leaq 0x478f(%rip), %rdi      # 0x11b0f
pushq $0x19
jmp 0xd36b