// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rsi, %r12
movq %rdi, 0x8(%rsp)
movl 0xcc(%rdx), %ebp
testl %ebp, %ebp
jne 0x3c9d9
movl 0x58(%r12), %eax
cmpl $-0x1, %eax
je 0x3c9c5
testl %eax, %eax
movq %r12, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
jne 0x3c29a
movb $0x1, %al
xorl %r14d, %r14d
xorl %r12d, %r12d
movl %eax, 0x20(%rsp)
movq 0x38(%rsp), %r15
movslq (%r15,%r12,4), %rbx
leaq (,%rbx,4), %rdi
callq 0x46a0
movq %rax, 0x60(%r15,%r12,8)
testq %rbx, %rbx
jle 0x3c23d
movq %rax, %r13
movq 0x10(%r15,%r12,8), %rbp
xorl %r15d, %r15d
movq (%rbp), %rdx
testq %rdx, %rdx
je 0x3c225
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x2d3d9
movl %eax, (%r13,%r15,4)
cmpl $-0x1, %eax
sete %cl
movl %eax, %eax
cmpq %rax, %r15
sete %al
orb %cl, %al
jne 0x3c22e
incl %r14d
movq 0x38(%rsp), %rax
movl %r14d, 0x58(%rax)
movl (%rax,%r12,4), %ebx
jmp 0x3c22e
movl $0xffffffff, (%r13,%r15,4) # imm = 0xFFFFFFFF
incq %r15
movslq %ebx, %rax
addq $0x10, %rbp
cmpq %rax, %r15
jl 0x3c1e6
movl $0x1, %r12d
testb $0x1, 0x20(%rsp)
movl $0x0, %eax
jne 0x3c1b7
cmpl $-0x1, %r14d
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %rbx
je 0x3c9c5
testl %r14d, %r14d
jne 0x3c29a
movq 0x60(%r12), %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, 0x60(%r12)
movq 0x68(%r12), %rdi
callq 0x45c0
movq %rbx, 0x68(%r12)
movl $0xffffffff, 0x58(%r12) # imm = 0xFFFFFFFF
jmp 0x3c9c5
movq %rbx, %rdi
movl $0xf, %esi
callq 0x38183
movq 0x68(%r12), %rax
movslq 0x10(%rbx), %rcx
movl (%rax,%rcx,4), %eax
testl %eax, %eax
js 0x3c2ba
movl %eax, 0x10(%rbx)
movl 0x68(%rbx), %eax
testl %eax, %eax
jle 0x3c2ef
movq 0x70(%rbx), %rcx
movq 0x60(%r12), %rdx
xorl %esi, %esi
movslq (%rcx,%rsi,4), %rdi
movl (%rdx,%rdi,4), %edi
testl %edi, %edi
js 0x3c2dd
movl %edi, (%rcx,%rsi,4)
movl 0x68(%rbx), %eax
orb $0x4, 0xb0(%rbx)
incq %rsi
movslq %eax, %rdi
cmpq %rdi, %rsi
jl 0x3c2cc
movq 0x18(%rbx), %rax
testw %ax, %ax
je 0x3c65a
movl $0x10, %r14d
xorl %r15d, %r15d
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
movq 0x90(%rbx), %r13
movslq -0x10(%r13,%r14), %rcx
movq 0x60(%r12), %rax
movl (%rax,%rcx,4), %ebp
testl %ebp, %ebp
js 0x3c614
movl %ebp, -0x10(%r13,%r14)
movq (%r13,%r14), %r11
testq %r11, %r11
je 0x3c614
cmpl %r8d, %ecx
movl $0x3, %edx
sbbl $0x0, %edx
cmpl %r8d, %ebp
movl $0x3, %eax
sbbl $0x0, %eax
xorl %esi, %esi
cmpl %r9d, %ebp
cmovbl %r10d, %eax
setb %sil
xorl %edi, %edi
cmpl %eax, %edx
sete %dil
cmpl %r9d, %ecx
cmovael %edi, %esi
cmpb $0x1, %sil
jne 0x3c39f
movl 0xc(%r13,%r14), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
negq %rcx
cmpl $0x2, %eax
je 0x3c40a
cmpl $0x1, %eax
jne 0x3c414
movb %bpl, 0x1(%r11,%rcx)
jmp 0x3c614
movq %r11, 0x20(%rsp)
movl $0x7, %edi
callq 0x46a0
movq %rax, %r12
testq %rax, %rax
je 0x3c3d0
cmpl $0x7f, %ebp
ja 0x3c41d
movb $0x11, (%r12)
movb %bpl, 0x1(%r12)
movl $0x2, %r8d
jmp 0x3c45a
movl -0xc(%r13,%r14), %eax
movl %eax, 0x8(%rsp)
movl 0x10(%r13,%r14), %ebp
cmpl $0xe, %ebp
jg 0x3c438
movl $0x1, %esi
movq %r12, %rdi
callq 0x4860
testq %rax, %rax
je 0x3c62d
movq %rax, %r12
xorl %r8d, %r8d
movl $0x1, %ebx
movl 0x8(%rsp), %eax
jmp 0x3c46e
movw %bp, (%r11,%rcx)
jmp 0x3c614
movl %ebp, (%r11,%rcx)
jmp 0x3c614
cmpl $0x7fff, %ebp           # imm = 0x7FFF
ja 0x3c44a
movb $0x12, (%r12)
movw %bp, 0x1(%r12)
movl $0x3, %r8d
jmp 0x3c45a
movl $0x6, %eax
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
jmp 0x3c491
movb $0x13, (%r12)
movl %ebp, 0x1(%r12)
movl $0x5, %r8d
movl -0xc(%r13,%r14), %eax
movl 0x10(%r13,%r14), %ebp
movl $0x7, %ebx
cmpl $0xf, %ebp
jge 0x3c484
shll $0x4, %ebp
orl %eax, %ebp
movb %bpl, (%r12,%r8)
movl $0x1, %ecx
movq %r12, %rax
jmp 0x3c512
movl %eax, 0x8(%rsp)
movq %r8, 0x10(%rsp)
leaq 0x6(%r8), %rax
movl %eax, %esi
shrl %esi
addq %rax, %rsi
movq %r12, %rdi
movq %rsi, 0x18(%rsp)
callq 0x4860
testq %rax, %rax
je 0x3c4d6
movl 0x8(%rsp), %ecx
orb $-0x10, %cl
movq 0x10(%rsp), %r8
movb %cl, (%rax,%r8)
cmpl $0x7f, %ebp
ja 0x3c4e2
movb $0x11, 0x1(%rax,%r8)
movb %bpl, 0x2(%rax,%r8)
movl $0x3, %ecx
movq 0x18(%rsp), %rbx
jmp 0x3c512
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rsi
jmp 0x3c51d
cmpl $0x7fff, %ebp           # imm = 0x7FFF
movq 0x18(%rsp), %rbx
ja 0x3c502
movb $0x12, 0x1(%rax,%r8)
movw %bp, 0x2(%rax,%r8)
movl $0x4, %ecx
jmp 0x3c512
movb $0x13, 0x1(%rax,%r8)
movl %ebp, 0x2(%rax,%r8)
movl $0x6, %ecx
addq %rcx, %r8
movq (%r13,%r14), %rsi
movq %rax, %r12
movl 0x8(%r13,%r14), %edx
leaq (%r8,%rdx), %rax
movq %rax, 0x18(%rsp)
leaq (%r8,%rdx), %rax
addq $0x2, %rax
cmpq %rax, %rbx
jae 0x3c591
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %r8, 0x10(%rsp)
leaq (%r15,%r15,4), %rcx
leaq (,%rcx,8), %rcx
addq %r13, %rcx
addq $0x10, %rcx
movq %rcx, 0x8(%rsp)
movq 0x30(%rsp), %rbx
movq %r12, %rbp
movq %rax, %rsi
shrq %rsi
addq %rax, %rsi
movq %r12, %rdi
callq 0x4860
movq %rax, %r12
testq %rax, %rax
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
jne 0x3c59f
jmp 0x3c5bb
leaq (%r14,%r13), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rbx
leaq (%r12,%r8), %rdi
movq %r8, %rbp
callq 0x43c0
movq %rbp, %r8
movq 0x18(%rsp), %rax
movb $0x0, (%r12,%rax)
movq %r12, %rbp
movl 0xc(%r13,%r14), %eax
testl %eax, %eax
jns 0x3c5df
movq 0x8(%rsp), %rcx
movq (%rcx), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %rdi
movq %r8, %r12
callq 0x45c0
movq %r12, %r8
addq %r8, %rbp
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0xc(%r13,%r14)
orb $0x8, 0xb0(%rbx)
movq 0x38(%rsp), %r12
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
incq %r15
movq 0x18(%rbx), %rax
movzwl %ax, %ecx
addq $0x28, %r14
cmpq %rcx, %r15
jb 0x3c317
jmp 0x3c65a
leaq (%r14,%r13), %rax
movq %rax, 0x8(%rsp)
movl 0x8(%r13,%r14), %edx
leaq 0x2(%rdx), %rax
movq $0x0, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
xorl %r12d, %r12d
jmp 0x3c564
shrq $0x20, %rax
testb %al, %al
je 0x3c9c5
movl $0x10, %r14d
xorl %r15d, %r15d
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
movq 0x98(%rbx), %r13
movslq -0x10(%r13,%r14), %rcx
movq 0x60(%r12), %rax
movl (%rax,%rcx,4), %ebp
testl %ebp, %ebp
js 0x3c982
movl %ebp, -0x10(%r13,%r14)
movq (%r13,%r14), %r11
testq %r11, %r11
je 0x3c982
cmpl %r8d, %ecx
movl $0x3, %edx
sbbl $0x0, %edx
cmpl %r8d, %ebp
movl $0x3, %eax
sbbl $0x0, %eax
xorl %esi, %esi
cmpl %r9d, %ebp
cmovbl %r10d, %eax
setb %sil
xorl %edi, %edi
cmpl %eax, %edx
sete %dil
cmpl %r9d, %ecx
cmovael %edi, %esi
cmpb $0x1, %sil
jne 0x3c70d
movl 0xc(%r13,%r14), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
negq %rcx
cmpl $0x2, %eax
je 0x3c778
cmpl $0x1, %eax
jne 0x3c783
movb %bpl, 0x1(%r11,%rcx)
jmp 0x3c982
movq %r11, 0x20(%rsp)
movl $0x7, %edi
callq 0x46a0
movq %rax, %r12
testq %rax, %rax
je 0x3c73e
cmpl $0x7f, %ebp
ja 0x3c78d
movb $0x11, (%r12)
movb %bpl, 0x1(%r12)
movl $0x2, %r8d
jmp 0x3c7ca
movl -0xc(%r13,%r14), %ebp
movl -0x4(%r13,%r14), %eax
movl %eax, 0x8(%rsp)
cmpl $0xe, %ebp
jg 0x3c7a8
movl $0x1, %esi
movq %r12, %rdi
callq 0x4860
testq %rax, %rax
je 0x3c998
movq %rax, %r12
xorl %r8d, %r8d
movl $0x1, %ebx
movl 0x8(%rsp), %eax
jmp 0x3c7de
movw %bp, 0x1(%r11,%rcx)
jmp 0x3c982
movl %ebp, 0x1(%r11,%rcx)
jmp 0x3c982
cmpl $0x7fff, %ebp           # imm = 0x7FFF
ja 0x3c7ba
movb $0x12, (%r12)
movw %bp, 0x1(%r12)
movl $0x3, %r8d
jmp 0x3c7ca
movl $0x6, %eax
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
jmp 0x3c801
movb $0x13, (%r12)
movl %ebp, 0x1(%r12)
movl $0x5, %r8d
movl -0xc(%r13,%r14), %ebp
movl -0x4(%r13,%r14), %eax
movl $0x7, %ebx
cmpl $0xf, %ebp
jge 0x3c7f4
shll $0x4, %ebp
orl %eax, %ebp
movb %bpl, (%r12,%r8)
movl $0x1, %ecx
movq %r12, %rax
jmp 0x3c882
movl %eax, 0x8(%rsp)
movq %r8, 0x10(%rsp)
leaq 0x6(%r8), %rax
movl %eax, %esi
shrl %esi
addq %rax, %rsi
movq %r12, %rdi
movq %rsi, 0x18(%rsp)
callq 0x4860
testq %rax, %rax
je 0x3c846
movl 0x8(%rsp), %ecx
orb $-0x10, %cl
movq 0x10(%rsp), %r8
movb %cl, (%rax,%r8)
cmpl $0x7f, %ebp
ja 0x3c852
movb $0x11, 0x1(%rax,%r8)
movb %bpl, 0x2(%rax,%r8)
movl $0x3, %ecx
movq 0x18(%rsp), %rbx
jmp 0x3c882
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rsi
jmp 0x3c88d
cmpl $0x7fff, %ebp           # imm = 0x7FFF
movq 0x18(%rsp), %rbx
ja 0x3c872
movb $0x12, 0x1(%rax,%r8)
movw %bp, 0x2(%rax,%r8)
movl $0x4, %ecx
jmp 0x3c882
movb $0x13, 0x1(%rax,%r8)
movl %ebp, 0x2(%rax,%r8)
movl $0x6, %ecx
addq %rcx, %r8
movq (%r13,%r14), %rsi
movq %rax, %r12
movl 0x8(%r13,%r14), %edx
leaq (%r8,%rdx), %rax
movq %rax, 0x18(%rsp)
leaq (%r8,%rdx), %rax
addq $0x2, %rax
cmpq %rax, %rbx
jae 0x3c8fc
movq %rdx, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %r8, 0x10(%rsp)
movq %r15, %rcx
shlq $0x5, %rcx
addq %r13, %rcx
addq $0x10, %rcx
movq %rcx, 0x8(%rsp)
movq 0x30(%rsp), %rbx
movq %r12, %rbp
movq %rax, %rsi
shrq %rsi
addq %rax, %rsi
movq %r12, %rdi
callq 0x4860
movq %rax, %r12
testq %rax, %rax
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
jne 0x3c90a
jmp 0x3c926
leaq (%r14,%r13), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rbx
leaq (%r12,%r8), %rdi
movq %r8, %rbp
callq 0x43c0
movq %rbp, %r8
movq 0x18(%rsp), %rax
movb $0x0, (%r12,%rax)
movq %r12, %rbp
movl 0xc(%r13,%r14), %eax
testl %eax, %eax
jns 0x3c94a
movq 0x8(%rsp), %rcx
movq (%rcx), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %rdi
movq %r8, %r12
callq 0x45c0
movq %r12, %r8
addq %r8, %rbp
movq 0x8(%rsp), %rax
movq %rbp, (%rax)
orl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0xc(%r13,%r14)
movl $0x1, 0xb4(%rbx)
movq 0x38(%rsp), %r12
movl $0x8000, %r8d           # imm = 0x8000
movl $0x80, %r9d
movl $0x1, %r10d
incq %r15
movzbl 0x1c(%rbx), %eax
addq $0x20, %r14
cmpq %rax, %r15
jb 0x3c681
jmp 0x3c9c5
leaq (%r14,%r13), %rax
movq %rax, 0x8(%rsp)
movl 0x8(%r13,%r14), %edx
leaq 0x2(%rdx), %rax
movq $0x0, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movq %rdx, 0x28(%rsp)
xorl %r12d, %r12d
jmp 0x3c8cf
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 0x31afd
movq %rax, %r15
movq %r12, %rdi
movq %rbx, %rsi
callq 0x318ad
movq (%rbx), %rcx
incq %rcx
movq %rcx, (%rsp)
leaq 0x6f612(%rip), %rsi     # 0xac02d
leaq 0x6f619(%rip), %rdx     # 0xac03b
movl $0x1, %edi
movl %ebp, %ecx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x942d
movl $0x1, %edi
callq 0x45f0