// File: /workspace/github_cpp_makefile_star2_O1/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, 0x14(%rsp)
movl %r8d, 0x10(%rsp)
movl %ecx, %r15d
movl %edx, %r13d
movq %rsi, %r14
movq %rdi, %r12
movl %ecx, %ebx
subl %edx, %ebx
cvtsi2sd %ebx, %xmm0
mulsd 0x6ae9(%rip), %xmm0     # 0xb020
callq 0x3080
movq %r12, %r8
movq %rbx, %rsi
movapd %xmm0, %xmm3
movl %r13d, %r12d
leaq (%r8,%r12), %rbp
testl %esi, %esi
jle 0x457b
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 0x4577
btl %edi, %edx
jae 0x4577
incq %rcx
cmpl %ecx, %eax
jne 0x455c
jmp 0x457d
movb $0x1, %bl
jmp 0x456e
xorl %ebx, %ebx
movzbl 0x625dec(%rip), %eax    # 0x62a370
cmpl $0x1, %eax
movq %rsi, 0x8(%rsp)
movq %r8, 0x60(%rsp)
je 0x45b4
cmpl $0x2, %eax
jne 0x460f
addq %r12, %r14
movq %r14, %rdi
movsd %xmm3, (%rsp)
callq 0x3a9b
movsd (%rsp), %xmm3
movq 0x8(%rsp), %rsi
jmp 0x4617
xorpd %xmm0, %xmm0
cmpl %r13d, %r15d
je 0x45ee
addq %r12, %r14
movl %esi, %eax
xorl %ecx, %ecx
movl $0xff, %edx
leaq 0x6255a0(%rip), %r8     # 0x629b70
movsbl (%r14,%rcx), %edi
testl %edi, %edi
je 0x45ee
addl $-0x21, %edi
cmpl %edx, %edi
cmovael %edx, %edi
addsd (%r8,%rdi,8), %xmm0
incq %rcx
cmpl %ecx, %eax
jne 0x45d0
movsd 0x6a22(%rip), %xmm2     # 0xb018
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
cmpnlesd %xmm0, %xmm2
andpd %xmm1, %xmm2
movapd %xmm2, 0x40(%rsp)
jmp 0x461d
movsd 0x6a01(%rip), %xmm0     # 0xb018
movapd %xmm0, 0x40(%rsp)
testb $0x1, %bl
je 0x465b
movl %r15d, (%rsp)
movq %r12, %rbx
movslq %esi, %r14
movl 0x10(%rsp), %r13d
cmpb $0x3, %r13b
jne 0x476d
cmpb $0x0, 0xac8d(%rip)      # 0xf2cf
jne 0x476d
movq %rbp, %rdi
movq %rsi, %r15
callq 0x4492
movq %rax, %r12
jmp 0x478c
movq %r12, 0x38(%rsp)
cvttsd2si %xmm3, %eax
cltq
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
movq %rdi, 0x58(%rsp)
callq 0x3030
movq 0x8(%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
movq 0x60(%rsp), %rbp
jle 0x46f5
movl $0x20, %r14d
xorl %r12d, %r12d
movq 0x30(%rsp), %rbx
leal 0x20(%r13), %edx
movl %edx, (%rsp)
cmpl %r15d, %edx
cmoval %ecx, %r14d
movl %r13d, %edi
addq %rbp, %rdi
movl %ecx, %r13d
movl %r14d, %esi
callq 0x95ba
movl %r13d, %ecx
movq 0x8(%rsp), %rdx
movq %rax, (%rbx)
addq $0x8, %rbx
addl $0x20, %r12d
movl (%rsp), %edi
movl %edi, %r13d
cmpl %r12d, %edx
jg 0x46b8
testl %ecx, %ecx
je 0x470b
movq -0x8(%rbx), %rax
addl %ecx, %ecx
negb %cl
shrq %cl, %rax
shlq %cl, %rax
movq %rax, -0x8(%rbx)
movl 0x10(%rsp), %ebx
cmpb $0x3, %bl
movl 0x14(%rsp), %ebp
movl 0xa0(%rsp), %r12d
jne 0x481a
cmpb $0x0, 0xaba4(%rip)      # 0xf2cf
jne 0x481a
movq 0x58(%rsp), %rdi
callq 0x3030
movq %rax, %r14
movq 0x30(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
movq 0x8(%rsp), %rdx
callq 0x96b5
movq %r13, %rdi
callq 0x3360
movq 0x8(%rsp), %rdx
movq %r14, %rax
movq 0x38(%rsp), %r14
jmp 0x4824
leal 0x1(%rsi), %eax
movslq %eax, %rdi
movq %rsi, %r15
callq 0x3030
movq %rax, %r12
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x3150
movb $0x0, (%r12,%r14)
movl 0x14(%rsp), %ebp
movl %ebp, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movb $0x1, 0x28(%rsp)
movl %r15d, 0x2c(%rsp)
movb 0x625bc2(%rip), %al     # 0x62a370
cmpb $0x3, %r13b
jne 0x4847
testb %al, %al
movq %rbx, %r14
movl 0xa0(%rsp), %r12d
movl (%rsp), %r15d
je 0x47f7
movslq %r12d, %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq 0x625be3(%rip), %rdi    # 0x62a3c0
leaq 0x18(%rsp), %rsi
callq 0x6c84
movapd 0x40(%rsp), %xmm0
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movslq %r12d, %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq 0x625bb7(%rip), %rdi    # 0x62a3c0
leaq 0x18(%rsp), %rsi
callq 0x6c84
incl (%rax)
jmp 0x48db
movq 0x38(%rsp), %r14
movq 0x30(%rsp), %rax
movl %ebp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movl %edx, 0x2c(%rsp)
movb 0x625b34(%rip), %al     # 0x62a370
cmpb $0x3, %bl
jne 0x488f
testb %al, %al
jne 0x47cb
jmp 0x47f7
testb %al, %al
movq %rbx, %r14
movl 0xa0(%rsp), %r12d
movl (%rsp), %r15d
je 0x4886
movslq %r12d, %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq 0x625b54(%rip), %rdi    # 0x62a3c0
leaq 0x18(%rsp), %rsi
callq 0x6c84
movapd 0x40(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movslq %r12d, %rax
leaq (%rax,%rax,2), %rdi
jmp 0x48c3
movslq %r12d, %rbx
testb %al, %al
je 0x48bf
leaq (%rbx,%rbx,2), %rdi
shlq $0x4, %rdi
addq 0x625b1b(%rip), %rdi    # 0x62a3c0
leaq 0x18(%rsp), %rsi
callq 0x6c84
movapd 0x40(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
leaq (%rbx,%rbx,2), %rdi
shlq $0x4, %rdi
addq 0x625af2(%rip), %rdi    # 0x62a3c0
leaq 0x18(%rsp), %rsi
callq 0x6c84
incl 0x4(%rax)
cmpb $0x1, 0xa9eb(%rip)      # 0xf2cd
jne 0x4918
movq 0x625abd(%rip), %rax    # 0x62a3a8
movslq %r12d, %rcx
movq (%rax,%rcx,8), %rax
movl %ebp, %edx
incl (%rax,%rdx,4)
movq 0x625ab2(%rip), %rax    # 0x62a3b0
movq (%rax,%rcx,8), %rax
addq %r14, (%rax,%rdx,8)
movl %r15d, %eax
movq 0x625aa8(%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