// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movb %r8b, %al
movl 0x10(%rbp), %r8d
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movb %al, -0x19(%rbp)
movl %r9d, -0x20(%rbp)
movl -0x18(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
cvtsi2sdl -0x24(%rbp), %xmm0
movsd 0xf383(%rip), %xmm1     # 0x14020
divsd %xmm1, %xmm0
callq 0x3080
cvttsd2si %xmm0, %eax
movl %eax, -0x28(%rbp)
movb $0x0, -0x29(%rbp)
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4d1b
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
je 0x4d02
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x43, %eax
je 0x4d02
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
je 0x4d02
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x54, %eax
je 0x4d02
movb $0x1, -0x29(%rbp)
jmp 0x4d04
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x4cc6
movsd 0xf2e5(%rip), %xmm0     # 0x14008
movsd %xmm0, -0x48(%rbp)
movsbl 0x632651(%rip), %eax    # 0x637380
cmpl $0x2, %eax
jne 0x4d4d
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x3b70
movsd %xmm0, -0x48(%rbp)
jmp 0x4d72
movsbl 0x63262c(%rip), %eax    # 0x637380
cmpl $0x1, %eax
jne 0x4d70
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x3c30
movsd %xmm0, -0x48(%rbp)
jmp 0x4d72
testb $0x1, -0x29(%rbp)
je 0x4ed6
movb 0x1755d(%rip), %al      # 0x1c2df
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x4dad
movzbl -0x19(%rbp), %eax
cmpl $0x3, %eax
jne 0x4dad
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %eax
addq %rax, %rdi
movl -0x24(%rbp), %esi
callq 0x4b70
movq %rax, -0x50(%rbp)
jmp 0x4dd6
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3030
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x14(%rbp), %eax
addq %rax, %rsi
movslq -0x24(%rbp), %rdx
callq 0x3140
movq -0x50(%rbp), %rax
movslq -0x24(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x20(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
movb $0x1, -0x58(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x3, %eax
jne 0x4e6a
cmpb $0x0, 0x632576(%rip)    # 0x637380
je 0x4e46
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movq 0x6325b0(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x8980
movsd -0xb0(%rbp), %xmm0
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x632583(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x8980
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4ed1
cmpb $0x0, 0x63250f(%rip)    # 0x637380
je 0x4ead
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movq 0x632549(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x8980
movsd -0xb8(%rbp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movq 0x63251c(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0x68(%rbp), %rsi
callq 0x8980
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x515b
movslq -0x28(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %eax
movl $0x20, %ecx
cltd
idivl %ecx
movl %edx, -0x7c(%rbp)
movl $0x20, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4f89
movl -0x84(%rbp), %eax
addl -0x14(%rbp), %eax
addl $0x20, %eax
cmpl -0x18(%rbp), %eax
jbe 0x4f48
movl -0x7c(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movl -0x84(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, %eax
addq %rax, %rdi
movl -0x80(%rbp), %esi
callq 0x11000
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, (%rax)
movl -0x84(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x84(%rbp)
movq -0x70(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x70(%rbp)
jmp 0x4f26
cmpl $0x0, -0x7c(%rbp)
je 0x4fd2
movq -0x70(%rbp), %rax
addq $-0x8, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movl $0x20, %eax
subl -0x7c(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
movq -0xc0(%rbp), %rcx
andq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, (%rax)
movb 0x17307(%rip), %al      # 0x1c2df
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5052
movzbl -0x19(%rbp), %eax
cmpl $0x3, %eax
jne 0x5052
movslq -0x28(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rdi
movq -0x90(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x11130
movq -0x78(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, %rax
je 0x5047
movq -0xc8(%rbp), %rdi
callq 0x3350
movq -0x90(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0xa0(%rbp)
movb $0x0, -0x98(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x94(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x3, %eax
jne 0x50ec
cmpb $0x0, 0x6322fa(%rip)    # 0x637380
je 0x50c5
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movq 0x632334(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x8980
movsd -0xd0(%rbp), %xmm0
addsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x632304(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x8980
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x5159
cmpb $0x0, 0x63228d(%rip)    # 0x637380
je 0x5132
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movq 0x6322c7(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x8980
movsd -0xd8(%rbp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movq 0x632297(%rip), %rdi    # 0x6373d0
movslq 0x10(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x8980
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
jmp 0x515b
testb $0x1, 0x1717b(%rip)     # 0x1c2dd
je 0x51bd
movq 0x63224d(%rip), %rax    # 0x6373b8
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
movl %eax, %edx
movq 0x632235(%rip), %rax    # 0x6373c0
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x18(%rbp), %eax
movl %eax, %edx
movq 0x63221e(%rip), %rax    # 0x6373c8
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x20(%rbp), %ecx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)