// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x4b511
leaq 0xbafdb(%rip), %rdi     # 0x106470
callq 0x3f560
movq %rax, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4240
movq -0x18(%rbp), %rdi
xorl %esi, %esi
leaq -0x30(%rbp), %rdx
callq 0x409c0
cmpl $0x0, %eax
jge 0x4b4d8
movq -0x20(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x4ba86
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3e890
cmpl $0x0, %eax
jge 0x4b4fb
movq -0x10(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x10(%rbp)
movq -0x20(%rbp), %rdi
callq 0x45a0
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4ba86
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x50(%rcx), %eax
jge 0x4ba5e
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x5, (%rax)
jne 0x4b6df
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq $0x0, 0x10(%rax)
je 0x4b6df
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x4b5d4
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x5, (%rax)
je 0x4b593
jmp 0x4b5c9
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rsi
callq 0x46b0
cmpl $0x0, %eax
jne 0x4b5c7
jmp 0x4b5d4
jmp 0x4b5c9
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4b574
movl -0x44(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x4b62f
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3b0f0
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x3ce30
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jge 0x4b621
movq $0x0, -0x8(%rbp)
jmp 0x4ba86
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x4b6da
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0xbc190(%rip), %rsi     # 0x1077da
callq 0x46b0
cmpl $0x0, %eax
jne 0x4b6d8
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rsi
callq 0x3cc20
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rsi
callq 0x3cc20
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jle 0x4b6d6
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rsi
callq 0x3f420
cmpl $0x0, %eax
jge 0x4b6cf
movq $0x0, -0x8(%rbp)
jmp 0x4ba86
movl $0x1, -0x3c(%rbp)
jmp 0x4b6d8
jmp 0x4b6da
jmp 0x4ba4e
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x4, (%rax)
jne 0x4b7d3
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xba889(%rip), %rsi     # 0x105f98
callq 0x3bb40
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0x4b7ce
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movslq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq 0x8(%rax), %r8
leaq 0xba82a(%rip), %rdx     # 0x105f98
callq 0x3e160
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x4b7cc
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3b0f0
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x3ce30
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jge 0x4b7c3
movq $0x0, -0x8(%rbp)
jmp 0x4ba86
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x4b7ce
jmp 0x4ba4c
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0xba7ae(%rip), %rsi     # 0x105f98
callq 0x3bb40
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x4b7fa
jmp 0x4b819
leaq 0xbc7f6(%rip), %rdi     # 0x107ff7
leaq 0xbbe5b(%rip), %rsi     # 0x107663
movl $0x127f, %edx           # imm = 0x127F
leaq 0xbc8a2(%rip), %rcx     # 0x1080b6
callq 0x42d0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %esi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0xba746(%rip), %rdx     # 0x105f98
xorl %eax, %eax
movl %eax, %r8d
callq 0x3e160
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x4b8ba
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3b0f0
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x3ce30
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jge 0x4b8ac
movq $0x0, -0x8(%rbp)
jmp 0x4ba86
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x4ba4a
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x1, (%rax)
je 0x4b8e8
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x2, (%rax)
jne 0x4ba48
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
callq 0x3e520
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rsi
callq 0x3e520
movl %eax, -0x80(%rbp)
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x7c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq -0x68(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x8, %rax
andq $0xf, %rax
movq -0x78(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x80(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movq -0x68(%rbp), %rdx
movslq (%rdx), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x8, %rcx
andq $0xf, %rcx
cmpq %rcx, %rax
je 0x4b9c6
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
movl $0x3, %edi
leaq 0xbc737(%rip), %rsi     # 0x1080ef
leaq 0xbc681(%rip), %rdx     # 0x108040
movb $0x0, %al
callq 0x9d90
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x7c(%rbp), %ecx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq -0x68(%rbp), %rcx
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x4, %rax
andq $0xf, %rax
movq -0x78(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x80(%rbp), %edx
imulq $0x38, %rdx, %rdx
addq %rdx, %rcx
movq -0x68(%rbp), %rdx
movslq (%rdx), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x4, %rcx
andq $0xf, %rcx
cmpq %rcx, %rax
je 0x4ba46
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rax), %rax
movq (%rax), %rcx
movl $0x3, %edi
leaq 0xbc6b7(%rip), %rsi     # 0x1080ef
leaq 0xbc63d(%rip), %rdx     # 0x10807c
movb $0x0, %al
callq 0x9d90
jmp 0x4ba48
jmp 0x4ba4a
jmp 0x4ba4c
jmp 0x4ba4e
jmp 0x4ba50
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4b529
cmpl $0x0, -0x3c(%rbp)
je 0x4ba7e
movq -0x10(%rbp), %rdi
callq 0x3ae50
cmpl $0x0, %eax
jge 0x4ba7c
movq $0x0, -0x8(%rbp)
jmp 0x4ba86
jmp 0x4ba7e
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)