// File: /workspace/github_c_makefile_star2_O2/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 $0x138, %rsp            # imm = 0x138
movl %ecx, 0x4(%rsp)
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x28(%rsp)
testb $0x1, 0xbc(%rsi)
jne 0x2f876
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x2b198
movq %rbx, 0x8(%rsp)
movslq 0x5c(%rbx), %rax
movl $0x100, %r14d           # imm = 0x100
cmpq %r14, %rax
movq %rax, 0x20(%rsp)
cmovbq %rax, %r14
movq $0x0, 0x18(%rsp)
movl 0x4(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x10(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq %rbp, 0x10(%rsp)
je 0x2f8f1
movq (%r12,%rbp,8), %r15
movq %r15, %rdi
callq 0x41c0
movq %rax, %rbx
incq %rbx
movq %r14, %rax
subq %r13, %rax
cmpq %rbx, %rax
jb 0x2f8fb
leaq (%rsp,%r13), %rdi
addq $0x30, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x43c0
addq %rbx, %r13
incq %rbp
jmp 0x2f8b2
movq 0x20(%rsp), %rbx
jmp 0x2f988
movl 0x4(%rsp), %eax
cmpl %ebp, %eax
movl %ebp, %ebx
cmovgl %eax, %ebx
movq %rbp, %r15
movq %r13, %r14
cmpq %r15, %rbx
je 0x2f925
movq (%r12,%r15,8), %rdi
callq 0x41c0
addq %rax, %r14
incq %r14
incq %r15
jmp 0x2f90c
movq 0x20(%rsp), %rdi
cmpq %rdi, %r14
cmovaq %r14, %rdi
testq $-0x80000000, %rdi      # imm = 0x80000000
je 0x2f957
leaq 0x57749(%rip), %rsi     # 0x8708a
leaq 0x57755(%rip), %rdx     # 0x8709d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x2fa17
movq %rdi, %rbx
callq 0x46a0
testq %rax, %rax
je 0x2fa17
movq 0x8(%rsp), %rcx
movq 0x80(%rcx), %rdx
movq %rdx, 0x18(%rsp)
movq %rax, 0x80(%rcx)
movl %ebx, 0x5c(%rcx)
movq %rbp, 0x10(%rsp)
testq %r13, %r13
je 0x2f9b2
movslq %ebx, %rax
cmpq %rax, %r13
ja 0x2fa2c
movq 0x8(%rsp), %rax
movq 0x80(%rax), %rdi
leaq 0x30(%rsp), %rsi
movq %r13, %rdx
callq 0x43c0
movl 0x10(%rsp), %r14d
movslq 0x4(%rsp), %rbp
cmpq %rbp, %r14
jge 0x2f9f6
movq (%r12,%r14,8), %rbx
movq %rbx, %rdi
callq 0x41c0
movq %rax, %r15
leaq 0x1(%rax), %rdx
movq 0x8(%rsp), %rax
movq 0x80(%rax), %rdi
addq %r13, %rdi
movq %rbx, %rsi
callq 0x43c0
addq %r15, %r13
incq %r13
incq %r14
jmp 0x2f9bc
movq 0x18(%rsp), %rdi
callq 0x45c0
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edx
callq 0x2fa4b
xorl %eax, %eax
jmp 0x2fa1a
pushq $-0x1
popq %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x57698(%rip), %rdi     # 0x870cb
leaq 0x568e9(%rip), %rsi     # 0x86323
leaq 0x576a0(%rip), %rcx     # 0x870e1
movl $0x1646, %edx           # imm = 0x1646
callq 0x42e0