// File: /workspace/github_c_makefile_star2_O3/jsh58[P]Genrich/Genrich.c
// Function: saveAlnsPair
void saveAlnsPair(char* qname, Aln* aln, int alnLen,
    float score, float asDiff, Read* r, uint16_t qualR1,
    uint16_t qualR2) {
  // populate Read* struct
  r->name = (char*) memalloc(1 + strlen(qname));
  strcpy(r->name, qname);
  r->qual = MIN(qualR1 + qualR2, UINT16_MAX);
  r->score = score;

  // adjust AS tolerance for secondary alns
  if (score != NOSCORE)
    score -= asDiff;

  // determine number of valid paired alignments
  uint8_t count = 0;
  for (int i = 0; i < alnLen; i++) {
    Aln* a = aln + i;
    if (a->paired && a->full && a->score >= score)
      count++;
  }
  r->aln = (Aln*) memalloc(count * sizeof(Aln));
  r->alnLen = count;

  // copy alignment info for valid alignments
  uint8_t j = 0;  // index into r->aln
  for (int i = 0; i < alnLen; i++) {
    Aln* a = aln + i;
    if (a->paired && a->full && a->score >= score) {
      Aln* b = r->aln + j;
      b->paired = a->paired;
      b->full = a->full;
      b->score = a->score;
      b->chrom = a->chrom;
      // ensure positions are ordered
      if (a->pos[0] > a->pos[1]) {
        b->pos[0] = a->pos[1];
        b->pos[1] = a->pos[0];
      } else {
        b->pos[0] = a->pos[0];
        b->pos[1] = a->pos[1];
      }
      j++;
    }
  }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r12d
movl %r8d, %r15d
movq %rcx, %r14
movss %xmm1, (%rsp)
movaps %xmm0, 0x10(%rsp)
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r13
callq 0x20f0
leaq 0x1(%rax), %rdi
callq 0x3913
movq %rax, (%r14)
movq %rax, %rdi
movq %r13, %rsi
callq 0x2070
addl %r12d, %r15d
movl $0xffff, %eax           # imm = 0xFFFF
cmpl %eax, %r15d
cmovael %eax, %r15d
movw %r15w, 0x22(%r14)
movaps 0x10(%rsp), %xmm2
movss %xmm2, 0x28(%r14)
movaps %xmm2, %xmm0
subss (%rsp), %xmm0
movss 0x8c4c(%rip), %xmm1     # 0x12174
cmpneqss %xmm2, %xmm1
andps %xmm1, %xmm0
andnps %xmm2, %xmm1
orps %xmm0, %xmm1
movl %ebp, %r15d
testl %ebp, %ebp
jle 0x9573
leaq (,%r15,8), %rax
leaq (%rax,%rax,4), %rcx
xorl %edx, %edx
xorl %eax, %eax
cmpb $0x1, 0xd(%rbx,%rdx)
jne 0x9568
cmpb $0x1, 0xe(%rbx,%rdx)
jne 0x9568
movss 0x8(%rbx,%rdx), %xmm0
ucomiss %xmm1, %xmm0
jb 0x9568
incb %al
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0x954d
jmp 0x9575
xorl %eax, %eax
movzbl %al, %r12d
leal (,%r12,8), %eax
leaq (%rax,%rax,4), %rdi
movaps %xmm1, (%rsp)
callq 0x3913
movaps (%rsp), %xmm1
movq %rax, 0x8(%r14)
movb %r12b, 0x10(%r14)
testl %ebp, %ebp
jle 0x9616
shlq $0x3, %r15
leaq (%r15,%r15,4), %rcx
xorl %edx, %edx
xorl %esi, %esi
cmpb $0x1, 0xd(%rbx,%rdx)
jne 0x960d
movb 0xe(%rbx,%rdx), %dil
cmpb $0x1, %dil
jne 0x960d
movss 0x8(%rbx,%rdx), %xmm0
ucomiss %xmm1, %xmm0
jb 0x960d
movzbl %sil, %esi
leaq (%rsi,%rsi,4), %r8
movb $0x1, 0xd(%rax,%r8,8)
movb %dil, 0xe(%rax,%r8,8)
movss %xmm0, 0x8(%rax,%r8,8)
movq 0x20(%rbx,%rdx), %rdi
movq %rdi, 0x20(%rax,%r8,8)
movl (%rbx,%rdx), %edi
movl 0x4(%rbx,%rdx), %r9d
cmpl %r9d, %edi
movl %r9d, %r10d
cmovbl %edi, %r10d
cmoval %edi, %r9d
movl %r10d, (%rax,%r8,8)
movl %r9d, 0x4(%rax,%r8,8)
incb %sil
addq $0x28, %rdx
cmpq %rdx, %rcx
jne 0x95aa
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq