// File: /workspace/github_cpp_makefile_star2_O3/Ahhgust[P]STRaitRazor/str8.cpp
// Function: makeRecord(char const*, char const*, unsigned int, unsigned int, unsigned char, unsigned int, int)
void
makeRecord(const char* dna, const char *qvals, unsigned left, unsigned right, unsigned char orientation, unsigned strIndex, int id) {

  int len = (int) (right - left);
  int wordlen = ceil(len / (MAXWORD/2.0)); //number of binarywords to represent a haplotype

  bool nonstandard=false;
  const char *d = &(dna[left]);
  for (int i = 0; i < len; ++i, ++d) {
    if (*d != 'A' && *d != 'C' && *d != 'G' && *d != 'T') {
      nonstandard=true;
    }
  }

  double toAdd=1;
  if (USE_QVALS == EXPECT_QUALITY) {
    toAdd=getProbCorrect(&(qvals[left]), len);
  } else if (USE_QVALS == EDGAR_QUALITY) {
    toAdd=getProbCorrectEdgar(&(qvals[left]), len);
  }
    

  if (nonstandard) { // nonstandard letters are present (probably an N). Let's use the full ascii table.
    char *hap;
    if (opt.noReverseComplement== 0 && orientation==REVERSEFLANK) {
      hap = revcompCstring(dna+left, len);
    } else {
      hap = new char[ len + 1 ];
      strncpy(hap, dna+left, len);
    }
    hap[len]=0;

    Report rep = {strIndex, (binaryword*) hap, true, len};
    if (orientation==REVERSEFLANK) {

      if (USE_QVALS) {
        (matches[id][rep].fq) += toAdd;
      }
      
      ++(matches[id][rep].first);
    } else {

      if (USE_QVALS) {
        (matches[id][rep].rq) += toAdd;
      }
      
      ++(matches[id][rep].second);
    }

  } else { // This reduces DNA into its 2-bit encoding (saving much space, and making lookup operations faster

    binaryword *t, *haplotype = new binaryword[ wordlen ];
    t = haplotype;
    unsigned mod = len % (MAXWORD/2);
    unsigned numChars = MAXWORD/2;
    
    for (int i=0; i < len; i += (MAXWORD/2), ++t) {
      if (i + left + MAXWORD/2 > right) // don't read past the end of the array
        numChars=mod;
      
      *t = gatcToLong((char*)(&dna[i + left ]), numChars);
    }
    

    if (mod) { // is the sequence not a multple of 32?
      --t;
      *t = *t & ((binaryword)MAXBINARYWORD) << 2*((MAXWORD/2)-mod); // mask out the (right-most) character
    }
    
    if (opt.noReverseComplement== 0 && orientation==REVERSEFLANK) {
      binaryword *hap2 = new binaryword[ wordlen ];
      reverseComplement(haplotype, hap2, len);
      delete[] (haplotype);
      haplotype=hap2;
    }
    Report rep = {strIndex, haplotype, false, len};
    if (orientation==REVERSEFLANK) {

      if (USE_QVALS) {
        (matches[id][rep].fq) += toAdd;
      }
      
      ++(matches[id][rep].first);

    } else {
      
      if (USE_QVALS) {
        (matches[id][rep].rq) += toAdd;
      }
      
      ++(matches[id][rep].second);
    }
  }

  

  
  if (opt.verbose) {
    ++totalCounts[id][strIndex];
    leftFlankPosSum[id][strIndex] += left;
    rightFlankPosSum[id][strIndex] += right;
  }


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, %r12d
movl %r8d, 0xc(%rsp)
movl %edx, %r13d
movq %rsi, %r15
movq %rdi, %r14
movl %ecx, 0x8(%rsp)
movl %ecx, %ebx
subl %edx, %ebx
cvtsi2sd %ebx, %xmm0
mulsd 0x6afd(%rip), %xmm0     # 0xb020
callq 0x3080
movq %rbx, %rsi
movapd %xmm0, %xmm3
movl %r13d, %eax
movq %rax, 0x38(%rsp)
leaq (%r14,%rax), %rbp
testl %esi, %esi
jle 0x4569
movl %esi, %eax
xorl %ecx, %ecx
movl $0x80045, %edx          # imm = 0x80045
xorl %ebx, %ebx
movzbl (%rbp,%rcx), %edi
addl $-0x41, %edi
cmpl $0x13, %edi
ja 0x4565
btl %edi, %edx
jae 0x4565
incq %rcx
cmpl %ecx, %eax
jne 0x454a
jmp 0x456b
movb $0x1, %bl
jmp 0x455c
xorl %ebx, %ebx
movzbl 0x625dfe(%rip), %eax    # 0x62a370
cmpl $0x1, %eax
movq %rsi, 0x40(%rsp)
movl %r12d, 0x2c(%rsp)
je 0x45a6
cmpl $0x2, %eax
jne 0x4605
addq 0x38(%rsp), %r15
movq %r15, %rdi
movsd %xmm3, 0x48(%rsp)
callq 0x3a7b
movsd 0x48(%rsp), %xmm3
movq 0x40(%rsp), %rsi
jmp 0x460d
xorpd %xmm0, %xmm0
cmpl %r13d, 0x8(%rsp)
je 0x45e4
addq 0x38(%rsp), %r15
movl %esi, %eax
xorl %ecx, %ecx
movl $0xff, %edx
leaq 0x6255aa(%rip), %r8     # 0x629b70
movsbl (%r15,%rcx), %edi
testl %edi, %edi
je 0x45e4
addl $-0x21, %edi
cmpl %edx, %edi
cmovael %edx, %edi
addsd (%r8,%rdi,8), %xmm0
incq %rcx
cmpl %ecx, %eax
jne 0x45c6
movsd 0x6a2c(%rip), %xmm2     # 0xb018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
cmpnlesd %xmm0, %xmm2
andpd %xmm1, %xmm2
movapd %xmm2, 0x50(%rsp)
jmp 0x4613
movsd 0x6a0b(%rip), %xmm0     # 0xb018
movapd %xmm0, 0x50(%rsp)
movl 0xa0(%rsp), %r15d
testb $0x1, %bl
je 0x466b
cmpb $0x3, 0xc(%rsp)
jne 0x478a
cmpb $0x0, 0xac9d(%rip)      # 0xf2cf
jne 0x478a
movq %rbp, %rdi
movq %rsi, %rbx
callq 0x4477
movslq %ebx, %rcx
movb $0x0, (%rax,%rcx)
movl 0x2c(%rsp), %ebp
movl %ebp, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x1, 0x20(%rsp)
movl %ebx, 0x24(%rsp)
movb 0x625d0a(%rip), %al     # 0x62a370
jmp 0x47df
cvttsd2si %xmm3, %eax
cltq
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
movq %rdi, 0x60(%rsp)
callq 0x3030
movq 0x40(%rsp), %rdx
movq %rax, %rbx
leal 0x1f(%rdx), %eax
testl %edx, %edx
cmovnsl %edx, %eax
andl $-0x20, %eax
movl %edx, %ecx
subl %eax, %ecx
movq %rbx, 0x30(%rsp)
testl %edx, %edx
movl 0x8(%rsp), %esi
jle 0x4706
movq %r14, %r15
movl $0x20, %ebp
xorl %r12d, %r12d
movq 0x30(%rsp), %rbx
leal 0x20(%r13), %edx
movl %edx, 0x48(%rsp)
cmpl %esi, %edx
cmoval %ecx, %ebp
movl %r13d, %edi
addq %r15, %rdi
movl %ecx, %r13d
movl %esi, %r14d
movl %ebp, %esi
callq 0x969a
movl %r14d, %esi
movl %r13d, %ecx
movq 0x40(%rsp), %rdx
movq %rax, (%rbx)
addq $0x8, %rbx
addl $0x20, %r12d
movl 0x48(%rsp), %edi
movl %edi, %r13d
cmpl %r12d, %edx
jg 0x46c4
movl %esi, %r14d
testl %ecx, %ecx
je 0x471f
movq -0x8(%rbx), %rax
addl %ecx, %ecx
negb %cl
shrq %cl, %rax
shlq %cl, %rax
movq %rax, -0x8(%rbx)
cmpb $0x3, 0xc(%rsp)
movl 0x2c(%rsp), %ebp
jne 0x47e6
cmpb $0x0, 0xab9a(%rip)      # 0xf2cf
jne 0x47e6
movq 0x60(%rsp), %rdi
movq %rdx, %rbx
callq 0x3030
movq %rax, %r15
movq 0x30(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
movl %ebx, %edx
callq 0x9795
movq %r12, %rdi
callq 0x3360
movl %ebp, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movl %ebx, 0x24(%rsp)
movb 0x625bf3(%rip), %al     # 0x62a370
movl 0xa0(%rsp), %r15d
jmp 0x4812
movl %r15d, %ebx
leal 0x1(%rsi), %eax
movslq %eax, %rdi
movq %rsi, %r13
callq 0x3030
movq %rax, %r15
movslq %r13d, %r12
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x3150
movb $0x0, (%r15,%r12)
movl 0x2c(%rsp), %ebp
movl %ebp, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movb $0x1, 0x20(%rsp)
movl %r13d, 0x24(%rsp)
movb 0x625b9f(%rip), %al     # 0x62a370
cmpb $0x3, 0xc(%rsp)
jne 0x485f
movl %ebx, %r15d
movl 0x8(%rsp), %r14d
jmp 0x4812
movl %ebp, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movl %edx, 0x24(%rsp)
movb 0x625b6d(%rip), %al     # 0x62a370
cmpb $0x3, 0xc(%rsp)
movl 0xa0(%rsp), %r15d
jne 0x4870
movslq %r15d, %rbx
testb %al, %al
je 0x4842
leaq (%rbx,%rbx,2), %rdi
shlq $0x4, %rdi
addq 0x625b98(%rip), %rdi    # 0x62a3c0
leaq 0x10(%rsp), %rsi
callq 0x6d24
movapd 0x50(%rsp), %xmm0
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
leaq (%rbx,%rbx,2), %rdi
shlq $0x4, %rdi
addq 0x625b6f(%rip), %rdi    # 0x62a3c0
leaq 0x10(%rsp), %rsi
callq 0x6d24
incl (%rax)
jmp 0x48bc
testb %al, %al
movl %ebx, %r15d
movl 0x8(%rsp), %r14d
movslq %ebx, %rbx
jne 0x4877
jmp 0x48a0
movslq %r15d, %rbx
testb %al, %al
je 0x48a0
leaq (%rbx,%rbx,2), %rdi
shlq $0x4, %rdi
addq 0x625b3a(%rip), %rdi    # 0x62a3c0
leaq 0x10(%rsp), %rsi
callq 0x6d24
movapd 0x50(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
leaq (%rbx,%rbx,2), %rdi
shlq $0x4, %rdi
addq 0x625b11(%rip), %rdi    # 0x62a3c0
leaq 0x10(%rsp), %rsi
callq 0x6d24
incl 0x4(%rax)
cmpb $0x1, 0xaa0a(%rip)      # 0xf2cd
jne 0x48fe
movq 0x625adc(%rip), %rax    # 0x62a3a8
movslq %r15d, %rcx
movq (%rax,%rcx,8), %rax
movl %ebp, %edx
incl (%rax,%rdx,4)
movq 0x625ad1(%rip), %rax    # 0x62a3b0
movq (%rax,%rcx,8), %rax
movq 0x38(%rsp), %rsi
addq %rsi, (%rax,%rdx,8)
movl %r14d, %eax
movq 0x625ac2(%rip), %rsi    # 0x62a3b8
movq (%rsi,%rcx,8), %rcx
addq %rax, (%rcx,%rdx,8)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq