// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/vcf.c
// Function: bcf_update_alleles
int bcf_update_alleles(const bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int nals)
{
    if ( !(line->unpacked & BCF_UN_STR) ) bcf_unpack(line, BCF_UN_STR);
    char *free_old = NULL;
    char buffer[256];
    size_t used = 0;

    // The pointers in alleles may point into the existing line->d.als memory,
    // so care needs to be taken not to clobber them while updating.  Usually
    // they will be short so we can copy through an intermediate buffer.
    // If they're longer, or won't fit in the existing allocation we
    // can allocate a new buffer to write into.  Note that in either case
    // pointers to line->d.als memory in alleles may not be valid when we've
    // finished.
    int i;
    size_t avail = line->d.m_als < sizeof(buffer) ? line->d.m_als : sizeof(buffer);
    for (i=0; i<nals; i++) {
        size_t sz = strlen(alleles[i]) + 1;
        if (avail - used < sz)
            break;
        memcpy(buffer + used, alleles[i], sz);
        used += sz;
    }

    // Did we miss anything?
    if (i < nals) {
        int j;
        size_t needed = used;
        char *new_als;
        for (j = i; j < nals; j++)
            needed += strlen(alleles[j]) + 1;
        if (needed < line->d.m_als) // Don't shrink the buffer
            needed = line->d.m_als;
        if (needed > INT_MAX) {
            hts_log_error("REF + alleles too long to fit in a BCF record");
            return -1;
        }
        new_als = malloc(needed);
        if (!new_als)
            return -1;
        free_old = line->d.als;
        line->d.als = new_als;
        line->d.m_als = needed;
    }

    // Copy from the temp buffer to the destination
    if (used) {
        assert(used <= line->d.m_als);
        memcpy(line->d.als, buffer, used);
    }

    // Add in any remaining entries - if this happens we will always be
    // writing to a newly-allocated buffer.
    for (; i < nals; i++) {
        size_t sz = strlen(alleles[i]) + 1;
        memcpy(line->d.als + used, alleles[i], sz);
        used += sz;
    }

    if (free_old)
        free(free_old);
    return _bcf1_sync_alleles(hdr,line,nals);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x38(%rsp)
testb $0x1, 0xbc(%rsi)
jne 0x3fd3c
movq %rbx, %rdi
movl $0x1, %esi
callq 0x38183
movl %ebp, %r15d
movq %rbx, 0x20(%rsp)
movslq 0x5c(%rbx), %rax
movl $0x100, %r13d           # imm = 0x100
cmpq %r13, %rax
cmovbq %rax, %r13
testl %ebp, %ebp
movq %r14, 0x28(%rsp)
movq %r15, 0x30(%rsp)
movl %ebp, 0x14(%rsp)
jle 0x3fdc4
movq %rax, 0x18(%rsp)
xorl %ebx, %ebx
xorl %r12d, %r12d
movq (%r14,%rbx,8), %r14
movq %r14, %rdi
callq 0x41c0
movq %rax, %rbp
incq %rbp
movq %r13, %rax
subq %r12, %rax
cmpq %rbp, %rax
jb 0x3fdd7
leaq (%rsp,%r12), %rdi
addq $0x40, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x43c0
addq %rbp, %r12
incq %rbx
cmpq %rbx, %r15
movq 0x28(%rsp), %r14
jne 0x3fd71
xorl %edx, %edx
movl %r15d, %ebx
movl 0x14(%rsp), %ebp
movq 0x18(%rsp), %r15
jmp 0x3fe5e
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
jmp 0x3fe9c
movq %r12, %r14
cmpl 0x14(%rsp), %ebx
movq %r15, %rbp
movq 0x28(%rsp), %r15
jge 0x3fe05
movq %rbx, %r13
movq %r12, %r14
movq (%r15,%r13,8), %rdi
callq 0x41c0
addq %rax, %r14
incq %r14
incq %r13
cmpq %r13, %rbp
jne 0x3fdee
movq 0x18(%rsp), %r15
cmpq %r15, %r14
cmovaq %r14, %r15
testq $-0x80000000, %r15      # imm = 0x80000000
je 0x3fe36
leaq 0x6c50d(%rip), %rsi     # 0xac32e
leaq 0x6c519(%rip), %rdx     # 0xac341
movl $0x1, %edi
xorl %eax, %eax
callq 0x942d
jmp 0x3fe8f
movq %r15, %rdi
callq 0x46a0
testq %rax, %rax
je 0x3fe8f
movq 0x20(%rsp), %rcx
movq 0x80(%rcx), %rdx
movq %rax, 0x80(%rcx)
movl %r15d, 0x5c(%rcx)
movl 0x14(%rsp), %ebp
testq %r12, %r12
movq %rdx, 0x18(%rsp)
je 0x3fe99
movslq %r15d, %rax
cmpq %rax, %r12
ja 0x3ff9c
movq 0x20(%rsp), %rax
movq 0x80(%rax), %rdi
leaq 0x40(%rsp), %rsi
movq %r12, %rdx
callq 0x43c0
jmp 0x3fe9c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3ff8a
xorl %r12d, %r12d
cmpl %ebp, %ebx
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r14
jge 0x3fee4
movl %ebx, %ebx
movq (%r15,%rbx,8), %r13
movq %r13, %rdi
callq 0x41c0
movq %rax, %rbp
leaq 0x1(%rax), %rdx
movq 0x20(%rsp), %rax
movq 0x80(%rax), %rdi
addq %r12, %rdi
movq %r13, %rsi
callq 0x43c0
addq %rbp, %r12
incq %r12
incq %rbx
cmpq %rbx, %r14
jne 0x3feac
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x3fef3
callq 0x45c0
movq 0x20(%rsp), %rbx
orb $0x2, 0xb0(%rbx)
movl $0xffffffff, 0xac(%rbx) # imm = 0xFFFFFFFF
movl 0x14(%rsp), %ebp
movw %bp, 0x1a(%rbx)
movzwl %bp, %edi
movslq 0x60(%rbx), %rsi
cmpl %esi, %edi
movq 0x30(%rsp), %r14
jle 0x3ff4e
cmpl $0x1, %edi
adcl $0x0, %edi
leaq 0x88(%rbx), %r9
leaq 0x6d0c9(%rip), %rax     # 0xacffe
movq %rax, (%rsp)
movl $0x4, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
callq 0x114b1
movl %eax, 0x60(%rbx)
testl %ebp, %ebp
jle 0x3ff77
movq 0x80(%rbx), %rcx
xorl %eax, %eax
movq 0x88(%rbx), %rdx
movq %rcx, (%rdx,%rax,8)
cmpb $0x0, (%rcx)
leaq 0x1(%rcx), %rcx
jne 0x3ff66
incq %rax
cmpq %r14, %rax
jne 0x3ff5b
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x370a7
movq %rax, 0x8(%rbx)
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6c3cc(%rip), %rdi     # 0xac36f
leaq 0x6b629(%rip), %rsi     # 0xab5d3
leaq 0x6c3d4(%rip), %rcx     # 0xac385
movl $0x1646, %edx           # imm = 0x1646
callq 0x42e0