// File: Ahhgust[P]STRaitRazor/str8.cpp
// Function: CompareReport::operator()(Report const&, Report const&) const
bool operator() (const Report &a, const Report &b) const {
    //TODO: Handle string/float pair instead of lexicographic ordering

    unsigned i1 = a.strIndex;
    unsigned i2 = b.strIndex;

    // different loci
    if (i2 < i1) 
      return false;
    else if (i1 < i2) 
      return true;


    // different haplotype lengths; ergo different haplotypes
    if (a.hapLength < b.hapLength)
      return true;
    else if (a.hapLength > b.hapLength)
      return false;

    // one haplotype has nonstandard letters and the other does not.    
    if (a.nonstandardLetters == false && b.nonstandardLetters==true)
      return false;
    else if (a.nonstandardLetters == true && b.nonstandardLetters==false)
      return true;

    if (a.nonstandardLetters==false) { // compare binary words

    // compute the (min) length in binarywords of the two haplotypes
      unsigned i, lengthInWords = ceil( min(a.hapLength, b.hapLength)/ (MAXWORD/2.0));
      binaryword *b1 = a.haplotype;
      binaryword *b2 = b.haplotype;
      
      for (i=0; i < lengthInWords; ++i, ++b1, ++b2) {
        if (*b1 < *b2)
          return true;
        else if (*b1 > *b2)
          return false;
      }

    } else { // compare char*s
      char *b1 = (char*) a.haplotype;
      char *b2 = (char*) b.haplotype;

      for (int i=0; i < a.hapLength; ++i, ++b1, ++b2) {
        if (*b1 < *b2)
          return true;
        else if (*b1 > *b2)
          return false;
      }
    }

    return false;
    
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0xbbf7
movb $0x0, -0x1(%rbp)
jmp 0xbdea
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0xbc08
movb $0x1, -0x1(%rbp)
jmp 0xbdea
jmp 0xbc0a
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0xbc23
movb $0x1, -0x1(%rbp)
jmp 0xbdea
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jle 0xbc3c
movb $0x0, -0x1(%rbp)
jmp 0xbdea
jmp 0xbc3e
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xbc69
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xbc69
movb $0x0, -0x1(%rbp)
jmp 0xbdea
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xbc94
movq -0x20(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xbc94
movb $0x1, -0x1(%rbp)
jmp 0xbdea
jmp 0xbc96
movq -0x18(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xbd62
movq -0x18(%rbp), %rdi
addq $0x14, %rdi
movq -0x20(%rbp), %rsi
addq $0x14, %rsi
callq 0xc1b0
cvtsi2sdl (%rax), %xmm0
movsd 0x834c(%rip), %xmm1     # 0x14018
mulsd %xmm1, %xmm0
callq 0x3080
cvttsd2si %xmm0, %rax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jae 0xbd5d
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xbd1d
movb $0x1, -0x1(%rbp)
jmp 0xbdea
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
cmpq (%rcx), %rax
jbe 0xbd36
movb $0x0, -0x1(%rbp)
jmp 0xbdea
jmp 0xbd38
jmp 0xbd3a
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x40(%rbp)
jmp 0xbcfc
jmp 0xbde6
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0xbde4
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
movq -0x50(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xbda5
movb $0x1, -0x1(%rbp)
jmp 0xbdea
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
movq -0x50(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jle 0xbdbd
movb $0x0, -0x1(%rbp)
jmp 0xbdea
jmp 0xbdbf
jmp 0xbdc1
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xbd81
jmp 0xbde6
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop