// File: zeeev[P]DASVC/bamtools/src/toolkit/bamtools_resolve.cpp
// Function: CalculateModelType(BamTools::BamAlignment const&)
uint16_t CalculateModelType(const BamAlignment& al) {

    // localize alignment's mate positions & orientations for convenience
    const int32_t m1_begin = ( al.IsFirstMate() ? al.Position : al.MatePosition );
    const int32_t m2_begin = ( al.IsFirstMate() ? al.MatePosition : al.Position );
    const bool m1_isReverseStrand = ( al.IsFirstMate() ? al.IsReverseStrand() : al.IsMateReverseStrand() );
    const bool m2_isReverseStrand = ( al.IsFirstMate() ? al.IsMateReverseStrand() : al.IsReverseStrand() );

    // determine 'model type'
    if ( m1_begin < m2_begin ) {
        if ( !m1_isReverseStrand && !m2_isReverseStrand ) return 0; // ID: 1
        if ( !m1_isReverseStrand &&  m2_isReverseStrand ) return 1; // ID: 2
        if (  m1_isReverseStrand && !m2_isReverseStrand ) return 2; // ID: 3
        if (  m1_isReverseStrand &&  m2_isReverseStrand ) return 3; // ID: 4
    } else {
        if ( !m2_isReverseStrand && !m1_isReverseStrand ) return 4; // ID: 5
        if ( !m2_isReverseStrand &&  m1_isReverseStrand ) return 5; // ID: 6
        if (  m2_isReverseStrand && !m1_isReverseStrand ) return 6; // ID: 7
        if (  m2_isReverseStrand &&  m1_isReverseStrand ) return 7; // ID: 8
    }

    // unknown model
    return ModelType::DUMMY_ID;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq 0x18(%rsp), %rdi
callq 0x86340
testb $0x1, %al
jne 0xc7409
jmp 0xc741a
movq 0x18(%rsp), %rax
movl 0xac(%rax), %eax
movl %eax, 0x8(%rsp)
jmp 0xc7429
movq 0x18(%rsp), %rax
movl 0xd4(%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rdi
callq 0x86340
testb $0x1, %al
jne 0xc7441
jmp 0xc7452
movq 0x18(%rsp), %rax
movl 0xd4(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0xc7461
movq 0x18(%rsp), %rax
movl 0xac(%rax), %eax
movl %eax, 0x4(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
callq 0x86340
testb $0x1, %al
jne 0xc7479
jmp 0xc7489
movq 0x18(%rsp), %rdi
callq 0x86a40
movb %al, 0x3(%rsp)
jmp 0xc7497
movq 0x18(%rsp), %rdi
callq 0x86a80
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
andb $0x1, %al
movb %al, 0xf(%rsp)
movq 0x18(%rsp), %rdi
callq 0x86340
testb $0x1, %al
jne 0xc74b1
jmp 0xc74c1
movq 0x18(%rsp), %rdi
callq 0x86a80
movb %al, 0x2(%rsp)
jmp 0xc74cf
movq 0x18(%rsp), %rdi
callq 0x86a40
movb %al, 0x2(%rsp)
movb 0x2(%rsp), %al
andb $0x1, %al
movb %al, 0xe(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x10(%rsp), %eax
jge 0xc7547
testb $0x1, 0xf(%rsp)
jne 0xc74fd
testb $0x1, 0xe(%rsp)
jne 0xc74fd
movw $0x0, 0x26(%rsp)
jmp 0xc75ac
testb $0x1, 0xf(%rsp)
jne 0xc7517
testb $0x1, 0xe(%rsp)
je 0xc7517
movw $0x1, 0x26(%rsp)
jmp 0xc75ac
testb $0x1, 0xf(%rsp)
je 0xc752e
testb $0x1, 0xe(%rsp)
jne 0xc752e
movw $0x2, 0x26(%rsp)
jmp 0xc75ac
testb $0x1, 0xf(%rsp)
je 0xc7545
testb $0x1, 0xe(%rsp)
je 0xc7545
movw $0x3, 0x26(%rsp)
jmp 0xc75ac
jmp 0xc75a5
testb $0x1, 0xe(%rsp)
jne 0xc755e
testb $0x1, 0xf(%rsp)
jne 0xc755e
movw $0x4, 0x26(%rsp)
jmp 0xc75ac
testb $0x1, 0xe(%rsp)
jne 0xc7575
testb $0x1, 0xf(%rsp)
je 0xc7575
movw $0x5, 0x26(%rsp)
jmp 0xc75ac
testb $0x1, 0xe(%rsp)
je 0xc758c
testb $0x1, 0xf(%rsp)
jne 0xc758c
movw $0x6, 0x26(%rsp)
jmp 0xc75ac
testb $0x1, 0xe(%rsp)
je 0xc75a3
testb $0x1, 0xf(%rsp)
je 0xc75a3
movw $0x7, 0x26(%rsp)
jmp 0xc75ac
jmp 0xc75a5
movw $0x64, 0x26(%rsp)
movw 0x26(%rsp), %ax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)