// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/./htslib/sam.h
// Function: sam_format_aux1
static inline const uint8_t *sam_format_aux1(const uint8_t *key,
                                             const uint8_t type,
                                             const uint8_t *tag,
                                             const uint8_t *end,
                                             kstring_t *ks) {
    int r = 0;
    const uint8_t *s = tag; // brevity and consistency with other code.
    r |= kputsn_((char*)key, 2, ks) < 0;
    r |= kputc_(':', ks) < 0;
    if (type == 'C') {
        r |= kputsn_("i:", 2, ks) < 0;
        r |= kputw(*s, ks) < 0;
        ++s;
    } else if (type == 'c') {
        r |= kputsn_("i:", 2, ks) < 0;
        r |= kputw(*(int8_t*)s, ks) < 0;
        ++s;
    } else if (type == 'S') {
        if (end - s >= 2) {
            r |= kputsn_("i:", 2, ks) < 0;
            r |= kputuw(le_to_u16(s), ks) < 0;
            s += 2;
        } else goto bad_aux;
    } else if (type == 's') {
        if (end - s >= 2) {
            r |= kputsn_("i:", 2, ks) < 0;
            r |= kputw(le_to_i16(s), ks) < 0;
            s += 2;
        } else goto bad_aux;
    } else if (type == 'I') {
        if (end - s >= 4) {
            r |= kputsn_("i:", 2, ks) < 0;
            r |= kputuw(le_to_u32(s), ks) < 0;
            s += 4;
        } else goto bad_aux;
    } else if (type == 'i') {
        if (end - s >= 4) {
            r |= kputsn_("i:", 2, ks) < 0;
            r |= kputw(le_to_i32(s), ks) < 0;
            s += 4;
        } else goto bad_aux;
    } else if (type == 'A') {
        r |= kputsn_("A:", 2, ks) < 0;
        r |= kputc_(*s, ks) < 0;
        ++s;
    } else if (type == 'f') {
        if (end - s >= 4) {
            // cast to avoid triggering -Wdouble-promotion
            ksprintf(ks, "f:%g", (double)le_to_float(s));
            s += 4;
        } else goto bad_aux;

    } else if (type == 'd') {
        // NB: "d" is not an official type in the SAM spec.
        // However for unknown reasons samtools has always supported this.
        // We believe, HOPE, it is not in general usage and we do not
        // encourage it.
        if (end - s >= 8) {
            ksprintf(ks, "d:%g", le_to_double(s));
            s += 8;
        } else goto bad_aux;
    } else if (type == 'Z' || type == 'H') {
        r |= kputc_(type, ks) < 0;
        r |= kputc_(':', ks) < 0;
        while (s < end && *s) r |= kputc_(*s++, ks) < 0;
        r |= kputsn("", 0, ks) < 0;     //ensures NUL termination
        if (s >= end)
            goto bad_aux;
        ++s;
    } else if (type == 'B') {
        uint8_t sub_type = *(s++);
        unsigned sub_type_size;

        // or externalise sam.c's aux_type2size function?
        switch (sub_type) {
        case 'A': case 'c': case 'C':
            sub_type_size = 1;
            break;
        case 's': case 'S':
            sub_type_size = 2;
            break;
        case 'i': case 'I': case 'f':
            sub_type_size = 4;
            break;
        default:
            sub_type_size = 0;
            break;
        }

        uint32_t i, n;
        if (sub_type_size == 0 || end - s < 4)
            goto bad_aux;
        n = le_to_u32(s);
        s += 4; // now points to the start of the array
        if ((size_t)(end - s) / sub_type_size < n)
            goto bad_aux;
        r |= kputsn_("B:", 2, ks) < 0;
        r |= kputc(sub_type, ks) < 0; // write the type
        switch (sub_type) {
        case 'c':
            if (ks_expand(ks, n*2) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                r |= kputw(*(int8_t*)s, ks) < 0;
                ++s;
            }
            break;
        case 'C':
            if (ks_expand(ks, n*2) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                r |= kputuw(*(uint8_t*)s, ks) < 0;
                ++s;
            }
            break;
        case 's':
            if (ks_expand(ks, n*4) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                r |= kputw(le_to_i16(s), ks) < 0;
                s += 2;
            }
            break;
        case 'S':
            if (ks_expand(ks, n*4) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                r |= kputuw(le_to_u16(s), ks) < 0;
                s += 2;
            }
            break;
        case 'i':
            if (ks_expand(ks, n*6) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                r |= kputw(le_to_i32(s), ks) < 0;
                s += 4;
            }
            break;
        case 'I':
            if (ks_expand(ks, n*6) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                r |= kputuw(le_to_u32(s), ks) < 0;
                s += 4;
            }
            break;
        case 'f':
            if (ks_expand(ks, n*8) < 0) goto mem_err;
            for (i = 0; i < n; ++i) {
                ks->s[ks->l++] = ',';
                // cast to avoid triggering -Wdouble-promotion
                r |= kputd((double)le_to_float(s), ks) < 0;
                s += 4;
            }
            break;
        default:
            goto bad_aux;
        }
    } else { // Unknown type
        goto bad_aux;
    }
    return r ? NULL : s;

 bad_aux:
    errno = EINVAL;
    return NULL;

 mem_err:
    hts_log_error("Out of memory");
    errno = ENOMEM;
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %rbx
movl %esi, %r13d
pushq $0x2
popq %rbp
movq %rbp, %rsi
movq %r8, %rdx
callq 0x29b5e
movl %eax, %r14d
pushq $0x3a
popq %rdi
movq %r15, (%rsp)
movq %r15, %rsi
callq 0x24655
movl %eax, %r15d
orl %r14d, %r15d
leal -0x41(%r13), %eax
cmpl $0x8, %eax
jbe 0x24715
leal -0x63(%r13), %eax
cmpl $0x6, %eax
ja 0x2474d
movl %r15d, %ebp
shrl $0x1f, %ebp
leaq 0x54bcc(%rip), %rcx     # 0x792b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5603a(%rip), %rdi     # 0x7a736
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movsbl (%rbx), %edi
jmp 0x24824
leaq 0x54b78(%rip), %rcx     # 0x79294
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5600d(%rip), %rdi     # 0x7a739
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movzbl (%rbx), %edi
movq %r14, %rsi
callq 0x24655
jmp 0x2482c
cmpl $0x53, %r13d
je 0x2493b
cmpl $0x5a, %r13d
je 0x2479c
cmpl $0x73, %r13d
jne 0x249bb
subq %rbx, %r12
cmpq $0x2, %r12
jl 0x249bb
leaq 0x55fbb(%rip), %rdi     # 0x7a736
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movswl (%rbx), %edi
movq %r14, %rsi
callq 0x21504
jmp 0x24967
movzbl %r13b, %edi
movq (%rsp), %r14
movq %r14, %rsi
callq 0x24655
movl %eax, %ebp
pushq $0x3a
popq %rdi
movq %r14, %rsi
callq 0x24655
movl %eax, %r13d
orl %ebp, %r13d
orl %r15d, %r13d
shrl $0x1f, %r13d
cmpq %r12, %rbx
jae 0x247e5
movzbl (%rbx), %edi
testl %edi, %edi
je 0x247e5
incq %rbx
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %r13d
jmp 0x247c6
leaq 0x5356a(%rip), %rdi     # 0x77d56
xorl %esi, %esi
movq %r14, %rdx
callq 0x21461
cmpq %r12, %rbx
jae 0x249bb
movl %eax, %ebp
shrl $0x1f, %ebp
orl %r13d, %ebp
jmp 0x24834
leaq 0x55f26(%rip), %rdi     # 0x7a736
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movzbl (%rbx), %edi
movq %r14, %rsi
callq 0x21504
orl %r15d, %ebp
orl %eax, %ebp
shrl $0x1f, %ebp
incq %rbx
jmp 0x24973
movzbl (%rbx), %r13d
leal -0x41(%r13), %eax
cmpl $0x32, %eax
ja 0x249bb
movabsq $0x400000005, %rcx      # imm = 0x400000005
btq %rax, %rcx
jb 0x2497e
movabsq $0x12000000100, %rcx    # imm = 0x12000000100
btq %rax, %rcx
jae 0x24983
pushq $0x4
jmp 0x24980
subq %rbx, %r12
cmpq $0x4, %r12
jl 0x249bb
leaq 0x55ea6(%rip), %rdi     # 0x7a736
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movl (%rbx), %edi
movq %r14, %rsi
callq 0x28a2f
jmp 0x24908
subq %rbx, %r12
cmpq $0x8, %r12
jl 0x249bb
movsd (%rbx), %xmm0
leaq 0x55e7c(%rip), %rsi     # 0x7a741
movq (%rsp), %rdi
movb $0x1, %al
callq 0x8c78
addq $0x8, %rbx
jmp 0x24973
subq %rbx, %r12
cmpq $0x4, %r12
jl 0x249bb
leaq 0x55e49(%rip), %rdi     # 0x7a736
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movl (%rbx), %edi
movq %r14, %rsi
callq 0x21504
orl %r15d, %ebp
orl %eax, %ebp
shrl $0x1f, %ebp
jmp 0x24935
subq %rbx, %r12
cmpq $0x4, %r12
jl 0x249bb
cvtss2sd (%rbx), %xmm0
leaq 0x55e12(%rip), %rsi     # 0x7a73c
movq (%rsp), %rdi
movb $0x1, %al
callq 0x8c78
addq $0x4, %rbx
jmp 0x24973
subq %rbx, %r12
cmpq $0x2, %r12
jl 0x249bb
leaq 0x55deb(%rip), %rdi     # 0x7a736
pushq $0x2
popq %rsi
movq (%rsp), %r14
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebp
movzwl (%rbx), %edi
movq %r14, %rsi
callq 0x28a2f
orl %r15d, %ebp
orl %eax, %ebp
shrl $0x1f, %ebp
addq $0x2, %rbx
xorl %r14d, %r14d
testl %ebp, %ebp
cmoveq %rbx, %r14
jmp 0x249c9
pushq $0x1
popq %rbp
jmp 0x24993
movabsq $0x4000000040000, %rcx  # imm = 0x4000000040000
btq %rax, %rcx
jae 0x249bb
leaq 0x1(%rbx), %rax
movq %r12, %rcx
subq %rax, %rcx
cmpq $0x4, %rcx
jl 0x249bb
movl 0x1(%rbx), %r14d
addq $0x5, %rbx
subq %rbx, %r12
movq %r12, %rax
xorl %edx, %edx
divq %rbp
cmpq %r14, %rax
jae 0x249db
callq 0x4050
movl $0x16, (%rax)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55d64(%rip), %rdi     # 0x7a746
pushq $0x2
popq %rsi
movq (%rsp), %r12
movq %r12, %rdx
callq 0x29b5e
movl %eax, %ebp
movl %r13d, %edi
movq %r12, %rsi
callq 0x21551
orl %r15d, %ebp
orl %eax, %ebp
shrl $0x1f, %ebp
cmpl $0x43, %r13d
je 0x24b6f
cmpl $0x49, %r13d
je 0x24bfe
cmpl $0x53, %r13d
movq (%rsp), %r15
je 0x24bb8
cmpl $0x73, %r13d
je 0x24a95
cmpl $0x66, %r13d
je 0x24b24
cmpl $0x69, %r13d
je 0x24adf
cmpl $0x63, %r13d
jne 0x249bb
leal (%r14,%r14), %esi
movq (%rsp), %r15
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
movsbl (%rbx), %edi
movq %r15, %rsi
callq 0x21504
shrl $0x1f, %eax
orl %eax, %ebp
incq %rbx
jmp 0x24a64
leal (,%r14,4), %esi
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
movswl (%rbx), %edi
movq %r15, %rsi
callq 0x21504
shrl $0x1f, %eax
orl %eax, %ebp
addq $0x2, %rbx
jmp 0x24aad
imull $0x6, %r14d, %esi
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
movl (%rbx), %edi
movq %r15, %rsi
callq 0x21504
shrl $0x1f, %eax
orl %eax, %ebp
addq $0x4, %rbx
jmp 0x24af3
leal (,%r14,8), %esi
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
cvtss2sd (%rbx), %xmm0
movq %r15, %rdi
callq 0x8758
shrl $0x1f, %eax
orl %eax, %ebp
addq $0x4, %rbx
jmp 0x24b3c
leal (%r14,%r14), %esi
movq (%rsp), %r15
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
movzbl (%rbx), %edi
movq %r15, %rsi
callq 0x28a2f
shrl $0x1f, %eax
orl %eax, %ebp
incq %rbx
jmp 0x24b87
leal (,%r14,4), %esi
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
movzwl (%rbx), %edi
movq %r15, %rsi
callq 0x28a2f
shrl $0x1f, %eax
orl %eax, %ebp
addq $0x2, %rbx
jmp 0x24bcc
imull $0x6, %r14d, %esi
movq (%rsp), %r15
movq %r15, %rdi
callq 0x29bb7
testl %eax, %eax
js 0x24c43
subl $0x1, %r14d
jb 0x24973
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
movb $0x2c, (%rcx,%rax)
movl (%rbx), %edi
movq %r15, %rsi
callq 0x28a2f
shrl $0x1f, %eax
orl %eax, %ebp
addq $0x4, %rbx
jmp 0x24c12
leaq 0x55aff(%rip), %rsi     # 0x7a749
leaq 0x54994(%rip), %rdx     # 0x795e5
xorl %r14d, %r14d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
callq 0x4050
movl $0xc, (%rax)
jmp 0x249c9