// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/../vcf.c
// Function: bcf_set_variant_type
static void bcf_set_variant_type(const char *ref, const char *alt, bcf_variant_t *var)
{
    if ( *alt == '*' && !alt[1] ) { var->n = 0; var->type = VCF_OVERLAP; return; }  // overlapping variant

    // The most frequent case
    if ( !ref[1] && !alt[1] )
    {
        if ( *alt == '.' || *ref==*alt ) { var->n = 0; var->type = VCF_REF; return; }
        if ( *alt == 'X' ) { var->n = 0; var->type = VCF_REF; return; }  // mpileup's X allele shouldn't be treated as variant
        var->n = 1; var->type = VCF_SNP; return;
    }
    if ( alt[0]=='<' )
    {
        if ( alt[1]=='X' && alt[2]=='>' ) { var->n = 0; var->type = VCF_REF; return; }  // mpileup's X allele shouldn't be treated as variant
        if ( alt[1]=='*' && alt[2]=='>' ) { var->n = 0; var->type = VCF_REF; return; }
        if ( !strcmp("NON_REF>",alt+1) ) { var->n = 0; var->type = VCF_REF; return; }
        var->type = VCF_OTHER;
        return;
    }

    // Catch "joined before" breakend case
    if ( alt[0]==']' || alt[0] == '[' )
    {
        var->type = VCF_BND; return;
    }

    // Iterate through alt characters that match the reference
    const char *r = ref, *a = alt;
    while (*r && *a && toupper_c(*r)==toupper_c(*a) ) { r++; a++; }     // unfortunately, matching REF,ALT case is not guaranteed

    if ( *a && !*r )
    {
        while ( *a ) a++;
        if ( *(a-1)==']' || *(a-1)=='[' ) { var->type = VCF_BND; return; } // "joined after" breakend
        var->n = (a-alt)-(r-ref); var->type = VCF_INDEL | VCF_INS; return;
    }
    else if ( *r && !*a )
    {
        while ( *r ) r++;
        var->n = (a-alt)-(r-ref); var->type = VCF_INDEL | VCF_DEL; return;
    }
    else if ( !*r && !*a )
    {
        var->n = 0; var->type = VCF_REF; return;
    }

    const char *re = r, *ae = a;
    while ( re[1] ) re++;
    while ( ae[1] ) ae++;
    if ( ae[0]==']' || ae[0]=='[' ) { var->type = VCF_BND; return; }    // "joined after" breakend
    while ( re>r && ae>a && toupper_c(*re)==toupper_c(*ae) ) { re--; ae--; }
    if ( ae==a )
    {
        if ( re==r ) { var->n = 1; var->type = VCF_SNP; return; }
        var->n = -(re-r);
        if ( toupper_c(*re)==toupper_c(*ae) ) { var->type = VCF_INDEL | VCF_DEL; return; }
        var->type = VCF_OTHER; return;
    }
    else if ( re==r )
    {
        var->n = ae-a;
        if ( toupper_c(*re)==toupper_c(*ae) ) { var->type = VCF_INDEL | VCF_INS; return; }
        var->type = VCF_OTHER; return;
    }

    var->type = ( re-r == ae-a ) ? VCF_MNP : VCF_OTHER;
    var->n = ( re-r > ae-a ) ? -(re-r+1) : ae-a+1;

    // should do also complex events, SVs, etc...
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movzbl (%rsi), %eax
cmpl $0x2a, %eax
jne 0x1d304
cmpb $0x0, 0x1(%r15)
je 0x1d330
cmpb $0x0, 0x1(%r14)
jne 0x1d316
cmpb $0x0, 0x1(%r15)
je 0x1d408
cmpl $0x3c, %eax
je 0x1d33c
cmpl $0x5b, %eax
je 0x1d325
cmpl $0x5d, %eax
jne 0x1d37b
movl $0x10, (%rbx)
jmp 0x1d420
movq $0x20, (%rbx)
jmp 0x1d420
movzbl 0x1(%r15), %eax
cmpl $0x2a, %eax
je 0x1d34b
cmpl $0x58, %eax
jne 0x1d356
cmpb $0x3e, 0x2(%r15)
je 0x1d419
incq %r15
leaq 0x8c200(%rip), %rdi     # 0xa9560
movq %r15, %rsi
callq 0x46e0
testl %eax, %eax
je 0x1d419
movl $0x8, (%rbx)
jmp 0x1d420
movb (%r14), %bpl
movq %r14, %r12
movq %r15, %rcx
testb %bpl, %bpl
je 0x1d3cb
xorl %r12d, %r12d
movzbl (%r15,%r12), %r13d
testq %r13, %r13
je 0x1d42f
callq 0x4090
movq (%rax), %rax
movzbl %bpl, %ecx
movb (%rax,%rcx,4), %cl
cmpb (%rax,%r13,4), %cl
jne 0x1d451
movb 0x1(%r14,%r12), %bpl
incq %r12
testb %bpl, %bpl
jne 0x1d38c
leaq (%r15,%r12), %rcx
movb (%r15,%r12), %al
addq %r14, %r12
testb %al, %al
je 0x1d419
leaq 0x1(%rcx), %rax
addl %r14d, %ecx
addl %r15d, %r12d
subl %r12d, %ecx
incl %ecx
cmpb $0x0, (%rax)
leaq 0x1(%rax), %rax
jne 0x1d3dc
movzbl -0x2(%rax), %eax
cmpl $0x5d, %eax
je 0x1d325
cmpl $0x5b, %eax
je 0x1d325
movl %ecx, 0x4(%rbx)
movl $0x44, (%rbx)
jmp 0x1d420
cmpb $0x2e, %al
je 0x1d419
cmpb %al, (%r14)
je 0x1d419
cmpb $0x58, %al
jne 0x1d565
movq $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
leaq (%r14,%rax), %rcx
incq %rax
cmpb $0x0, (%r12,%rcx)
jne 0x1d431
movl $0x1, %ecx
subl %eax, %ecx
movl %ecx, 0x4(%rbx)
movl $0x84, (%rbx)
jmp 0x1d420
leaq (%r14,%r12), %rdx
leaq (%r14,%r12), %r8
addq $-0x2, %r8
leaq (%r14,%r12), %rcx
decq %rcx
leaq (%r15,%r12), %rsi
leaq (%r15,%r12), %rdi
addq $-0x2, %rdi
incq %rcx
cmpb $0x0, 0x3(%r8)
leaq 0x1(%r8), %r8
jne 0x1d470
cmpb $0x0, 0x3(%rdi)
leaq 0x1(%rdi), %rdi
jne 0x1d47e
movzbl 0x1(%rdi), %r9d
cmpl $0x5b, %r9d
je 0x1d325
cmpl $0x5d, %r9d
je 0x1d325
leaq 0x1(%rdi), %r9
cmpq %rdx, %rcx
jbe 0x1d4f5
cmpq %rsi, %r9
jbe 0x1d4f5
xorl %r10d, %r10d
movzbl (%rcx,%r10), %r9d
movb (%rax,%r9,4), %r9b
movzbl 0x1(%rdi,%r10), %r11d
cmpb (%rax,%r11,4), %r9b
jne 0x1d4eb
leaq (%r8,%r10), %r9
leaq -0x1(%r10), %r11
cmpq %rdx, %r9
jbe 0x1d4df
addq %rdi, %r10
cmpq %rsi, %r10
movq %r11, %r10
ja 0x1d4b2
leaq (%rdi,%r11), %r9
incq %r9
addq %r11, %rcx
jmp 0x1d4f5
leaq (%rdi,%r10), %r9
incq %r9
addq %r10, %rcx
cmpq %r9, %rsi
je 0x1d53f
cmpq %rcx, %rdx
je 0x1d577
movq %rcx, %rax
subq %r14, %rax
movq %rax, %rdx
subq %r12, %rdx
subq %r15, %r9
movq %r9, %rsi
subq %r12, %rsi
cmpq %r9, %rax
movl $0x2, %eax
movl $0x8, %edi
cmovel %eax, %edi
movl %edi, (%rbx)
subl %ecx, %r14d
leal 0x1(%rsi), %eax
cmpq %rsi, %rdx
leal -0x1(%r14,%r12), %ecx
cmovlel %eax, %ecx
movl %ecx, 0x4(%rbx)
jmp 0x1d420
cmpq %rcx, %rdx
je 0x1d565
subl %ecx, %r14d
addl %r14d, %r12d
movl %r12d, 0x4(%rbx)
movzbl (%rcx), %ecx
movb (%rax,%rcx,4), %cl
movzbl (%rsi), %edx
cmpb (%rax,%rdx,4), %cl
jne 0x1d370
jmp 0x1d449
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%rbx)
jmp 0x1d420
movl %r9d, %ecx
subl %r15d, %ecx
subl %r12d, %ecx
movl %ecx, 0x4(%rbx)
movzbl (%rdx), %ecx
movb (%rax,%rcx,4), %cl
movzbl (%r9), %edx
cmpb (%rax,%rdx,4), %cl
jne 0x1d370
jmp 0x1d400
nop