// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movq %rsi, %r15
testq %rdi, %rdi
je 0x3cf23
movq %rdi, %r14
cmpl $0x0, 0x50(%r15)
jle 0x3cf9f
movslq 0x50(%r14), %r13
movl %r13d, %eax
testl %eax, %eax
setg 0xb(%rsp)
negq %rax
movq %rax, 0x68(%rsp)
leaq 0x7037a(%rip), %rbp     # 0xacd57
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movq %r14, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movq %r13, 0x60(%rsp)
movq 0x48(%r15), %rax
movq (%rax,%rbx,8), %r12
movl (%r12), %r13d
cmpl $0x4, %r13d
je 0x3ca93
cmpl $0x5, %r13d
jne 0x3cb09
movq 0x10(%r12), %rbp
testq %rbp, %rbp
je 0x3ca86
movq %rbx, 0x10(%rsp)
movq 0x60(%rsp), %r13
testl %r13d, %r13d
jle 0x3cc0e
movq 0x20(%rsp), %rax
movq 0x48(%rax), %r14
movl $0x1, %ebx
movb 0xb(%rsp), %r15b
movq -0x8(%r14,%rbx,8), %rax
cmpl $0x5, (%rax)
jne 0x3ca66
movq 0x8(%r12), %rdi
movq 0x8(%rax), %rsi
callq 0x46e0
testl %eax, %eax
je 0x3cbe5
cmpq %r13, %rbx
setl %r15b
movq 0x68(%rsp), %rax
addq %rbx, %rax
incq %rax
incq %rbx
cmpq $0x1, %rax
jne 0x3ca46
jmp 0x3cc0e
cmpl $0x4, %r13d
leaq 0x702c6(%rip), %rbp     # 0xacd57
jne 0x3cb09
movq %rbx, 0x10(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2c40b
movb $0x1, %bl
testl %eax, %eax
js 0x3cafd
movq 0x8(%r12), %r8
movq 0x28(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq %r14, %r12
movq %r14, %rdi
movl %r13d, %esi
movq %rbp, %rdx
callq 0x2dff0
testq %rax, %rax
jne 0x3cafd
movq 0x48(%r15), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2bdad
movq %r12, %rdi
movq %rax, %rsi
callq 0x2ce41
testl %eax, %eax
setns %bl
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %eax, 0xc(%rsp)
testb %bl, %bl
movq 0x10(%rsp), %rbx
jmp 0x3ce91
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2c40b
testl %eax, %eax
js 0x3cfb4
movq 0x28(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq %r14, %rdi
movl %r13d, %esi
movq %rbp, %rdx
xorl %r8d, %r8d
callq 0x2dff0
movq %rax, %r12
movq 0x48(%r15), %rax
movq (%rax,%rbx,8), %rdi
testq %r12, %r12
je 0x3cbbe
movl (%rdi), %eax
decl %eax
movb $0x1, %bpl
cmpl $0x1, %eax
ja 0x3ce8e
movq 0x28(%r15), %rcx
movq 0x28(%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rdi), %rax
movq (%rax), %r8
movq %rcx, 0x40(%rsp)
movl (%rcx), %esi
xorl %edx, %edx
movl $0x0, %ecx
testl %esi, %esi
movq %r12, 0x38(%rsp)
movq %r8, 0x58(%rsp)
movq %rbx, 0x10(%rsp)
je 0x3ccfb
movb (%r8), %cl
testb %cl, %cl
je 0x3cc57
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 0x3cba5
jmp 0x3cc5c
callq 0x2bdad
movq %r14, %rdi
movq %rax, %rsi
callq 0x2ce41
testl %eax, %eax
setns %bpl
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %eax, 0xc(%rsp)
jmp 0x3ce8e
testb $0x1, %r15b
je 0x3cc0e
movq 0x8(%r12), %rdi
leaq 0x71ba3(%rip), %rsi     # 0xae79a
callq 0x46e0
movb $0x1, %r15b
testl %eax, %eax
je 0x3ceb3
movq 0x20(%rsp), %r14
jmp 0x3cc38
movq %r12, %rdi
callq 0x2bdad
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x2ce41
testl %eax, %eax
setns %r15b
movl $0x0, %ecx
cmovlel %ecx, %eax
addl %eax, 0xc(%rsp)
leaq 0x70118(%rip), %rbp     # 0xacd57
movq 0x10(%rsp), %rbx
testb %r15b, %r15b
movq 0x18(%rsp), %r15
jne 0x3ce9e
jmp 0x3cf8f
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq %rsi, 0x28(%rsp)
leal -0x1(%rsi), %r12d
andl %r12d, %ebp
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %r15d
movl %ebp, %ebx
movq %rsi, 0x48(%rsp)
movl %ebx, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r14d
leal (%rbx,%rbx), %r13d
andl $0x1e, %r13d
movl %r14d, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3ccd8
testb $0x1, %al
jne 0x3ccc4
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x46e0
movq 0x48(%rsp), %rsi
movq 0x58(%rsp), %r8
testl %eax, %eax
je 0x3ccd8
addl %r15d, %ebx
andl %r12d, %ebx
incl %r15d
cmpl %ebp, %ebx
jne 0x3cc7e
movq 0x28(%rsp), %rax
jmp 0x3ccea
movl %r13d, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x28(%rsp), %rax
cmovel %ebx, %eax
movl %eax, %ecx
movq 0x18(%rsp), %r15
movb $0x1, %bpl
movq 0x38(%rsp), %r12
xorl %edx, %edx
movq 0x30(%rsp), %rax
movl (%rax), %esi
testl %esi, %esi
je 0x3cdda
movl %ecx, 0x28(%rsp)
movb (%r8), %cl
testb %cl, %cl
je 0x3cd34
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 0x3cd1e
jmp 0x3cd39
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq %rsi, 0x50(%rsp)
leal -0x1(%rsi), %r12d
andl %r12d, %ebp
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %r15d
movl %ebp, %ebx
movq %rsi, 0x48(%rsp)
movl %ebx, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r14d
leal (%rbx,%rbx), %r13d
andl $0x1e, %r13d
movl %r14d, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3cdb5
testb $0x1, %al
jne 0x3cda1
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x46e0
movq 0x48(%rsp), %rsi
movq 0x58(%rsp), %r8
testl %eax, %eax
je 0x3cdb5
addl %r15d, %ebx
andl %r12d, %ebx
incl %r15d
cmpl %ebp, %ebx
jne 0x3cd5b
movq 0x50(%rsp), %rax
jmp 0x3cdc7
movl %r13d, %ecx
shrl %cl, %r14d
testb $0x3, %r14b
movq 0x50(%rsp), %rax
cmovel %ebx, %eax
movl %eax, %edx
movq 0x18(%rsp), %r15
movb $0x1, %bpl
movq 0x38(%rsp), %r12
movl 0x28(%rsp), %ecx
movl %ecx, %eax
imulq $0x38, %rax, %rbx
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
addq %rbx, %rax
movslq (%r12), %rcx
movl %edx, %edx
imulq $0x38, %rdx, %r14
movq 0x30(%rsp), %rdx
movq 0x20(%rdx), %rdx
addq %r14, %rdx
movl (%rdx,%rcx,8), %edx
xorl (%rax,%rcx,8), %edx
testl $0xf00, %edx            # imm = 0xF00
je 0x3ce2d
movl $0x3, %edi
leaq 0x72253(%rip), %rsi     # 0xaf06f
leaq 0x7219d(%rip), %rdx     # 0xaefc0
movq %r8, %rcx
xorl %eax, %eax
callq 0x9774
movq 0x40(%rsp), %rax
addq 0x20(%rax), %rbx
movslq (%r12), %rax
movq 0x30(%rsp), %rcx
addq 0x20(%rcx), %r14
movl (%r14,%rax,8), %ecx
xorl (%rbx,%rax,8), %ecx
testb $-0x10, %cl
je 0x3ce84
movq 0x48(%r15), %rax
movq 0x10(%rsp), %rbx
movq (%rax,%rbx,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
movl $0x3, %edi
leaq 0x72200(%rip), %rsi     # 0xaf06f
leaq 0x72186(%rip), %rdx     # 0xaeffc
xorl %eax, %eax
callq 0x9774
movq 0x20(%rsp), %r14
jmp 0x3ce8e
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rbx
testb %bpl, %bpl
leaq 0x6febf(%rip), %rbp     # 0xacd57
je 0x3cf8f
incq %rbx
movslq 0x50(%r15), %rax
cmpq %rax, %rbx
jl 0x3c9f6
jmp 0x3cf7c
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2cd13
movl %eax, %ebp
movq 0x20(%rsp), %r14
movq 0x48(%r14), %rax
movq -0x8(%rax,%rbx,8), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x2cd13
cmpl %eax, %ebp
jle 0x3cc38
movq 0x48(%r12), %rax
movq 0x10(%rsp), %rbx
movq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x2f058
testl %eax, %eax
setns %r15b
movl $0x1, %eax
movl 0xc(%rsp), %ecx
cmovnsl %eax, %ecx
movl %ecx, 0xc(%rsp)
leaq 0x6fe39(%rip), %rbp     # 0xacd57
jmp 0x3cc44
leaq 0x70305(%rip), %rdi     # 0xad22f
callq 0x2f149
movq %rax, %r14
xorps %xmm0, %xmm0
movq %r15, %rdi
leaq 0x70(%rsp), %r15
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
xorl %esi, %esi
movq %r15, %rdx
callq 0x30754
movq 0x10(%r15), %rsi
testl %eax, %eax
js 0x3cf94
movq %r14, %rdi
callq 0x2e6a1
testl %eax, %eax
jns 0x3cf72
movq %r14, %rdi
callq 0x2f696
xorl %r14d, %r14d
movq 0x80(%rsp), %rsi
jmp 0x3cf97
cmpl $0x0, 0xc(%rsp)
je 0x3cf9f
movq %r14, %rdi
callq 0x2bc46
testl %eax, %eax
jns 0x3cf9f
xorl %r14d, %r14d
jmp 0x3cf9f
xorl %r14d, %r14d
movq %rsi, %rdi
callq 0x45c0
movq %r14, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x71fbc(%rip), %rdi     # 0xaef77
leaq 0x71661(%rip), %rsi     # 0xae623
leaq 0x7206d(%rip), %rcx     # 0xaf036
movl $0x127f, %edx           # imm = 0x127F
callq 0x42e0