// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x78, %rsp
movl %r8d, 0x4(%rsp)
movq %rcx, %rax
movl 0x4(%rsp), %ecx
movq %rax, 0x8(%rsp)
movl %edx, %eax
movq 0x8(%rsp), %rdx
movl %eax, 0x14(%rsp)
movq %rsi, %rax
movl 0x14(%rsp), %esi
movq %rax, 0x18(%rsp)
movq %rdi, %r8
movq 0x18(%rsp), %rdi
movw %r9w, %ax
movq %r8, 0x70(%rsp)
movq %rdi, 0x68(%rsp)
movl %esi, 0x64(%rsp)
movss %xmm0, 0x60(%rsp)
movss %xmm1, 0x5c(%rsp)
movq %rdx, 0x50(%rsp)
movw %cx, 0x4e(%rsp)
movw %ax, 0x4c(%rsp)
movq 0x70(%rsp), %rdi
callq 0x20f0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x2890
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, (%rax)
movq 0x50(%rsp), %rax
movq (%rax), %rdi
movq 0x70(%rsp), %rsi
callq 0x2070
movzwl 0x4e(%rsp), %eax
movzwl 0x4c(%rsp), %ecx
addl %ecx, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jge 0xd118
movzwl 0x4e(%rsp), %eax
movzwl 0x4c(%rsp), %ecx
addl %ecx, %eax
movl %eax, (%rsp)
jmp 0xd122
movl $0xffff, %eax           # imm = 0xFFFF
movl %eax, (%rsp)
jmp 0xd122
movl (%rsp), %eax
movw %ax, %cx
movq 0x50(%rsp), %rax
movw %cx, 0x22(%rax)
movss 0x60(%rsp), %xmm0
movq 0x50(%rsp), %rax
movss %xmm0, 0x28(%rax)
movss 0x60(%rsp), %xmm0
movss 0x11065(%rip), %xmm1    # 0x1e1b4
ucomiss %xmm1, %xmm0
jne 0xd158
jp 0xd158
jmp 0xd16e
movss 0x5c(%rsp), %xmm1
movss 0x60(%rsp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, 0x60(%rsp)
movb $0x0, 0x4b(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x64(%rsp), %eax
jge 0xd1db
movq 0x68(%rsp), %rax
movslq 0x44(%rsp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
testb $0x1, 0xd(%rax)
je 0xd1cc
movq 0x38(%rsp), %rax
testb $0x1, 0xe(%rax)
je 0xd1cc
movq 0x38(%rsp), %rax
movss 0x8(%rax), %xmm0
ucomiss 0x60(%rsp), %xmm0
jb 0xd1cc
movb 0x4b(%rsp), %al
addb $0x1, %al
movb %al, 0x4b(%rsp)
jmp 0xd1ce
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xd17b
movzbl 0x4b(%rsp), %eax
imulq $0x28, %rax, %rdi
callq 0x2890
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x8(%rax)
movb 0x4b(%rsp), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x10(%rax)
movb $0x0, 0x37(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x64(%rsp), %eax
jge 0xd339
movq 0x68(%rsp), %rax
movslq 0x30(%rsp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
testb $0x1, 0xd(%rax)
je 0xd327
movq 0x28(%rsp), %rax
testb $0x1, 0xe(%rax)
je 0xd327
movq 0x28(%rsp), %rax
movss 0x8(%rax), %xmm0
ucomiss 0x60(%rsp), %xmm0
jb 0xd327
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rax
movzbl 0x37(%rsp), %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movb 0xd(%rax), %cl
movq 0x20(%rsp), %rax
andb $0x1, %cl
movb %cl, 0xd(%rax)
movq 0x28(%rsp), %rax
movb 0xe(%rax), %cl
movq 0x20(%rsp), %rax
andb $0x1, %cl
movb %cl, 0xe(%rax)
movq 0x28(%rsp), %rax
movss 0x8(%rax), %xmm0
movq 0x20(%rsp), %rax
movss %xmm0, 0x8(%rax)
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq 0x28(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jbe 0xd2ff
movq 0x28(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x4(%rax)
jmp 0xd31d
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movq 0x28(%rsp), %rax
movl 0x4(%rax), %ecx
movq 0x20(%rsp), %rax
movl %ecx, 0x4(%rax)
movb 0x37(%rsp), %al
addb $0x1, %al
movb %al, 0x37(%rsp)
jmp 0xd329
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0xd20e
addq $0x78, %rsp
retq
nop