// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movl %r9d, 0xc(%rsp)
movl %r8d, %r12d
movl %edx, %r13d
movq %rsi, %rbx
movq %rdi, %r15
movl %ecx, 0x2c(%rsp)
movl %ecx, %r14d
subl %edx, %r14d
cvtsi2sd %r14d, %xmm0
mulsd 0x5e74(%rip), %xmm0     # 0xa020
callq 0x3070
movapd %xmm0, %xmm1
movl %r13d, %edi
movq %r15, 0x70(%rsp)
leaq (%r15,%rdi), %rbp
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %ecx
movq %r14, 0x18(%rsp)
cmovgl %r14d, %ecx
movl $0x80045, %edx          # imm = 0x80045
xorl %r14d, %r14d
cmpl %eax, %ecx
je 0x41fc
movzbl (%rbp,%rax), %esi
addl $-0x41, %esi
cmpl $0x13, %esi
ja 0x41f7
btl %esi, %edx
jae 0x41f7
incq %rax
jmp 0x41dc
movb $0x1, %r14b
jmp 0x41f2
movzbl 0x62614d(%rip), %eax    # 0x62a350
cmpl $0x1, %eax
movq %rdi, 0x48(%rsp)
je 0x422a
cmpl $0x2, %eax
jne 0x4248
addq %rdi, %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movsd %xmm1, 0x20(%rsp)
callq 0x3902
jmp 0x4240
addq %rdi, %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movsd %xmm1, 0x20(%rsp)
callq 0x3942
movsd 0x20(%rsp), %xmm1
jmp 0x4250
movsd 0x5dc8(%rip), %xmm0     # 0xa018
movsd %xmm0, 0x10(%rsp)
testb $0x1, %r14b
je 0x4291
movl %r12d, %r13d
cmpb $0x3, %r12b
jne 0x4390
cmpb $0x0, 0xb03f(%rip)      # 0xf2af
jne 0x4390
movq %rbp, %rdi
movq 0x18(%rsp), %r15
movl %r15d, %esi
callq 0x4107
movq %rax, %r14
movslq %r15d, %r12
jmp 0x43b5
movl %r12d, 0x54(%rsp)
cvttsd2si %xmm1, %eax
movslq 0xb0(%rsp), %rcx
movq %rcx, 0x58(%rsp)
cltq
leaq (,%rax,8), %rcx
testl %eax, %eax
pushq $-0x1
popq %rdi
cmovnsq %rcx, %rdi
movq %rdi, 0x60(%rsp)
callq 0x3030
movq %rax, %r15
pushq $0x20
popq %r14
movq 0x18(%rsp), %rcx
movl %ecx, %eax
cltd
idivl %r14d
movl %edx, 0x20(%rsp)
movslq %ecx, %rbx
movq %r15, 0x68(%rsp)
addq $-0x8, %r15
xorl %r12d, %r12d
cmpq %rbx, %r12
jge 0x431d
leal 0x20(%r13), %ebp
cmpl 0x2c(%rsp), %ebp
cmoval 0x20(%rsp), %r14d
movl %r13d, %edi
addq 0x70(%rsp), %rdi
movl %r14d, %esi
callq 0x84b6
movq %rax, 0x8(%r15)
addq $0x8, %r15
addq $0x20, %r12
movl %ebp, %r13d
jmp 0x42e9
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
je 0x4335
movq (%r15), %rax
addl %ecx, %ecx
negb %cl
shrq %cl, %rax
shlq %cl, %rax
movq %rax, (%r15)
movl 0x54(%rsp), %ebx
cmpb $0x3, %bl
movl 0xb0(%rsp), %ebp
movq 0x18(%rsp), %r15
movq 0x68(%rsp), %r13
jne 0x443e
cmpb $0x0, 0xaf55(%rip)      # 0xf2af
movl 0xc(%rsp), %r12d
jne 0x4443
movq 0x60(%rsp), %rdi
callq 0x3030
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x8566
movq %r13, %rdi
callq 0x3300
movq %r14, %r13
jmp 0x4443
movq 0x18(%rsp), %r15
leal 0x1(%r15), %eax
movslq %eax, %rdi
callq 0x3030
movq %rax, %r14
movslq %r15d, %r12
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x3140
movb $0x0, (%r14,%r12)
movl 0xc(%rsp), %r12d
movl %r12d, 0x30(%rsp)
movq %r14, 0x38(%rsp)
movb $0x1, 0x40(%rsp)
movl %r15d, 0x44(%rsp)
movb 0x625f77(%rip), %al     # 0x62a350
cmpb $0x3, %r13b
jne 0x442e
testb %al, %al
movl 0xb0(%rsp), %ebp
movslq %ebp, %rbx
je 0x4412
imulq $0x30, %rbx, %rdi
addq 0x625fa8(%rip), %rdi    # 0x62a3a0
leaq 0x30(%rsp), %rsi
callq 0x5fcc
movsd 0x10(%rsp), %xmm0
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
imulq $0x30, %rbx, %rdi
addq 0x625f83(%rip), %rdi    # 0x62a3a0
leaq 0x30(%rsp), %rsi
callq 0x5fcc
incl (%rax)
jmp 0x44b8
testb %al, %al
movl 0xb0(%rsp), %ebp
movslq %ebp, %rbx
jne 0x4474
jmp 0x44a0
movl 0xc(%rsp), %r12d
movl %r12d, 0x30(%rsp)
movq %r13, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movl %r15d, 0x44(%rsp)
movb 0x625ef3(%rip), %al     # 0x62a350
cmpb $0x3, %bl
jne 0x446b
movslq %ebp, %rbx
testb %al, %al
jne 0x43ed
jmp 0x4412
testb %al, %al
je 0x449b
movq 0x58(%rsp), %rbx
imulq $0x30, %rbx, %rdi
addq 0x625f21(%rip), %rdi    # 0x62a3a0
leaq 0x30(%rsp), %rsi
callq 0x5fcc
movsd 0x10(%rsp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
jmp 0x44a0
movq 0x58(%rsp), %rbx
imulq $0x30, %rbx, %rdi
addq 0x625ef5(%rip), %rdi    # 0x62a3a0
leaq 0x30(%rsp), %rsi
callq 0x5fcc
incl 0x4(%rax)
movq 0x48(%rsp), %rsi
cmpb $0x1, 0xade9(%rip)      # 0xf2ad
jne 0x44fc
movq 0x625ebb(%rip), %rax    # 0x62a388
movslq %ebp, %rcx
movq (%rax,%rcx,8), %rax
movl %r12d, %edx
incl (%rax,%rdx,4)
movq 0x625eaf(%rip), %rax    # 0x62a390
movq (%rax,%rcx,8), %rax
addq %rsi, (%rax,%rdx,8)
movl 0x2c(%rsp), %eax
movq 0x625ea4(%rip), %rsi    # 0x62a398
movq (%rsi,%rcx,8), %rcx
addq %rax, (%rcx,%rdx,8)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq