// File: karel-brinda[P]ococo/ext/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)
{
    uint8_t *s = bam_aux_get(b,tag);
    if (!s) return -1;
    char type = *s;
    if (type != 'Z') { fprintf(stderr,"bam_aux_update_str() called for type '%c' instead of 'Z'\n", type); abort(); }
    bam_aux_del(b,s);
    s -= 2;
    int l_aux = bam_get_l_aux(b);
    uint8_t *aux = bam_get_aux(b);

    b->l_data += 3 + len;
    if (b->m_data < b->l_data) {
        b->m_data = b->l_data;
        kroundup32(b->m_data);
        b->data = (uint8_t*)realloc(b->data, b->m_data);
    }
    memmove(s+3+len, s, l_aux - (s - aux));
    s[0] = tag[0];
    s[1] = tag[1];
    s[2] = type;
    memmove(s+3,data,len);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x20160
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2047b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2069c
movq -0x30(%rbp), %rax
movb (%rax), %al
movb %al, -0x31(%rbp)
movsbl -0x31(%rbp), %eax
cmpl $0x5a, %eax
je 0x204ae
movq 0x69b3c(%rip), %rax     # 0x89fd0
movq (%rax), %rdi
movsbl -0x31(%rbp), %edx
leaq 0x5b309(%rip), %rsi     # 0x7b7ab
movb $0x0, %al
callq 0x4830
callq 0x42e0
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x20330
movq -0x30(%rbp), %rax
addq $-0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
subl %ecx, %eax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
subl %ecx, %eax
movq -0x10(%rbp), %rcx
subl 0x10(%rcx), %eax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl $0x1, %ecx
sarl %ecx
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x30, %rcx
shll $0x2, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x18, %rcx
andq $0xff, %rcx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl $0x1, %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %ecx
addl $0x3, %ecx
movq -0x10(%rbp), %rax
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x20632
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
sarl %ecx
movq -0x10(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x2, %ecx
movq -0x10(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x4, %ecx
movq -0x10(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x8, %ecx
movq -0x10(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
sarl $0x10, %ecx
movq -0x10(%rbp), %rax
orl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x24(%rax), %rsi
callq 0x4990
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rdi
addq $0x3, %rdi
movslq -0x1c(%rbp), %rax
addq %rax, %rdi
movq -0x30(%rbp), %rsi
movslq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
subq %rax, %rdx
callq 0x4970
movq -0x18(%rbp), %rax
movb (%rax), %cl
movq -0x30(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb 0x1(%rax), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x1(%rax)
movb -0x31(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x30(%rbp), %rdi
addq $0x3, %rdi
movq -0x28(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x4970
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)