// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: bam_aux_update_str
int bam_aux_update_str(bam1_t *b, const char tag[2], int len, const char *data)
{
    // FIXME: This is not at all efficient!
    size_t ln = len >= 0 ? len : strlen(data) + 1;
    size_t old_ln = 0;
    int need_nul = ln == 0 || data[ln - 1] != '\0';
    int save_errno = errno;
    int new_tag = 0;
    uint8_t *s = bam_aux_get(b,tag), *e;

    if (s) {  // Replacing existing tag
        char type = *s;
        if (type != 'Z') {
            hts_log_error("Called bam_aux_update_str for type '%c' instead of 'Z'", type);
            errno = EINVAL;
            return -1;
        }
        s++;
        e = memchr(s, '\0', b->data + b->l_data - s);
        old_ln = (e ? e - s : b->data + b->l_data - s) + 1;
        s -= 3;
    } else {
        if (errno != ENOENT) { // Invalid aux data, give up
            return -1;
        } else { // Tag doesn't exist - put it on the end
            errno = save_errno;
            s = b->data + b->l_data;
            new_tag = 3;
        }
    }

    if (old_ln < ln + need_nul + new_tag) {
        ptrdiff_t s_offset = s - b->data;
        if (possibly_expand_bam_data(b, ln + need_nul + new_tag - old_ln) < 0)
            return -1;
        s = b->data + s_offset;
    }
    if (!new_tag) {
        memmove(s + 3 + ln + need_nul,
                s + 3 + old_ln,
                b->l_data - (s + 3 - b->data) - old_ln);
    }
    b->l_data += new_tag + ln + need_nul - old_ln;

    s[0] = tag[0];
    s[1] = tag[1];
    s[2] = 'Z';
    memmove(s+3,data,ln);
    if (need_nul) s[3 + ln] = '\0';
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x40eaa
movslq -0x1c(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x40ebb
movq -0x28(%rbp), %rdi
callq 0x41b0
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movb $0x1, %al
cmpq $0x0, -0x30(%rbp)
movb %al, -0x71(%rbp)
je 0x40ef0
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x3c(%rbp)
callq 0x4050
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e760
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x40ff4
movq -0x50(%rbp), %rax
movb (%rax), %al
movb %al, -0x59(%rbp)
movsbl -0x59(%rbp), %eax
cmpl $0x5a, %eax
je 0x40f6f
movsbl -0x59(%rbp), %ecx
movl $0x1, %edi
leaq 0xb1396(%rip), %rsi     # 0xf22e0
leaq 0xb13a2(%rip), %rdx     # 0xf22f3
movb $0x0, %al
callq 0x1b030
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4116f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdx
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rax
addq %rax, %rdx
movq -0x50(%rbp), %rax
subq %rax, %rdx
xorl %esi, %esi
callq 0x4530
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x40fbc
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x80(%rbp)
jmp 0x40fda
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
addq %rcx, %rax
movq -0x50(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
addq $-0x3, %rax
movq %rax, -0x50(%rbp)
jmp 0x41040
callq 0x4050
cmpl $0x2, (%rax)
je 0x4100a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4116f
movl -0x40(%rbp), %eax
movl %eax, -0x84(%rbp)
callq 0x4050
movl -0x84(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x3, -0x44(%rbp)
jmp 0x41040
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
addq %rdx, %rcx
movslq -0x44(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x410ae
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movslq -0x3c(%rbp), %rax
addq %rax, %rsi
movslq -0x44(%rbp), %rax
addq %rax, %rsi
subq -0x38(%rbp), %rsi
callq 0x3a350
cmpl $0x0, %eax
jge 0x4109e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4116f
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x410fa
movq -0x50(%rbp), %rdi
addq $0x3, %rdi
addq -0x30(%rbp), %rdi
movslq -0x3c(%rbp), %rax
addq %rax, %rdi
movq -0x50(%rbp), %rsi
addq $0x3, %rsi
addq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rdx
movq -0x50(%rbp), %rax
addq $0x3, %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
subq %rax, %rdx
subq -0x38(%rbp), %rdx
callq 0x4810
movslq -0x44(%rbp), %rdx
addq -0x30(%rbp), %rdx
movslq -0x3c(%rbp), %rax
addq %rax, %rdx
subq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0x40(%rax)
movq -0x18(%rbp), %rax
movb (%rax), %cl
movq -0x50(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb 0x1(%rax), %cl
movq -0x50(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x50(%rbp), %rax
movb $0x5a, 0x2(%rax)
movq -0x50(%rbp), %rdi
addq $0x3, %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x4810
cmpl $0x0, -0x3c(%rbp)
je 0x41168
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
addq $0x3, %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)