// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/sam.c
// Function: bam_aux_update_int
int bam_aux_update_int(bam1_t *b, const char tag[2], int64_t val)
{
    uint32_t sz, old_sz = 0, new = 0;
    uint8_t *s, type;

    if (val < INT32_MIN || val > UINT32_MAX) {
        errno = EOVERFLOW;
        return -1;
    }
    if (val < INT16_MIN)       { type = 'i'; sz = 4; }
    else if (val < INT8_MIN)   { type = 's'; sz = 2; }
    else if (val < 0)          { type = 'c'; sz = 1; }
    else if (val < UINT8_MAX)  { type = 'C'; sz = 1; }
    else if (val < UINT16_MAX) { type = 'S'; sz = 2; }
    else                       { type = 'I'; sz = 4; }

    s = bam_aux_get(b, tag);
    if (s) {  // Tag present - how big was the old one?
        switch (*s) {
            case 'c': case 'C': old_sz = 1; break;
            case 's': case 'S': old_sz = 2; break;
            case 'i': case 'I': old_sz = 4; break;
            default: errno = EINVAL; return -1;  // Not an integer
        }
    } 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;
        }
    }

    if (new || old_sz < sz) {
        // Make room for new tag
        ptrdiff_t s_offset = s - b->data;
        if (possibly_expand_bam_data(b, (new ? 3 : 0) + sz - old_sz) < 0)
            return -1;
        s =  b->data + s_offset;
        if (new) { // Add tag id
            *s++ = tag[0];
            *s++ = tag[1];
        } else {   // Shift following data so we have space
            memmove(s + sz, s + old_sz, b->l_data - s_offset - old_sz);
        }
    } else {
        // Reuse old space.  Data value may be bigger than necessary but
        // we avoid having to move everything else
        sz = old_sz;
        type = (val < 0 ? "\0cs\0i" : "\0CS\0I")[old_sz];
        assert(type > 0);
    }
    *s++ = type;
#ifdef HTS_LITTLE_ENDIAN
    memcpy(s, &val, sz);
#else
    switch (sz) {
        case 4:  u32_to_le(val, s); break;
        case 2:  u16_to_le(val, s); break;
        default: *s = val; break;
    }
#endif
    b->l_data += (new ? 3 : 0) + sz - old_sz;
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpq $-0x80000000, -0x20(%rbp) # imm = 0x80000000
jl 0x411b7
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, -0x20(%rbp)
jle 0x411ce
callq 0x4050
movl $0x4b, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41484
cmpq $-0x8000, -0x20(%rbp)   # imm = 0x8000
jge 0x411e5
movb $0x69, -0x39(%rbp)
movl $0x4, -0x24(%rbp)
jmp 0x4124e
cmpq $-0x80, -0x20(%rbp)
jge 0x411f9
movb $0x73, -0x39(%rbp)
movl $0x2, -0x24(%rbp)
jmp 0x4124c
cmpq $0x0, -0x20(%rbp)
jge 0x4120d
movb $0x63, -0x39(%rbp)
movl $0x1, -0x24(%rbp)
jmp 0x4124a
cmpq $0xff, -0x20(%rbp)
jge 0x41224
movb $0x43, -0x39(%rbp)
movl $0x1, -0x24(%rbp)
jmp 0x41248
cmpq $0xffff, -0x20(%rbp)    # imm = 0xFFFF
jge 0x4123b
movb $0x53, -0x39(%rbp)
movl $0x2, -0x24(%rbp)
jmp 0x41246
movb $0x49, -0x39(%rbp)
movl $0x4, -0x24(%rbp)
jmp 0x41248
jmp 0x4124a
jmp 0x4124c
jmp 0x4124e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e760
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x412dd
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x4c(%rbp)
subl $0x43, %eax
je 0x412a9
jmp 0x41277
movl -0x4c(%rbp), %eax
subl $0x49, %eax
je 0x412bb
jmp 0x41281
movl -0x4c(%rbp), %eax
subl $0x53, %eax
je 0x412b2
jmp 0x4128b
movl -0x4c(%rbp), %eax
subl $0x63, %eax
je 0x412a9
jmp 0x41295
movl -0x4c(%rbp), %eax
subl $0x69, %eax
je 0x412bb
jmp 0x4129f
movl -0x4c(%rbp), %eax
subl $0x73, %eax
je 0x412b2
jmp 0x412c4
movl $0x1, -0x28(%rbp)
jmp 0x412db
movl $0x2, -0x28(%rbp)
jmp 0x412db
movl $0x4, -0x28(%rbp)
jmp 0x412db
callq 0x4050
movl $0x16, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41484
jmp 0x41315
callq 0x4050
cmpl $0x2, (%rax)
jne 0x41307
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x40(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
jmp 0x41313
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41484
jmp 0x41315
cmpl $0x0, -0x2c(%rbp)
jne 0x41327
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x413e2
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x38(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x2c(%rbp), %edx
xorl %eax, %eax
movl $0x3, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
addl -0x24(%rbp), %eax
subl -0x28(%rbp), %eax
movl %eax, %eax
movl %eax, %esi
callq 0x3a350
cmpl $0x0, %eax
jge 0x4136e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41484
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
addq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x413b5
movq -0x18(%rbp), %rax
movb (%rax), %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movb 0x1(%rax), %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
jmp 0x413e0
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %eax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movl -0x28(%rbp), %eax
addq %rax, %rsi
movq -0x10(%rbp), %rax
movslq 0x40(%rax), %rdx
subq -0x48(%rbp), %rdx
movl -0x28(%rbp), %eax
subq %rax, %rdx
callq 0x4810
jmp 0x41437
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rdx
leaq 0xb04a8(%rip), %rax     # 0xf189b
leaq 0xb049b(%rip), %rcx     # 0xf1895
cmpq $0x0, %rdx
cmovlq %rcx, %rax
movl -0x28(%rbp), %ecx
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
cmpl $0x0, %eax
jle 0x41416
jmp 0x41435
leaq 0xb0f0d(%rip), %rdi     # 0xf232a
leaq 0xb0e20(%rip), %rsi     # 0xf2244
movl $0x13d0, %edx           # imm = 0x13D0
leaq 0xb0f03(%rip), %rcx     # 0xf2333
callq 0x42e0
jmp 0x41437
movb -0x39(%rbp), %cl
movq -0x38(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x38(%rbp)
movb %cl, (%rax)
movq -0x38(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, %edx
leaq -0x20(%rbp), %rsi
callq 0x43b0
movl -0x2c(%rbp), %edx
xorl %ecx, %ecx
movl $0x3, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
addl -0x24(%rbp), %ecx
subl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x40(%rax), %ecx
movl %ecx, 0x40(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)