// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rsi, %rbp
testq %rdi, %rdi
je 0x2cff4
movq %rdi, %rbx
movl 0x50(%rdi), %r14d
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
movq %rbp, 0x10(%rsp)
movslq 0x50(%rbp), %rax
cmpq %rax, %r12
jge 0x2cfdd
movq 0x48(%rbp), %rax
movq (%rax,%r12,8), %r13
movl (%r13), %ebp
cmpl $0x4, %ebp
je 0x2cee4
cmpl $0x5, %ebp
jne 0x2cda8
movq 0x10(%r13), %rax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x2cda8
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0x2cf4a
movq 0x48(%rbx), %rax
movq (%rax,%rbp,8), %rax
cmpl $0x5, (%rax)
jne 0x2cda3
movq 0x8(%r13), %r15
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x46e0
testl %eax, %eax
je 0x2cf6b
incq %rbp
jmp 0x2cd75
movq %r13, %rdi
leaq 0x57f23(%rip), %r15     # 0x84cd5
movq %r15, %rsi
callq 0x22ef9
testl %eax, %eax
js 0x2d062
movq 0x28(%r13), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x244fd
movq %rax, %r13
movq 0x10(%rsp), %rbp
movq 0x48(%rbp), %rax
movq (%rax,%r12,8), %rdi
testq %r13, %r13
je 0x2cf2c
movl (%rdi), %eax
decl %eax
cmpl $0x1, %eax
ja 0x2cf83
movq 0x28(%rbp), %r15
movq 0x28(%rbx), %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rdi), %rax
movq (%rax), %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0x246ef
movl %eax, 0x20(%rsp)
movq 0x18(%rsp), %rdi
movq %rbp, 0x28(%rsp)
movq %rbp, %rsi
callq 0x246ef
movl 0x20(%rsp), %ecx
imulq $0x38, %rcx, %rbp
movq %r15, 0x20(%rsp)
movq 0x20(%r15), %rcx
addq %rbp, %rcx
movslq (%r13), %rdx
movl %eax, %eax
imulq $0x38, %rax, %r15
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
addq %r15, %rax
movq (%rax,%rdx,8), %rax
xorq (%rcx,%rdx,8), %rax
testw $0xf00, %ax             # imm = 0xF00
je 0x2ceab
pushq $0x3
popq %rdi
leaq 0x59f02(%rip), %rsi     # 0x86d7b
leaq 0x59e4c(%rip), %rdx     # 0x86ccc
movq 0x28(%rsp), %rcx
xorl %eax, %eax
callq 0x8132
movq 0x20(%rsp), %rax
addq 0x20(%rax), %rbp
movq 0x18(%rsp), %rax
addq 0x20(%rax), %r15
movslq (%r13), %rcx
movq (%r15,%rcx,8), %rax
xorq (%rbp,%rcx,8), %rax
testb $-0x10, %al
je 0x2cf7e
movq 0x10(%rsp), %rbp
movq 0x48(%rbp), %rax
movq (%rax,%r12,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
pushq $0x3
popq %rdi
leaq 0x59eaa(%rip), %rsi     # 0x86d7b
leaq 0x59e30(%rip), %rdx     # 0x86d08
xorl %eax, %eax
callq 0x8132
jmp 0x2cf83
movq %r13, %rdi
leaq 0x57de7(%rip), %r15     # 0x84cd5
movq %r15, %rsi
callq 0x22ef9
testl %eax, %eax
js 0x2cf7e
movq 0x8(%r13), %r8
movq 0x28(%r13), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rcx
movq %rbx, %rdi
pushq $0x4
popq %rsi
movq %r15, %rdx
callq 0x244fd
testq %rax, %rax
movq 0x10(%rsp), %rbp
jne 0x2cf83
movq 0x48(%rbp), %rax
movq (%rax,%r12,8), %rdi
callq 0x228bb
movq %rbx, %rdi
movq %rax, %rsi
callq 0x238dd
testl %eax, %eax
js 0x2cff0
addl %eax, 0xc(%rsp)
jmp 0x2cf83
movq %r13, %rdi
callq 0x228bb
movq %rbx, %rdi
movq %rax, %rsi
callq 0x238dd
testl %eax, %eax
js 0x2cff0
addl %eax, 0xc(%rsp)
jmp 0x2cf7e
movq %r15, %rdi
leaq 0x59525(%rip), %rsi     # 0x8649a
callq 0x46e0
testl %eax, %eax
je 0x2cf8b
movq 0x10(%rsp), %rbp
incq %r12
jmp 0x2cd3e
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x237b5
movl %eax, %r15d
movq 0x48(%rbx), %rax
movq (%rax,%rbp,8), %rax
movq %r13, %rbp
movq 0x10(%rax), %rsi
movq %rbx, %rdi
callq 0x237b5
cmpl %eax, %r15d
jle 0x2cf83
movq 0x48(%rbp), %rax
movq (%rax,%r12,8), %rax
movq 0x10(%rax), %rsi
movq %rbx, %rdi
callq 0x24fdf
pushq $0x1
popq %rcx
movl %ecx, 0xc(%rsp)
testl %eax, %eax
jns 0x2cf83
jmp 0x2cff0
cmpl $0x0, 0xc(%rsp)
je 0x2d050
movq %rbx, %rdi
callq 0x2276e
testl %eax, %eax
jns 0x2d050
xorl %ebx, %ebx
jmp 0x2d050
leaq 0x581aa(%rip), %rdi     # 0x851a5
callq 0x250c7
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movq %rbp, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x25ea7
movq 0x10(%r15), %rsi
testl %eax, %eax
js 0x2d046
movq %rbx, %rdi
callq 0x248c9
testl %eax, %eax
jns 0x2d03f
movq %rbx, %rdi
callq 0x25554
xorl %ebx, %ebx
movq 0x40(%rsp), %rsi
jmp 0x2d048
xorl %ebx, %ebx
movq %rsi, %rdi
callq 0x45c0
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x59c1a(%rip), %rdi     # 0x86c83
leaq 0x592b3(%rip), %rsi     # 0x86323
leaq 0x59ccb(%rip), %rcx     # 0x86d42
movl $0x127f, %edx           # imm = 0x127F
callq 0x42e0