// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/sam.c
// Function: sam_format1_append
static int sam_format1_append(const bam_hdr_t *h, const bam1_t *b, kstring_t *str)
{
    int i, r = 0;
    uint8_t *s, *end;
    const bam1_core_t *c = &b->core;

    if (c->l_qname == 0)
        return -1;
    r |= kputsn_(bam_get_qname(b), c->l_qname-1-c->l_extranul, str);
    r |= kputc_('\t', str); // query name
    r |= kputw(c->flag, str); r |= kputc_('\t', str); // flag
    if (c->tid >= 0) { // chr
        r |= kputs(h->target_name[c->tid] , str);
        r |= kputc_('\t', str);
    } else r |= kputsn_("*\t", 2, str);
    r |= kputll(c->pos + 1, str); r |= kputc_('\t', str); // pos
    r |= kputw(c->qual, str); r |= kputc_('\t', str); // qual
    if (c->n_cigar) { // cigar
        uint32_t *cigar = bam_get_cigar(b);
        for (i = 0; i < c->n_cigar; ++i) {
            r |= kputw(bam_cigar_oplen(cigar[i]), str);
            r |= kputc_(bam_cigar_opchr(cigar[i]), str);
        }
    } else r |= kputc_('*', str);
    r |= kputc_('\t', str);
    if (c->mtid < 0) r |= kputsn_("*\t", 2, str); // mate chr
    else if (c->mtid == c->tid) r |= kputsn_("=\t", 2, str);
    else {
        r |= kputs(h->target_name[c->mtid], str);
        r |= kputc_('\t', str);
    }
    r |= kputll(c->mpos + 1, str); r |= kputc_('\t', str); // mate pos
    r |= kputll(c->isize, str); r |= kputc_('\t', str); // template len
    if (c->l_qseq) { // seq and qual
        uint8_t *s = bam_get_seq(b);
        if (ks_resize(str, str->l+2+2*c->l_qseq) < 0) goto mem_err;
        char *cp = str->s + str->l;

        // Sequence, 2 bases at a time
        nibble2base(s, cp, c->l_qseq);
        cp[c->l_qseq] = '\t';
        cp += c->l_qseq+1;

        // Quality
        s = bam_get_qual(b);
        i = 0;
        if (s[0] == 0xff) {
            cp[i++] = '*';
        } else {
            add33((uint8_t *)cp, s, c->l_qseq); // cp[i] = s[i]+33;
            i = c->l_qseq;
        }
        cp[i] = 0;
        cp += i;
        str->l = cp - str->s;
    } else r |= kputsn_("*\t*", 3, str);

    s = bam_get_aux(b); // aux
    end = b->data + b->l_data;

    while (end - s >= 4) {
        r |= kputc_('\t', str);
        if ((s = (uint8_t *)sam_format_aux1(s, s[2], s+3, end, str)) == NULL)
            goto bad_aux;
    }
    r |= kputsn("", 0, str); // nul terminate
    if (r < 0) goto mem_err;

    return str->l;

 bad_aux:
    hts_log_error("Corrupted aux data for read %.*s flag %d",
                  b->core.l_qname, bam_get_qname(b), b->core.flag);
    errno = EINVAL;
    return -1;

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, (%rsp)
movzwl 0x12(%rsi), %ecx
pushq $-0x1
popq %rax
testq %rcx, %rcx
je 0x24055
movq %rdx, %r14
movq %rsi, %r15
movq 0x38(%rsi), %rdi
movzbl 0xf(%rsi), %esi
notq %rsi
addq %rcx, %rsi
callq 0x29b5e
movl %eax, %ebx
pushq $0x9
popq %rbp
movl %ebp, %edi
movq %r14, %rsi
callq 0x24655
movl %eax, %r13d
movzwl 0x10(%r15), %edi
movq %r14, %rsi
callq 0x21504
movl %eax, %r12d
orl %r13d, %r12d
movl %ebp, %edi
movq %r14, %rsi
callq 0x24655
movl %eax, %ebp
orl %r12d, %ebp
orl %ebx, %ebp
movslq 0x8(%r15), %rax
testq %rax, %rax
js 0x23d24
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x214c5
movl %eax, %r12d
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x24655
movl %eax, %ebx
orl %r12d, %ebx
jmp 0x23d38
leaq 0x569c5(%rip), %rdi     # 0x7a6f0
pushq $0x2
popq %rsi
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebx
movq (%r15), %rdi
incq %rdi
movq %r14, %rsi
callq 0x28928
movl %eax, %r12d
orl %ebx, %r12d
pushq $0x9
popq %rbx
movl %ebx, %edi
movq %r14, %rsi
callq 0x24655
movl %eax, %r13d
orl %r12d, %r13d
orl %ebp, %r13d
movzbl 0xe(%r15), %edi
movq %r14, %rsi
callq 0x21504
movl %eax, %r12d
movl %ebx, %edi
movq %r14, %rsi
callq 0x24655
movl %eax, %ebp
orl %r12d, %ebp
orl %r13d, %ebp
movl 0x14(%r15), %eax
testl %eax, %eax
je 0x23dd9
movzwl 0x12(%r15), %r12d
addq 0x38(%r15), %r12
xorl %r13d, %r13d
movl %eax, %eax
cmpq %rax, %r13
jae 0x23de6
movl (%r12,%r13,4), %edi
shrl $0x4, %edi
movq %r14, %rsi
callq 0x21504
movl %eax, %ebx
movl (%r12,%r13,4), %eax
andl $0xf, %eax
leaq 0x5618d(%rip), %rcx     # 0x79f4b
movsbl (%rax,%rcx), %edi
movq %r14, %rsi
callq 0x24655
orl %ebp, %ebx
orl %eax, %ebx
incq %r13
movl 0x14(%r15), %eax
movl %ebx, %ebp
jmp 0x23d98
pushq $0x2a
popq %rdi
movq %r14, %rsi
callq 0x24655
orl %eax, %ebp
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x24655
movl %eax, %r13d
orl %ebp, %r13d
movslq 0x1c(%r15), %rax
testq %rax, %rax
js 0x23e0f
cmpl 0x8(%r15), %eax
jne 0x23e25
leaq 0x568e6(%rip), %rdi     # 0x7a6f3
jmp 0x23e16
leaq 0x568da(%rip), %rdi     # 0x7a6f0
pushq $0x2
popq %rsi
movq %r14, %rdx
callq 0x29b5e
movl %eax, %ebx
jmp 0x23e4a
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x214c5
movl %eax, %ebp
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x24655
movl %eax, %ebx
orl %ebp, %ebx
orl %r13d, %ebx
movq 0x20(%r15), %rdi
incq %rdi
movq %r14, %rsi
callq 0x28928
movl %eax, %ebp
pushq $0x9
popq %r12
movl %r12d, %edi
movq %r14, %rsi
callq 0x24655
movl %eax, %r13d
orl %ebx, %r13d
movq 0x28(%r15), %rdi
movq %r14, %rsi
callq 0x28928
movl %eax, %ebx
orl %r13d, %ebx
orl %ebp, %ebx
movl %r12d, %edi
movq %r14, %rsi
callq 0x24655
movl %eax, %ebp
orl %ebx, %ebp
movslq 0x18(%r15), %rax
testq %rax, %rax
je 0x23f46
movq %r15, %r13
movq 0x38(%r15), %r15
movl 0x14(%r13), %ebx
movzwl 0x12(%r13), %r12d
movq (%r14), %rcx
leaq (%rcx,%rax,2), %rsi
addq $0x2, %rsi
movq %r14, %rdi
callq 0x24d14
testl %eax, %eax
js 0x2402f
addq %r12, %r15
shll $0x2, %ebx
addq %r15, %rbx
movq 0x10(%r14), %r12
addq (%r14), %r12
movl 0x18(%r13), %edx
leaq 0x7a8a0(%rip), %rax     # 0x9e788
movq %rbx, %rdi
movq %r12, %rsi
callq *(%rax)
movslq 0x18(%r13), %rax
movb $0x9, (%rax,%r12)
movslq 0x18(%r13), %rdx
leaq 0x1(%rdx), %rsi
leaq (%rdx,%r12), %rax
incq %rax
movl 0x14(%r13), %edi
shll $0x2, %edi
addq 0x38(%r13), %rdi
movzwl 0x12(%r13), %ecx
addq %rdi, %rcx
sarl %esi
movslq %esi, %rsi
cmpb $-0x1, (%rsi,%rcx)
movq %r13, %r15
je 0x23f62
movl %edx, %edx
addq %rsi, %rcx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x23f5c
movb (%rcx,%rsi), %dil
addb $0x21, %dil
movb %dil, (%rax,%rsi)
incq %rsi
jmp 0x23f30
leaq 0x567a9(%rip), %rdi     # 0x7a6f6
pushq $0x3
popq %rsi
movq %r14, %rdx
callq 0x29b5e
orl %eax, %ebp
jmp 0x23f77
movslq 0x18(%r15), %rcx
jmp 0x23f68
movb $0x2a, (%rax)
pushq $0x1
popq %rcx
leaq (%rax,%rcx), %rdx
movb $0x0, (%rax,%rcx)
subq 0x10(%r14), %rdx
movq %rdx, (%r14)
movq 0x38(%r15), %rax
movl 0x14(%r15), %ecx
shll $0x2, %ecx
movzwl 0x12(%r15), %r12d
addq %rax, %r12
addq %rcx, %r12
movslq 0x18(%r15), %rcx
leal 0x1(%rcx), %edx
sarl %edx
movslq %edx, %rdx
addq %rcx, %r12
addq %rdx, %r12
movslq 0x40(%r15), %r13
addq %rax, %r13
pushq $0x9
popq %rbx
movq %r13, %rax
subq %r12, %rax
cmpq $0x4, %rax
jl 0x24015
movl %ebx, %edi
movq %r14, %rsi
callq 0x24655
orl %eax, %ebp
movzbl 0x2(%r12), %esi
leaq 0x3(%r12), %rdx
movq %r12, %rdi
movq %r13, %rcx
movq %r14, %r8
callq 0x24690
movq %rax, %r12
testq %rax, %rax
jne 0x23fa9
movzwl 0x12(%r15), %ecx
movq 0x38(%r15), %r8
movzwl 0x10(%r15), %r9d
leaq 0x56703(%rip), %rsi     # 0x7a6fa
leaq 0x5670f(%rip), %rdx     # 0x7a70d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
callq 0x4050
movl $0x16, (%rax)
jmp 0x24052
leaq 0x53d3a(%rip), %rdi     # 0x77d56
xorl %esi, %esi
movq %r14, %rdx
callq 0x21461
orl %ebp, %eax
js 0x2402f
movl (%r14), %eax
jmp 0x24055
leaq 0x566c4(%rip), %rsi     # 0x7a6fa
leaq 0x555a8(%rip), %rdx     # 0x795e5
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x110c6
callq 0x4050
movl $0xc, (%rax)
pushq $-0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq