// File: /workspace/github_c_makefile_star2_O3/jsh58[P]Genrich/Genrich.c
// Function: parseAlign
bool parseAlign(Aln** aln, int* alnLen, uint16_t flag,
    Chrom* chrom, uint32_t pos, int length, uint32_t pnext,
    uint64_t* paired, uint64_t* single, uint64_t* secPair,
    uint64_t* secSingle, uint64_t* skipped, bool singleOpt,
    float score, bool dupsOpt, char* qual, int qualLen,
    int offset, uint16_t* qualR1, uint16_t* qualR2) {

  // check for linear template or missing index
  if (flag & 0x1) {
    if ((flag & 0xC0) == 0xC0)
      exit(error("", ERRLINEAR));
    if (!(flag & 0xC0))
      exit(error("", ERRINDEX));
  }

  // save sum of quality scores (only if removing dups)
  if (dupsOpt) {
    if (flag & 0x40) {
      if (! *qualR1 && strcmp(qual, "*"))
        *qualR1 = sumQual(qual, qualLen, offset);
    } else {
      if (! *qualR2 && strcmp(qual, "*"))
        *qualR2 = sumQual(qual, qualLen, offset);
    }
  }

  // paired alignment: save alignment information
  if ((flag & 0x3) == 0x3) {

    // update counts
    if (chrom->skip || ! chrom->save)
      (*skipped)++;
    else {
      (*paired)++;
      if (flag & 0x100)
        (*secPair)++;
    }

    // search for matching paired alignment (already analyzed)
    for (int i = 0; i < *alnLen; i++) {
      Aln* a = *aln + i;
      if ( a->paired && ! a->full && a->chrom == chrom
          && (flag & 0x40 ? (! a->first && a->pos[0] == pos)
            : (a->first && a->pos[1] == pos) )
          && (flag & 0x100 ? ! a->primary : a->primary) ) {
        // complete paired alignment
        updatePairedAln(a, flag, pos, length, score);
        return true;
      }
    }

    // not found: start new paired alignment
    return savePairedAln(aln, alnLen, flag, chrom,
      pos, length, pnext, score);
  }

  // unpaired alignment
  if (chrom->skip || ! chrom->save)
    (*skipped)++;
  else {
    (*single)++;
    if (flag & 0x100)
      (*secSingle)++;
  }

  // save alignment info
  if (singleOpt)
    return saveSingleAln(aln, alnLen, flag, chrom,
      pos, length, score);

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x8(%rsp)
movq %rcx, %r15
movl %edx, %ecx
movq 0xc0(%rsp), %rax
movq 0xb8(%rsp), %r9
movl 0xb0(%rsp), %ebp
movl 0xa8(%rsp), %ebx
movq 0xa0(%rsp), %r13
movb 0x98(%rsp), %r14b
movb 0x90(%rsp), %r11b
movq 0x88(%rsp), %r10
movq 0x80(%rsp), %rdx
movq %rdx, 0x20(%rsp)
movq 0x78(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movq 0x70(%rsp), %rdx
movq %rdx, 0x10(%rsp)
movq 0x68(%rsp), %r12
movl 0x60(%rsp), %edx
movl %edx, 0xc(%rsp)
testb $0x1, %cl
je 0xc66c
testb $-0x40, %cl
je 0xc855
movl %ecx, %edx
andl $0xc0, %edx
cmpl $0xc0, %edx
je 0xc85a
testb %r14b, %r14b
je 0xc6f9
testb $0x40, %cl
jne 0xc6ae
cmpw $0x0, (%rax)
jne 0xc6f9
cmpb $0x2a, (%r13)
jne 0xc68e
cmpb $0x0, 0x1(%r13)
je 0xc6f9
testl %ebx, %ebx
jle 0xc6e2
movl %ebx, %r9d
xorl %r14d, %r14d
xorl %ebx, %ebx
movsbl (%r13,%r14), %edx
subl %ebp, %ebx
addl %edx, %ebx
incq %r14
cmpq %r14, %r9
jne 0xc69a
jmp 0xc6e4
cmpw $0x0, (%r9)
jne 0xc6f9
cmpb $0x2a, (%r13)
jne 0xc6c3
cmpb $0x0, 0x1(%r13)
je 0xc6f9
testl %ebx, %ebx
jle 0xc6e9
movl %ebx, %eax
xorl %r14d, %r14d
xorl %ebx, %ebx
movsbl (%r13,%r14), %edx
subl %ebp, %ebx
addl %edx, %ebx
incq %r14
cmpq %r14, %rax
jne 0xc6ce
jmp 0xc6eb
xorl %ebx, %ebx
movq %rax, %r9
jmp 0xc6eb
xorl %ebx, %ebx
movl $0xffff, %eax           # imm = 0xFFFF
cmpl %eax, %ebx
cmovll %ebx, %eax
movw %ax, (%r9)
movl %ecx, %edx
notl %edx
movb 0xc(%r15), %al
testb $0x3, %dl
jne 0xc7b1
testb %al, %al
jne 0xc724
cmpb $0x1, 0xd(%r15)
jne 0xc724
incq (%r12)
btl $0x8, %ecx
movq 0x18(%rsp), %r10
jae 0xc727
incq (%r10)
movslq (%rsi), %rax
testq %rax, %rax
jle 0xc7f5
movq (%rdi), %r10
shlq $0x3, %rax
leaq (%rax,%rax,4), %r9
xorl %eax, %eax
cmpb $0x1, 0xd(%r10,%rax)
jne 0xc757
cmpb $0x0, 0xe(%r10,%rax)
jne 0xc757
cmpq %r15, 0x20(%r10,%rax)
je 0xc765
addq $0x28, %rax
cmpq %rax, %r9
jne 0xc740
jmp 0xc7f5
movb 0xf(%r10,%rax), %r11b
testb $0x40, %cl
jne 0xc77d
testb %r11b, %r11b
je 0xc757
cmpl %r8d, 0x4(%r10,%rax)
jne 0xc757
jmp 0xc788
testb %r11b, %r11b
jne 0xc757
cmpl %r8d, (%r10,%rax)
jne 0xc757
btl $0x8, %ecx
setae %dl
xorb 0xc(%r10,%rax), %dl
jne 0xc757
movl %ecx, %edx
shll $0x1b, %edx
sarl $0x1f, %edx
andl 0x8(%rsp), %edx
addl %r8d, %edx
testb $0x40, %cl
jne 0xc80e
movl %edx, 0x4(%r10,%rax)
jmp 0xc812
testb %al, %al
jne 0xc7cf
cmpb $0x1, 0xd(%r15)
jne 0xc7cf
movq 0x10(%rsp), %rax
incq (%rax)
btl $0x8, %ecx
movq 0x20(%rsp), %r10
jae 0xc7d2
incq (%r10)
testb %r11b, %r11b
je 0xc844
movzwl %cx, %edx
movq %r15, %rcx
movl 0x8(%rsp), %r9d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc53f
movl 0xc(%rsp), %eax
movl %eax, (%rsp)
movzwl %cx, %edx
movq %r15, %rcx
movl 0x8(%rsp), %r9d
callq 0xc4cd
jmp 0xc846
movl %edx, (%r10,%rax)
movss 0x595a(%rip), %xmm1     # 0x12174
ucomiss %xmm1, %xmm0
jne 0xc821
jnp 0xc837
movss 0x8(%r10,%rax), %xmm1
ucomiss 0x5945(%rip), %xmm1     # 0x12174
jne 0xc833
jnp 0xc83e
addss %xmm0, %xmm1
movss %xmm1, 0x8(%r10,%rax)
movb $0x1, 0xe(%r10,%rax)
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2f75
callq 0x2f8d