// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/vcf.c
// Function: bcf_hdr_merge
bcf_hdr_t *bcf_hdr_merge(bcf_hdr_t *dst, const bcf_hdr_t *src)
{
    if ( !dst )
    {
        // this will effectively strip existing IDX attributes from src to become dst
        dst = bcf_hdr_init("r");
        kstring_t htxt = {0,0,0};
        if (bcf_hdr_format(src, 0, &htxt) < 0) {
            free(htxt.s);
            return NULL;
        }
        if ( bcf_hdr_parse(dst, htxt.s) < 0 ) {
            bcf_hdr_destroy(dst);
            dst = NULL;
        }
        free(htxt.s);
        return dst;
    }

    int i, ndst_ori = dst->nhrec, need_sync = 0, res;
    for (i=0; i<src->nhrec; i++)
    {
        if ( src->hrec[i]->type==BCF_HL_GEN && src->hrec[i]->value )
        {
            int j;
            for (j=0; j<ndst_ori; j++)
            {
                if ( dst->hrec[j]->type!=BCF_HL_GEN ) continue;

                // Checking only the key part of generic lines, otherwise
                // the VCFs are too verbose. Should we perhaps add a flag
                // to bcf_hdr_combine() and make this optional?
                if ( !strcmp(src->hrec[i]->key,dst->hrec[j]->key) ) break;
            }
            if ( j>=ndst_ori ) {
                res = bcf_hdr_add_hrec(dst, bcf_hrec_dup(src->hrec[i]));
                if (res < 0) return NULL;
                need_sync += res;
            }
            else if ( !strcmp(src->hrec[i]->key,"fileformat") )
            {
                int ver_src = bcf_get_version(src,src->hrec[i]->value);
                int ver_dst = bcf_get_version(dst,dst->hrec[j]->value);
                if ( ver_src > ver_dst )
                {
                    if (bcf_hdr_set_version(dst,src->hrec[i]->value) < 0)
                        return NULL;
                    need_sync = 1;
                }
            }
        }
        else if ( src->hrec[i]->type==BCF_HL_STR )
        {
            // NB: we are ignoring fields without ID
            int j = bcf_hrec_find_key(src->hrec[i],"ID");
            if ( j>=0 )
            {
                bcf_hrec_t *rec = bcf_hdr_get_hrec(dst, src->hrec[i]->type, "ID", src->hrec[i]->vals[j], src->hrec[i]->key);
                if ( !rec ) {
                    res = bcf_hdr_add_hrec(dst, bcf_hrec_dup(src->hrec[i]));
                    if (res < 0) return NULL;
                    need_sync += res;
                }
            }
        }
        else
        {
            int j = bcf_hrec_find_key(src->hrec[i],"ID");
            assert( j>=0 ); // this should always be true for valid VCFs

            bcf_hrec_t *rec = bcf_hdr_get_hrec(dst, src->hrec[i]->type, "ID", src->hrec[i]->vals[j], NULL);
            if ( !rec ) {
                res = bcf_hdr_add_hrec(dst, bcf_hrec_dup(src->hrec[i]));
                if (res < 0) return NULL;
                need_sync += res;
            } else if ( src->hrec[i]->type==BCF_HL_INFO || src->hrec[i]->type==BCF_HL_FMT )
            {
                // Check that both records are of the same type. The bcf_hdr_id2length
                // macro cannot be used here because dst header is not synced yet.
                vdict_t *d_src = (vdict_t*)src->dict[BCF_DT_ID];
                vdict_t *d_dst = (vdict_t*)dst->dict[BCF_DT_ID];
                khint_t k_src  = kh_get(vdict, d_src, src->hrec[i]->vals[0]);
                khint_t k_dst  = kh_get(vdict, d_dst, src->hrec[i]->vals[0]);
                if ( (kh_val(d_src,k_src).info[rec->type]>>8 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>8 & 0xf) )
                {
                    hts_log_warning("Trying to combine \"%s\" tag definitions of different lengths",
                        src->hrec[i]->vals[0]);
                }
                if ( (kh_val(d_src,k_src).info[rec->type]>>4 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>4 & 0xf) )
                {
                    hts_log_warning("Trying to combine \"%s\" tag definitions of different types",
                        src->hrec[i]->vals[0]);
                }
            }
        }
    }
    if ( need_sync ) {
        if (bcf_hdr_sync(dst) < 0) return NULL;
    }
    return dst;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
testq %rdi, %rdi
je 0x3c0b8
movq %rdi, %r15
cmpl $0x0, 0x50(%r14)
jle 0x3c134
movl 0x50(%r15), %eax
movq %rax, 0x58(%rsp)
leaq 0x6e0e5(%rip), %rbx     # 0xa9d0a
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %r12
movl (%r12), %r13d
cmpl $0x4, %r13d
je 0x3bd81
movq %rbp, 0x8(%rsp)
cmpl $0x5, %r13d
jne 0x3bccb
movq 0x10(%r12), %rbp
testq %rbp, %rbp
je 0x3bccb
cmpl $0x0, 0x58(%rsp)
jle 0x3bc9d
movq 0x48(%r15), %r14
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rax
cmpl $0x5, (%rax)
jne 0x3bc93
movq 0x8(%r12), %r13
movq 0x8(%rax), %rsi
movq %r13, %rdi
callq 0x46e0
testl %eax, %eax
je 0x3bde6
incq %rbx
cmpq %rbx, 0x58(%rsp)
jne 0x3bc71
movq %r12, %rdi
callq 0x2acf6
movq %r15, %rdi
movq %rax, %rsi
callq 0x2bd95
testl %eax, %eax
movq 0x20(%rsp), %r14
movq 0x8(%rsp), %rbp
js 0x3c124
addl %eax, 0x4(%rsp)
jmp 0x3c044
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2b32b
testl %eax, %eax
js 0x3c146
movq 0x28(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq %r15, %rdi
movl %r13d, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x2ce51
movq %rax, %r12
movq 0x48(%r14), %rax
movq 0x8(%rsp), %rbp
movq (%rax,%rbp,8), %rdi
testq %r12, %r12
je 0x3bdc5
movl (%rdi), %eax
decl %eax
cmpl $0x1, %eax
ja 0x3c04b
movq 0x28(%r14), %rsi
movq 0x28(%r15), %r13
movq 0x28(%rdi), %rax
movq (%rax), %r8
movl (%rsi), %edx
xorl %edi, %edi
movl $0x0, %eax
testl %edx, %edx
movq %r12, 0x38(%rsp)
movq %r8, 0x50(%rsp)
movq %r13, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
je 0x3bebf
movb (%r8), %cl
testb %cl, %cl
je 0x3be13
leaq 0x1(%r8), %rax
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %ebp, %ecx
imull $0x1000193, %ecx, %ebp  # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x3bd68
jmp 0x3be18
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2b32b
testl %eax, %eax
js 0x3c04b
movq 0x8(%r12), %r8
movq 0x28(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq %r15, %rdi
movl $0x4, %esi
movq %rbx, %rdx
callq 0x2ce51
testq %rax, %rax
jne 0x3c04b
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rdi
callq 0x2acf6
movq %r15, %rdi
movq %rax, %rsi
callq 0x2bd95
testl %eax, %eax
js 0x3c124
addl %eax, 0x4(%rsp)
jmp 0x3c04b
movq %r13, %rdi
leaq 0x6f95a(%rip), %rsi     # 0xab74a
callq 0x46e0
testl %eax, %eax
je 0x3c060
movq 0x20(%rsp), %r14
leaq 0x6df01(%rip), %rbx     # 0xa9d0a
movq 0x8(%rsp), %rbp
jmp 0x3c04b
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq %rdx, 0x10(%rsp)
leal -0x1(%rdx), %r12d
andl %r12d, %ebp
movq 0x10(%rsi), %rsi
movl $0x1, %ebx
movl %ebp, %r14d
movq %rsi, 0x40(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r15d
leal (%r14,%r14), %r13d
andl $0x1e, %r13d
movl %r15d, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3be91
testb $0x1, %al
jne 0x3be7d
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x46e0
movq 0x40(%rsp), %rsi
movq 0x50(%rsp), %r8
testl %eax, %eax
je 0x3be91
addl %ebx, %r14d
andl %r12d, %r14d
incl %ebx
cmpl %ebp, %r14d
jne 0x3be35
movq 0x10(%rsp), %rax
jmp 0x3bea4
movl %r13d, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x10(%rsp), %rax
cmovel %r14d, %eax
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rbp
movq 0x38(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rsi
xorl %edi, %edi
movl (%r13), %edx
testl %edx, %edx
je 0x3bfa5
movl %eax, 0x10(%rsp)
movb (%r8), %cl
testb %cl, %cl
je 0x3bef5
leaq 0x1(%r8), %rax
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %ebp, %ecx
imull $0x1000193, %ecx, %ebp  # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x3bedf
jmp 0x3befa
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq %rdx, 0x48(%rsp)
leal -0x1(%rdx), %r12d
andl %r12d, %ebp
movq 0x10(%r13), %rsi
movl $0x1, %ebx
movl %ebp, %r14d
movq %rsi, 0x40(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r15d
leal (%r14,%r14), %r13d
andl $0x1e, %r13d
movl %r15d, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3bf73
testb $0x1, %al
jne 0x3bf5f
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x46e0
movq 0x40(%rsp), %rsi
movq 0x50(%rsp), %r8
testl %eax, %eax
je 0x3bf73
addl %ebx, %r14d
andl %r12d, %r14d
incl %ebx
cmpl %ebp, %r14d
jne 0x3bf17
movq 0x48(%rsp), %rax
jmp 0x3bf86
movl %r13d, %ecx
shrl %cl, %r15d
testb $0x3, %r15b
movq 0x48(%rsp), %rax
cmovel %r14d, %eax
movl %eax, %edi
movq 0x18(%rsp), %r15
movq 0x8(%rsp), %rbp
movq 0x38(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rsi
movl 0x10(%rsp), %eax
movl %eax, %eax
imulq $0x38, %rax, %rbx
movq 0x20(%rsi), %rcx
addq %rbx, %rcx
movslq (%r12), %rdx
movl %edi, %eax
imulq $0x38, %rax, %r14
movq 0x20(%r13), %rax
addq %r14, %rax
movq (%rax,%rdx,8), %rax
xorq (%rcx,%rdx,8), %rax
testl $0xf00, %eax            # imm = 0xF00
je 0x3c00b
movl $0x3, %edi
movq %rsi, %r15
leaq 0x7003e(%rip), %rsi     # 0xac01f
leaq 0x6ff88(%rip), %rdx     # 0xabf70
movq %r8, %rcx
xorl %eax, %eax
callq 0x942d
addq 0x20(%r15), %rbx
movq 0x18(%rsp), %r15
addq 0x20(%r13), %r14
movslq (%r12), %rcx
movq (%r14,%rcx,8), %rax
xorq (%rbx,%rcx,8), %rax
testb $-0x10, %al
je 0x3c03f
movq 0x20(%rsp), %r14
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
movl $0x3, %edi
leaq 0x6fff0(%rip), %rsi     # 0xac01f
leaq 0x6ff76(%rip), %rdx     # 0xabfac
xorl %eax, %eax
callq 0x942d
jmp 0x3c044
movq 0x20(%rsp), %r14
leaq 0x6dcbf(%rip), %rbx     # 0xa9d0a
incq %rbp
movslq 0x50(%r14), %rax
cmpq %rax, %rbp
jl 0x3bc39
jmp 0x3c111
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2bc61
movl %eax, %ebp
movq 0x48(%r15), %rax
movq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rsi
movq %r15, %rdi
callq 0x2bc61
cmpl %eax, %ebp
leaq 0x6dc7b(%rip), %rbx     # 0xa9d0a
movq 0x8(%rsp), %rbp
jle 0x3c04b
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rax
movq 0x10(%rax), %rsi
movq %r15, %rdi
callq 0x2de88
movl $0x1, 0x4(%rsp)
testl %eax, %eax
jns 0x3c04b
jmp 0x3c124
leaq 0x6e11b(%rip), %rdi     # 0xaa1da
callq 0x2df79
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %r15
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2f5bf
movq 0x10(%r15), %rsi
testl %eax, %eax
js 0x3c129
movq %rbx, %rdi
callq 0x2d4f2
testl %eax, %eax
movq %rbx, %r15
jns 0x3c10a
movq %r15, %rdi
callq 0x2e474
xorl %r15d, %r15d
movq 0x70(%rsp), %rsi
jmp 0x3c12c
cmpl $0x0, 0x4(%rsp)
je 0x3c134
movq %r15, %rdi
callq 0x2ab97
testl %eax, %eax
jns 0x3c134
xorl %r15d, %r15d
jmp 0x3c134
xorl %r15d, %r15d
movq %rsi, %rdi
callq 0x45c0
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6fdda(%rip), %rdi     # 0xabf27
leaq 0x6f47f(%rip), %rsi     # 0xab5d3
leaq 0x6fe8b(%rip), %rcx     # 0xabfe6
movl $0x127f, %edx           # imm = 0x127F
callq 0x42e0