// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/vcf.c
// Function: bcf_translate
int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line)
{
    int i;
    if ( line->errcode )
    {
        char errordescription[1024] = "";
        hts_log_error("Unchecked error (%d %s) at %s:%"PRIhts_pos", exiting", line->errcode, bcf_strerror(line->errcode, errordescription, sizeof(errordescription)),  bcf_seqname_safe(src_hdr,line), line->pos+1);
        exit(1);
    }
    if ( src_hdr->ntransl==-1 ) return 0;    // no need to translate, all tags have the same id
    if ( !src_hdr->ntransl )  // called for the first time, see what needs translating
    {
        int dict;
        for (dict=0; dict<2; dict++)    // BCF_DT_ID and BCF_DT_CTG
        {
            src_hdr->transl[dict] = (int*) malloc(src_hdr->n[dict]*sizeof(int));
            for (i=0; i<src_hdr->n[dict]; i++)
            {
                if ( !src_hdr->id[dict][i].key ) // gap left after removed BCF header lines
                {
                    src_hdr->transl[dict][i] = -1;
                    continue;
                }
                src_hdr->transl[dict][i] = bcf_hdr_id2int(dst_hdr,dict,src_hdr->id[dict][i].key);
                if ( src_hdr->transl[dict][i]!=-1 && i!=src_hdr->transl[dict][i] ) src_hdr->ntransl++;
            }
        }
        if ( !src_hdr->ntransl )
        {
            free(src_hdr->transl[0]); src_hdr->transl[0] = NULL;
            free(src_hdr->transl[1]); src_hdr->transl[1] = NULL;
            src_hdr->ntransl = -1;
        }
        if ( src_hdr->ntransl==-1 ) return 0;
    }
    bcf_unpack(line,BCF_UN_ALL);

    // CHROM
    if ( src_hdr->transl[BCF_DT_CTG][line->rid] >=0 ) line->rid = src_hdr->transl[BCF_DT_CTG][line->rid];

    // FILTER
    for (i=0; i<line->d.n_flt; i++)
    {
        int src_id = line->d.flt[i];
        if ( src_hdr->transl[BCF_DT_ID][src_id] >=0 )
            line->d.flt[i] = src_hdr->transl[BCF_DT_ID][src_id];
        line->d.shared_dirty |= BCF1_DIRTY_FLT;
    }

    // INFO
    for (i=0; i<line->n_info; i++)
    {
        int src_id = line->d.info[i].key;
        int dst_id = src_hdr->transl[BCF_DT_ID][src_id];
        if ( dst_id<0 ) continue;
        line->d.info[i].key = dst_id;
        if ( !line->d.info[i].vptr ) continue;  // skip deleted
        int src_size = src_id>>7 ? ( src_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8;
        int dst_size = dst_id>>7 ? ( dst_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8;
        if ( src_size==dst_size )   // can overwrite
        {
            uint8_t *vptr = line->d.info[i].vptr - line->d.info[i].vptr_off;
            if ( dst_size==BCF_BT_INT8 ) { vptr[1] = (uint8_t)dst_id; }
            else if ( dst_size==BCF_BT_INT16 ) { *(uint16_t*)vptr = (uint16_t)dst_id; }
            else { *(uint32_t*)vptr = (uint32_t)dst_id; }
        }
        else    // must realloc
        {
            bcf_info_t *info = &line->d.info[i];
            kstring_t str = {0,0,0};
            bcf_enc_int1(&str, dst_id);
            bcf_enc_size(&str, info->len,info->type);
            uint32_t vptr_off = str.l;
            kputsn((char*)info->vptr, info->vptr_len, &str);
            if( info->vptr_free ) free(info->vptr - info->vptr_off);
            info->vptr_off = vptr_off;
            info->vptr = (uint8_t*)str.s + info->vptr_off;
            info->vptr_free = 1;
            line->d.shared_dirty |= BCF1_DIRTY_INF;
        }
    }

    // FORMAT
    for (i=0; i<line->n_fmt; i++)
    {
        int src_id = line->d.fmt[i].id;
        int dst_id = src_hdr->transl[BCF_DT_ID][src_id];
        if ( dst_id<0 ) continue;
        line->d.fmt[i].id = dst_id;
        if( !line->d.fmt[i].p ) continue;  // skip deleted
        int src_size = src_id>>7 ? ( src_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8;
        int dst_size = dst_id>>7 ? ( dst_id>>15 ? BCF_BT_INT32 : BCF_BT_INT16) : BCF_BT_INT8;
        if ( src_size==dst_size )   // can overwrite
        {
            uint8_t *p = line->d.fmt[i].p - line->d.fmt[i].p_off;    // pointer to the vector size (4bits) and BT type (4bits)
            if ( dst_size==BCF_BT_INT8 ) { p[1] = dst_id; }
            else if ( dst_size==BCF_BT_INT16 ) { i16_to_le(dst_id, p + 1); }
            else { i32_to_le(dst_id, p + 1); }
        }
        else    // must realloc
        {
            bcf_fmt_t *fmt = &line->d.fmt[i];
            kstring_t str = {0,0,0};
            bcf_enc_int1(&str, dst_id);
            bcf_enc_size(&str, fmt->n, fmt->type);
            uint32_t p_off = str.l;
            kputsn((char*)fmt->p, fmt->p_len, &str);
            if( fmt->p_free ) free(fmt->p - fmt->p_off);
            fmt->p_off = p_off;
            fmt->p = (uint8_t*)str.s + fmt->p_off;
            fmt->p_free = 1;
            line->d.indiv_dirty = 1;
        }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rdx, %r12
movq %rsi, %r14
movl 0xcc(%rdx), %ebp
testl %ebp, %ebp
jne 0x3d7f1
movl 0x58(%r14), %eax
cmpl $-0x1, %eax
je 0x3d7dd
testl %eax, %eax
movq %r12, 0x38(%rsp)
jne 0x3d0ce
movq %rdi, %r15
xorl %r12d, %r12d
movslq (%r14,%r12,4), %rbx
leaq (,%rbx,4), %rdi
callq 0x46a0
movq %rax, 0x60(%r14,%r12,8)
testq %rbx, %rbx
jle 0x3d086
movq %rax, %r13
movq 0x10(%r14,%r12,8), %rbx
xorl %ebp, %ebp
movq (%rbx), %rdx
testq %rdx, %rdx
je 0x3d06d
movq %r15, %rdi
movl %r12d, %esi
callq 0x2e585
movl %eax, (%r13,%rbp,4)
cmpl $-0x1, %eax
sete %cl
movl %eax, %eax
cmpq %rax, %rbp
sete %al
orb %cl, %al
jne 0x3d076
incl 0x58(%r14)
jmp 0x3d076
movl $0xffffffff, (%r13,%rbp,4) # imm = 0xFFFFFFFF
incq %rbp
movslq (%r14,%r12,4), %rax
addq $0x10, %rbx
cmpq %rax, %rbp
jl 0x3d03d
leaq 0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
je 0x3d018
cmpl $0x0, 0x58(%r14)
jne 0x3d0be
movq 0x60(%r14), %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, 0x60(%r14)
movq 0x68(%r14), %rdi
callq 0x45c0
movq %rbx, 0x68(%r14)
movl $0xffffffff, 0x58(%r14) # imm = 0xFFFFFFFF
cmpl $-0x1, 0x58(%r14)
movq 0x38(%rsp), %r12
je 0x3d7dd
movq %r12, %rdi
movl $0xf, %esi
callq 0x38e9d
movq 0x68(%r14), %rax
movslq 0x10(%r12), %rcx
movl (%rax,%rcx,4), %eax
testl %eax, %eax
js 0x3d0f0
movl %eax, 0x10(%r12)
cmpl $0x0, 0x68(%r12)
jle 0x3d127
movq 0x70(%r12), %rax
movq 0x60(%r14), %rcx
xorl %edx, %edx
movslq (%rax,%rdx,4), %rsi
movl (%rcx,%rsi,4), %esi
testl %esi, %esi
js 0x3d111
movl %esi, (%rax,%rdx,4)
orb $0x4, 0xb0(%r12)
incq %rdx
movslq 0x68(%r12), %rsi
cmpq %rsi, %rdx
jl 0x3d103
cmpw $0x0, 0x18(%r12)
je 0x3d480
movl $0x20, %ebp
xorl %ebx, %ebx
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
movq 0x90(%r12), %r13
movslq -0x20(%r13,%rbp), %rcx
movq 0x60(%r14), %rax
movl (%rax,%rcx,4), %r15d
testl %r15d, %r15d
js 0x3d452
movl %r15d, -0x20(%r13,%rbp)
cmpq $0x0, -0x10(%r13,%rbp)
je 0x3d452
cmpl %r8d, %ecx
movl $0x3, %edx
sbbl $0x0, %edx
cmpl %r8d, %r15d
movl $0x3, %eax
sbbl $0x0, %eax
xorl %esi, %esi
cmpl %r9d, %r15d
cmovbl %r10d, %eax
setb %sil
xorl %edi, %edi
cmpl %eax, %edx
sete %dil
cmpl %r9d, %ecx
cmovael %edi, %esi
cmpb $0x1, %sil
jne 0x3d1da
movq -0x10(%r13,%rbp), %rcx
movl -0x4(%r13,%rbp), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
negq %rdx
cmpl $0x2, %eax
je 0x3d208
cmpl $0x1, %eax
jne 0x3d212
movb %r15b, 0x1(%rcx,%rdx)
jmp 0x3d452
movl $0x7, %edi
callq 0x46a0
testq %rax, %rax
je 0x3d200
movl %r15d, %ecx
negl %ecx
jo 0x3d21b
cmpl $0x80000001, %r15d      # imm = 0x80000001
jne 0x3d222
movw $0x8111, (%rax)         # imm = 0x8111
jmp 0x3d233
xorl %edx, %edx
xorl %esi, %esi
xorl %eax, %eax
jmp 0x3d23d
movw %r15w, (%rcx,%rdx)
jmp 0x3d452
movl %r15d, (%rcx,%rdx)
jmp 0x3d452
movw $0x8011, (%rax)         # imm = 0x8011
jmp 0x3d233
cmpl $0x7f, %r15d
ja 0x3d354
movb $0x11, (%rax)
movb %r15b, 0x1(%rax)
movl $0x7, %esi
movl $0x2, %edx
movl -0x1c(%r13,%rbp), %edi
movl (%r13,%rbp), %r12d
cmpl $0xe, %r12d
jg 0x3d25d
leaq 0x1(%rdx), %rcx
cmpl %edx, %esi
jbe 0x3d2b3
movq %rax, %r15
jmp 0x3d2f8
leaq 0x6(%rdx), %rcx
cmpl %ecx, %esi
jae 0x3d305
movq %rsi, 0x30(%rsp)
movl %ecx, %r15d
shrl %r15d
addq %rcx, %r15
movl %edi, 0x1c(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
callq 0x4860
movl 0x1c(%rsp), %edi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r15
testq %rax, %rax
jne 0x3d308
jmp 0x3d345
movq %rsi, 0x30(%rsp)
movl %ecx, %r15d
shrl %r15d
addq %rcx, %r15
movl %edi, 0x1c(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
callq 0x4860
movl 0x1c(%rsp), %edi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r15
testq %rax, %rax
je 0x3d345
shll $0x4, %r12d
orl %edi, %r12d
movb %r12b, (%r15,%rdx)
jmp 0x3d383
movq %rax, %r15
orb $-0x10, %dil
movb %dil, (%r15,%rdx)
cmpl $0x7f, %r12d
jg 0x3d327
movb $0x11, 0x1(%r15,%rdx)
movb %r12b, 0x2(%r15,%rdx)
addq $0x3, %rdx
jmp 0x3d340
cmpl $0x7fff, %r12d          # imm = 0x7FFF
jg 0x3d378
movb $0x12, 0x1(%r15,%rdx)
movw %r12w, 0x2(%r15,%rdx)
addq $0x4, %rdx
movq %rdx, %rcx
jmp 0x3d383
movq %rdx, %rcx
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r15
jmp 0x3d383
cmpl $0x7fff, %r15d          # imm = 0x7FFF
ja 0x3d46a
movb $0x12, (%rax)
movw %r15w, 0x1(%rax)
movl $0x7, %esi
movl $0x3, %edx
jmp 0x3d23d
movb $0x13, 0x1(%r15,%rdx)
movl %r12d, 0x2(%r15,%rdx)
movl -0x8(%r13,%rbp), %r12d
leaq (%rcx,%r12), %rax
addq $0x2, %rax
cmpq %rcx, %rax
movq %rcx, 0x10(%rsp)
jbe 0x3d3cb
movq -0x10(%r13,%rbp), %rdx
cmpq %rax, %rsi
jae 0x3d3dd
movq %rax, %rsi
shrq %rsi
addq %rax, %rsi
movq %r15, %rdi
movq %rdx, 0x20(%rsp)
callq 0x4860
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
testq %rax, %rax
jne 0x3d3e0
jmp 0x3d3ff
callq 0x4050
movq 0x10(%rsp), %rcx
movl $0x4b, (%rax)
jmp 0x3d3ff
movq %r15, %rax
leaq (%rax,%rcx), %rdi
movq %rdx, %rsi
movq %r12, %rdx
movq %rax, %r15
callq 0x43c0
movq 0x10(%rsp), %rcx
addq %rcx, %r12
movb $0x0, (%r15,%r12)
movl -0x4(%r13,%rbp), %eax
testl %eax, %eax
jns 0x3d41f
movq -0x10(%r13,%rbp), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %rdi
callq 0x45c0
movq 0x10(%rsp), %rcx
addq %rcx, %r15
movq %r15, -0x10(%r13,%rbp)
leal -0x80000000(%rcx), %eax
movl %eax, -0x4(%r13,%rbp)
movq 0x38(%rsp), %r12
orb $0x8, 0xb0(%r12)
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
incq %rbx
movzwl 0x18(%r12), %eax
addq $0x28, %rbp
cmpq %rax, %rbx
jb 0x3d14d
jmp 0x3d480
movb $0x13, (%rax)
movl %r15d, 0x1(%rax)
movl $0x7, %esi
movl $0x5, %edx
jmp 0x3d23d
cmpb $0x0, 0x1c(%r12)
je 0x3d7dd
movl $0x1c, %ebp
xorl %ebx, %ebx
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
movq 0x98(%r12), %r13
movslq -0x1c(%r13,%rbp), %rcx
movq 0x60(%r14), %rax
movl (%rax,%rcx,4), %r15d
testl %r15d, %r15d
js 0x3d7af
movl %r15d, -0x1c(%r13,%rbp)
cmpq $0x0, -0xc(%r13,%rbp)
je 0x3d7af
cmpl %r8d, %ecx
movl $0x3, %edx
sbbl $0x0, %edx
cmpl %r8d, %r15d
movl $0x3, %eax
sbbl $0x0, %eax
xorl %esi, %esi
cmpl %r9d, %r15d
cmovbl %r10d, %eax
setb %sil
xorl %edi, %edi
cmpl %eax, %edx
sete %dil
cmpl %r9d, %ecx
cmovael %edi, %esi
cmpb $0x1, %sil
jne 0x3d532
movq -0xc(%r13,%rbp), %rcx
movl (%r13,%rbp), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
negq %rdx
cmpl $0x2, %eax
je 0x3d560
cmpl $0x1, %eax
jne 0x3d56b
movb %r15b, 0x1(%rcx,%rdx)
jmp 0x3d7af
movl $0x7, %edi
callq 0x46a0
testq %rax, %rax
je 0x3d558
movl %r15d, %ecx
negl %ecx
jo 0x3d575
cmpl $0x80000001, %r15d      # imm = 0x80000001
jne 0x3d57c
movw $0x8111, (%rax)         # imm = 0x8111
jmp 0x3d58d
xorl %edx, %edx
xorl %esi, %esi
xorl %eax, %eax
jmp 0x3d597
movw %r15w, 0x1(%rcx,%rdx)
jmp 0x3d7af
movl %r15d, 0x1(%rcx,%rdx)
jmp 0x3d7af
movw $0x8011, (%rax)         # imm = 0x8011
jmp 0x3d58d
cmpl $0x7f, %r15d
ja 0x3d6ae
movb $0x11, (%rax)
movb %r15b, 0x1(%rax)
movl $0x7, %esi
movl $0x2, %edx
movl -0x18(%r13,%rbp), %r12d
movl -0x10(%r13,%rbp), %edi
cmpl $0xe, %r12d
jg 0x3d5b7
leaq 0x1(%rdx), %rcx
cmpl %edx, %esi
jbe 0x3d60d
movq %rax, %r15
jmp 0x3d652
leaq 0x6(%rdx), %rcx
cmpl %ecx, %esi
jae 0x3d65f
movq %rsi, 0x30(%rsp)
movl %ecx, %r15d
shrl %r15d
addq %rcx, %r15
movl %edi, 0x1c(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
callq 0x4860
movl 0x1c(%rsp), %edi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r15
testq %rax, %rax
jne 0x3d662
jmp 0x3d69f
movq %rsi, 0x30(%rsp)
movl %ecx, %r15d
shrl %r15d
addq %rcx, %r15
movl %edi, 0x1c(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %rcx, 0x10(%rsp)
movq %rdx, 0x20(%rsp)
callq 0x4860
movl 0x1c(%rsp), %edi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %rax, %r15
testq %rax, %rax
je 0x3d69f
shll $0x4, %r12d
orl %edi, %r12d
movb %r12b, (%r15,%rdx)
jmp 0x3d6dd
movq %rax, %r15
orb $-0x10, %dil
movb %dil, (%r15,%rdx)
cmpl $0x7f, %r12d
jg 0x3d681
movb $0x11, 0x1(%r15,%rdx)
movb %r12b, 0x2(%r15,%rdx)
addq $0x3, %rdx
jmp 0x3d69a
cmpl $0x7fff, %r12d          # imm = 0x7FFF
jg 0x3d6d2
movb $0x12, 0x1(%r15,%rdx)
movw %r12w, 0x2(%r15,%rdx)
addq $0x4, %rdx
movq %rdx, %rcx
jmp 0x3d6dd
movq %rdx, %rcx
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r15
jmp 0x3d6dd
cmpl $0x7fff, %r15d          # imm = 0x7FFF
ja 0x3d7c7
movb $0x12, (%rax)
movw %r15w, 0x1(%rax)
movl $0x7, %esi
movl $0x3, %edx
jmp 0x3d597
movb $0x13, 0x1(%r15,%rdx)
movl %r12d, 0x2(%r15,%rdx)
movl -0x4(%r13,%rbp), %r12d
leaq (%rcx,%r12), %rax
addq $0x2, %rax
cmpq %rcx, %rax
movq %rcx, 0x10(%rsp)
jbe 0x3d725
movq -0xc(%r13,%rbp), %rdx
cmpq %rax, %rsi
jae 0x3d737
movq %rax, %rsi
shrq %rsi
addq %rax, %rsi
movq %r15, %rdi
movq %rdx, 0x20(%rsp)
callq 0x4860
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
testq %rax, %rax
jne 0x3d73a
jmp 0x3d759
callq 0x4050
movq 0x10(%rsp), %rcx
movl $0x4b, (%rax)
jmp 0x3d759
movq %r15, %rax
leaq (%rax,%rcx), %rdi
movq %rdx, %rsi
movq %r12, %rdx
movq %rax, %r15
callq 0x43c0
movq 0x10(%rsp), %rcx
addq %rcx, %r12
movb $0x0, (%r15,%r12)
movl (%r13,%rbp), %eax
testl %eax, %eax
jns 0x3d779
movq -0xc(%r13,%rbp), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %rdi
callq 0x45c0
movq 0x10(%rsp), %rcx
addq %rcx, %r15
movq %r15, -0xc(%r13,%rbp)
leal -0x80000000(%rcx), %eax
movl %eax, (%r13,%rbp)
movq 0x38(%rsp), %r12
movl $0x1, 0xb4(%r12)
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
incq %rbx
movzbl 0x1c(%r12), %eax
addq $0x20, %rbp
cmpq %rax, %rbx
jb 0x3d4a5
jmp 0x3d7dd
movb $0x13, (%rax)
movl %r15d, 0x1(%rax)
movl $0x7, %esi
movl $0x5, %edx
jmp 0x3d597
xorl %eax, %eax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rsp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x4250
movl $0x400, %edx            # imm = 0x400
movl %ebp, %edi
movq %r15, %rsi
callq 0x32cd9
movq %rax, %r15
movq %r14, %rdi
movq %r12, %rsi
callq 0x32a62
movq (%r12), %rcx
incq %rcx
movq %rcx, (%rsp)
leaq 0x71849(%rip), %rsi     # 0xaf07d
leaq 0x71850(%rip), %rdx     # 0xaf08b
movl $0x1, %edi
movl %ebp, %ecx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x9774
movl $0x1, %edi
callq 0x45f0