// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %r8, %r14
movq %rcx, -0x90(%rbp)
movq %rdx, -0x88(%rbp)
movq %rsi, %r13
movq %rdi, %rbx
movl $0x1, %esi
callq 0xd8bb
movl %eax, %edx
testl %eax, %eax
movq %rdx, -0x30(%rbp)
jle 0xe7f5
xorl %r12d, %r12d
movl (%rbx), %eax
testl %eax, %eax
je 0xe7c2
decl %eax
movl %eax, (%rbx)
incq 0x10(%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movzbl (%rax), %eax
jmp 0xe7ce
movq %rbx, %rdi
callq 0x20a0
movq -0x30(%rbp), %rdx
cmpl $-0x1, %eax
je 0xebca
testb %al, %al
je 0xe7f8
movzbl %al, %ecx
cmpl $0xa, %ecx
je 0xe7f8
movb %al, (%r13,%r12)
incq %r12
cmpq %r12, %rdx
jne 0xe7a3
movl %edx, %r12d
jmp 0xe7f8
xorl %r12d, %r12d
movq %r15, -0x78(%rbp)
movq %r14, -0x80(%rbp)
movl %r12d, %eax
movb $0x0, (%r13,%rax)
leaq 0x5351(%rip), %rsi      # 0x13b61
movq %r13, %rdi
callq 0x2280
testq %rax, %rax
je 0xebcf
leaq 0x5343(%rip), %rsi      # 0x13b6b
movq %rax, %rdi
callq 0x21b0
testl %eax, %eax
jne 0xebcf
leaq 0x5322(%rip), %rsi      # 0x13b61
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x2280
testq %rax, %rax
je 0xe888
movq %rax, %r15
xorl %r14d, %r14d
movl $0x3, %edx
movq %r15, %rdi
leaq 0x530c(%rip), %rsi      # 0x13b6f
callq 0x2060
addq $0x3, %r15
testl %eax, %eax
cmoveq %r15, %r14
xorl %edi, %edi
leaq 0x52e6(%rip), %rsi      # 0x13b61
callq 0x2280
movq %rax, %r15
testq %rax, %rax
jne 0xe854
cmpb $0x0, 0x1f8(%rbp)
je 0xe8b1
testq %r14, %r14
je 0xebd4
leaq 0x52d2(%rip), %rsi      # 0x13b73
movq %r14, %rdi
callq 0x21b0
testl %eax, %eax
jne 0xebd4
notl %r12d
addl -0x30(%rbp), %r12d
movslq %r12d, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2110
cmpq $-0x1, %rax
je 0xebd9
movb 0x200(%rbp), %r14b
movb 0x100(%rbp), %r15b
movq %rbx, %rdi
movl $0x1, %esi
callq 0xd8bb
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0x30(%rbp)
movq %rdx, %rsp
movzbl %r14b, %ecx
movq %rcx, -0x48(%rbp)
movzbl %r15b, %ecx
movq %rcx, -0x50(%rbp)
movq %rax, -0x70(%rbp)
testl %eax, %eax
jle 0xe9f0
xorl %r14d, %r14d
movq %rbx, %rdi
movl $0x1, %esi
callq 0xd8bb
leal -0xfff1(%rax), %ecx
cmpl $0xffff0010, %ecx       # imm = 0xFFFF0010
jb 0xebc0
movl %eax, %r15d
testl %eax, %eax
jle 0xe991
xorl %r12d, %r12d
movl (%rbx), %eax
testl %eax, %eax
je 0xe973
decl %eax
movl %eax, (%rbx)
incq 0x10(%rbx)
movq 0x8(%rbx), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%rbx)
movzbl (%rax), %eax
jmp 0xe97b
movq %rbx, %rdi
callq 0x20a0
cmpl $-0x1, %eax
je 0xebbb
movb %al, (%r13,%r12)
incq %r12
cmpq %r12, %r15
jne 0xe954
cmpb $0x0, -0x1(%r13,%r15)
jne 0xebc5
movq %rbx, %rdi
movl $0x1, %esi
callq 0xd8bb
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 0xc71f
addq $0x20, %rsp
movq -0x30(%rbp), %rcx
movl %eax, (%rcx,%r14,4)
incq %r14
cmpq -0x38(%rbp), %r14
jne 0xe92b
movb 0x120(%rbp), %r11b
movb 0x110(%rbp), %r10b
movb 0xf8(%rbp), %r12b
movb 0xf0(%rbp), %sil
movb 0xe0(%rbp), %dil
movb 0xc8(%rbp), %r14b
movb 0xb0(%rbp), %cl
movb 0xa0(%rbp), %al
movb 0x98(%rbp), %dl
movq 0x88(%rbp), %r8
movl (%r8), %r8d
movq 0x90(%rbp), %r9
movq (%r9), %r9
movzbl %r11b, %r15d
movzbl %r10b, %r11d
movzbl %r12b, %r10d
movzbl %sil, %r12d
movzbl %dil, %esi
movq %rsi, -0x58(%rbp)
movzbl %r14b, %r14d
movzbl %cl, %ecx
movq %rcx, -0x60(%rbp)
movzbl %al, %eax
movq %rax, -0x68(%rbp)
movzbl %dl, %eax
movq %rax, -0x38(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
movq -0x88(%rbp), %rdx
movq -0x90(%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), %eax
pushq %rax
pushq -0x50(%rbp)
pushq %r10
pushq %r12
pushq 0xe8(%rbp)
pushq -0x58(%rbp)
movl 0xd8(%rbp), %eax
pushq %rax
movl 0xd0(%rbp), %eax
pushq %rax
pushq %r14
pushq 0xc0(%rbp)
pushq 0xb8(%rbp)
pushq -0x60(%rbp)
movl 0xa8(%rbp), %eax
pushq %rax
pushq -0x68(%rbp)
pushq -0x38(%rbp)
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 -0x78(%rbp)
pushq -0x80(%rbp)
pushq -0x30(%rbp)
pushq -0x70(%rbp)
callq 0xde41
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x312c
callq 0x3144
callq 0x3114
callq 0x31a4
callq 0x318c
callq 0x3174
callq 0x315c