// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: bam_aux_update_array
int bam_aux_update_array(bam1_t *b, const char tag[2],
                         uint8_t type, uint32_t items, void *data)
{
    uint8_t *s = bam_aux_get(b, tag);
    size_t old_sz = 0, new_sz;
    int new = 0;

    if (s) { // Tag present
        if (*s != 'B') { errno = EINVAL; return -1; }
        old_sz = aux_type2size(s[1]);
        if (old_sz < 1 || old_sz > 4) { errno = EINVAL; return -1; }
        old_sz *= le_to_u32(s + 2);
    } else {
        if (errno == ENOENT) {  // Tag doesn't exist - add a new one
            s = b->data + b->l_data;
            new = 1;
        }  else { // Invalid aux data, give up.
            return -1;
        }
    }

    new_sz = aux_type2size(type);
    if (new_sz < 1 || new_sz > 4) { errno = EINVAL; return -1; }
    if (items > INT32_MAX / new_sz) { errno = ENOMEM; return -1; }
    new_sz *= items;

    if (new || old_sz < new_sz) {
        // Make room for new tag
        ptrdiff_t s_offset = s - b->data;
        if (possibly_expand_bam_data(b, (new ? 8 : 0) + new_sz - old_sz) < 0)
            return -1;
        s =  b->data + s_offset;
    }
    if (new) { // Add tag id and type
        *s++ = tag[0];
        *s++ = tag[1];
        *s = 'B';
        b->l_data += 8 + new_sz;
    } else if (old_sz != new_sz) { // shift following data if necessary
        memmove(s + 6 + new_sz, s + 6 + old_sz,
                b->l_data - ((s + 6 + old_sz) - b->data));
        b->l_data -= old_sz;
        b->l_data += new_sz;
    }

    s[1] = type;
    u32_to_le(items, s + 2);
    if (new_sz > 0) {
#ifdef HTS_LITTLE_ENDIAN
        memcpy(s + 6, data, new_sz);
#else
        return aux_to_le(type, s + 6, data, new_sz);
#endif
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e760
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x41718
movq -0x30(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x42, %eax
je 0x416c6
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4192f
movq -0x30(%rbp), %rax
movzbl 0x1(%rax), %edi
callq 0x41940
cltq
movq %rax, -0x38(%rbp)
cmpq $0x1, -0x38(%rbp)
jb 0x416e7
cmpq $0x4, -0x38(%rbp)
jbe 0x416fe
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4192f
movq -0x30(%rbp), %rdi
addq $0x2, %rdi
callq 0x32820
movl %eax, %eax
imulq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x41750
callq 0x4050
cmpl $0x2, (%rax)
jne 0x41742
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x4174e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4192f
jmp 0x41750
movzbl -0x19(%rbp), %edi
callq 0x41940
cltq
movq %rax, -0x40(%rbp)
cmpq $0x1, -0x40(%rbp)
jb 0x4176d
cmpq $0x4, -0x40(%rbp)
jbe 0x41784
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4192f
movl -0x20(%rbp), %eax
movq %rax, -0x58(%rbp)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jbe 0x417bb
callq 0x4050
movl $0xc, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4192f
movl -0x20(%rbp), %eax
imulq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x417d7
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x4182f
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %edx
xorl %eax, %eax
movl $0x8, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movslq %eax, %rsi
addq -0x40(%rbp), %rsi
subq -0x38(%rbp), %rsi
callq 0x3a350
cmpl $0x0, %eax
jge 0x4181f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4192f
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x41883
movq -0x18(%rbp), %rax
movb (%rax), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb 0x1(%rax), %cl
movq -0x30(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x30(%rbp)
movb %cl, (%rax)
movq -0x30(%rbp), %rax
movb $0x42, (%rax)
movq -0x40(%rbp), %rdx
addq $0x8, %rdx
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x40(%rax)
jmp 0x418f2
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x418f0
movq -0x30(%rbp), %rdi
addq $0x6, %rdi
addq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x6, %rsi
addq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rdx
movq -0x30(%rbp), %rax
addq $0x6, %rax
addq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
subq %rax, %rdx
callq 0x4810
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rcx
subq %rdx, %rcx
movl %ecx, 0x40(%rax)
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x40(%rax)
jmp 0x418f2
movb -0x19(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x20(%rbp), %edi
movq -0x30(%rbp), %rsi
addq $0x2, %rsi
callq 0x34b90
cmpq $0x0, -0x40(%rbp)
jbe 0x41928
movq -0x30(%rbp), %rdi
addq $0x6, %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x43b0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)