// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/sam.c
// Function: fastq_format1
int fastq_format1(fastq_state *x, const bam1_t *b, kstring_t *str)
{
    unsigned flag = b->core.flag;
    int i, e = 0, len = b->core.l_qseq;
    uint8_t *seq, *qual;

    str->l = 0;

    // Name
    if (kputc(x->nprefix, str) == EOF || kputs(bam_get_qname(b), str) == EOF)
        return -1;

    // /1 or /2 suffix
    if (x && x->rnum && (flag & BAM_FPAIRED)) {
        int r12 = flag & (BAM_FREAD1 | BAM_FREAD2);
        if (r12 == BAM_FREAD1) {
            if (kputs("/1", str) == EOF)
                return -1;
        } else if (r12 == BAM_FREAD2) {
            if (kputs("/2", str) == EOF)
                return -1;
        }
    }

    // Illumina CASAVA tag.
    // This is <rnum>:<Y/N qcfail>:<control-bits>:<barcode-or-zero>
    if (x && x->casava) {
        int rnum = (flag & BAM_FREAD1)? 1 : (flag & BAM_FREAD2)? 2 : 0;
        char filtered = (flag & BAM_FQCFAIL)? 'Y' : 'N';
        uint8_t *bc = bam_aux_get(b, x->BC);
        if (ksprintf(str, " %d:%c:0:%s", rnum, filtered,
                     bc ? (char *)bc+1 : "0") < 0)
            return -1;

        if (bc && (*bc != 'Z' || (!isupper_c(bc[1]) && !islower_c(bc[1])))) {
            hts_log_warning("BC tag starts with non-sequence base; using '0'");
            str->l -= strlen((char *)bc)-2; // limit to 1 char
            str->s[str->l-1] = '0';
            str->s[str->l] = 0;
            bc = NULL;
        }

        // Replace any non-alpha with '+'.  Ie seq-seq to seq+seq
        if (bc) {
            int l = strlen((char *)bc+1);
            char *c = (char *)str->s + str->l - l;
            for (i = 0; i < l; i++) {
                if (!isalpha_c(c[i]))
                    c[i] = '+';
                else if (islower_c(c[i]))
                    c[i] = toupper_c(c[i]);
            }
        }
    }

    // Aux tags
    if (x && x->aux) {
        uint8_t *s = bam_get_aux(b), *end = b->data + b->l_data;
        while (s && end - s >= 4) {
            int tt = s[0]*256 + s[1];
            if (x->tags == NULL ||
                kh_get(tag, x->tags, tt) != kh_end(x->tags)) {
                e |= kputc_('\t', str) < 0;
                if (!(s = (uint8_t *)sam_format_aux1(s, s[2], s+3, end, str)))
                    return -1;
            } else {
                s = skip_aux(s+2, end);
            }
        }
        e |= kputsn("", 0, str) < 0; // nul terminate
    }

    if (ks_resize(str, str->l + 1 + len+1 + 2 + len+1 + 1) < 0) return -1;
    e |= kputc_('\n', str) < 0;

    // Seq line
    seq = bam_get_seq(b);
    if (flag & BAM_FREVERSE)
        for (i = len-1; i >= 0; i--)
            e |= kputc_("!TGKCYSBAWRDMHVN"[bam_seqi(seq, i)], str) < 0;
    else
        for (i = 0; i < len; i++)
            e |= kputc_(seq_nt16_str[bam_seqi(seq, i)], str) < 0;


    // Qual line
    if (x->nprefix == '@') {
        kputsn("\n+\n", 3, str);
        qual = bam_get_qual(b);
        if (qual[0] == 0xff)
            for (i = 0; i < len; i++)
                e |= kputc_('B', str) < 0;
        else if (flag & BAM_FREVERSE)
            for (i = len-1; i >= 0; i--)
                e |= kputc_(33 + qual[i], str) < 0;
        else
            for (i = 0; i < len; i++)
                e |= kputc_(33 + qual[i], str) < 0;

    }
    e |= kputc('\n', str) < 0;

    return e ? -1 : str->l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rsi, %r12
movzwl 0x10(%rsi), %ebp
movl 0x18(%rsi), %r15d
andq $0x0, (%rdx)
movq %rdi, 0x18(%rsp)
movsbl 0x78(%rdi), %edi
movq %rdx, %rsi
callq 0x21551
pushq $-0x1
popq %rbx
cmpl $-0x1, %eax
je 0x24517
movq 0x38(%r12), %rdi
movq %r14, %rsi
callq 0x214c5
cmpl $-0x1, %eax
je 0x24517
movq 0x18(%rsp), %rax
cmpl $0x0, 0x68(%rax)
sete %al
testb $0x1, %bpl
sete %cl
orb %al, %cl
jne 0x24103
movl %ebp, %eax
andb $-0x40, %al
negb %al
jo 0x240eb
movl %ebp, %eax
andl $0xc0, %eax
cmpl $0x40, %eax
jne 0x24103
leaq 0x55a8a(%rip), %rdi     # 0x79b73
jmp 0x240f2
leaq 0x55a84(%rip), %rdi     # 0x79b76
movq %r14, %rsi
callq 0x214c5
cmpl $-0x1, %eax
je 0x24517
movq %r12, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movq %r15, 0x20(%rsp)
movq 0x18(%rsp), %r12
cmpl $0x0, 0x60(%r12)
je 0x2425a
movl 0xc(%rsp), %ebx
movl %ebx, %eax
shrl $0x6, %eax
andl $0x2, %eax
testb $0x40, %bl
pushq $0x1
popq %r13
cmovel %eax, %r13d
leaq 0x6c(%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x24528
movq %rax, %rbp
btl $0x9, %ebx
pushq $0x4e
popq %rax
pushq $0x59
popq %rcx
cmovael %eax, %ecx
leaq 0x1(%rbp), %rbx
testq %rbp, %rbp
leaq 0x5479f(%rip), %r8      # 0x78905
cmovneq %rbx, %r8
leaq 0x55a08(%rip), %rsi     # 0x79b79
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x8c78
testl %eax, %eax
js 0x243dd
testq %rbp, %rbp
je 0x2425a
cmpb $0x5a, (%rbp)
jne 0x24219
movzbl (%rbx), %r15d
callq 0x4510
movq %rax, %r13
movq (%rax), %rax
testb $0x1, 0x1(%rax,%r15,2)
jne 0x241bd
movsbl %r15b, %edi
callq 0x245cb
testl %eax, %eax
je 0x24219
movq %rbx, %rdi
callq 0x41d0
movq 0x10(%r14), %rbx
addq (%r14), %rbx
movslq %eax, %r15
subq %r15, %rbx
xorl %ebp, %ebp
testl %r15d, %r15d
cmovlel %ebp, %r15d
cmpq %rbp, %r15
je 0x2425a
movzbl (%rbx,%rbp), %r12d
movq (%r13), %rcx
movb $0x2b, %al
testb $0x4, 0x1(%rcx,%r12,2)
je 0x2420c
movsbl %r12b, %edi
callq 0x245cb
testl %eax, %eax
je 0x2420f
callq 0x40a0
movq (%rax), %rax
movb (%rax,%r12,4), %al
movb %al, (%rbx,%rbp)
incq %rbp
movq 0x18(%rsp), %r12
jmp 0x241db
leaq 0x55965(%rip), %rsi     # 0x79b85
leaq 0x5596c(%rip), %rdx     # 0x79b93
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x110c6
movq %rbp, %rdi
callq 0x41d0
movq (%r14), %rcx
movq 0x10(%r14), %rdx
subq %rax, %rcx
leaq 0x2(%rcx), %rax
movq %rax, (%r14)
movb $0x30, 0x1(%rdx,%rcx)
movq (%r14), %rax
movq 0x10(%r14), %rcx
movb $0x0, (%rcx,%rax)
cmpl $0x0, 0x64(%r12)
je 0x24333
movq 0x10(%rsp), %rsi
movq 0x38(%rsi), %rax
movl 0x14(%rsi), %ecx
shll $0x2, %ecx
movzwl 0x12(%rsi), %r13d
addq %rax, %r13
addq %rcx, %r13
movslq 0x18(%rsi), %rcx
leal 0x1(%rcx), %edx
sarl %edx
movslq %edx, %rdx
addq %rcx, %r13
addq %rdx, %r13
movslq 0x40(%rsi), %rbp
addq %rax, %rbp
xorl %r15d, %r15d
testq %r13, %r13
je 0x24318
movq %rbp, %rax
subq %r13, %rax
cmpq $0x4, %rax
jl 0x24318
movq 0x70(%r12), %rbx
testq %rbx, %rbx
je 0x242e3
movzwl (%r13), %eax
rolw $0x8, %ax
movzwl %ax, %esi
movq %rbx, %rdi
callq 0x245e4
cmpl (%rbx), %eax
jne 0x242e3
addq $0x2, %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x24c6e
movq %rax, %r13
jmp 0x2429c
pushq $0x9
popq %rdi
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %r15d
movzbl 0x2(%r13), %esi
leaq 0x3(%r13), %rdx
movq %r13, %rdi
movq %rbp, %rcx
movq %r14, %r8
callq 0x24690
movq %rax, %r13
testq %rax, %rax
jne 0x2429c
jmp 0x243dd
leaq 0x53a37(%rip), %rdi     # 0x77d56
xorl %esi, %esi
movq %r14, %rdx
callq 0x21461
movl %eax, %ebx
shrl $0x1f, %ebx
orl %r15d, %ebx
jmp 0x24335
xorl %ebx, %ebx
movq 0x20(%rsp), %r13
movslq %r13d, %rax
movq (%r14), %rcx
leaq (%rcx,%rax,2), %rsi
addq $0x6, %rsi
movq %r14, %rdi
callq 0x24d14
testl %eax, %eax
js 0x243dd
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x24655
movl %eax, %ebp
shrl $0x1f, %ebp
movq 0x10(%rsp), %rcx
movl 0x14(%rcx), %eax
shll $0x2, %eax
addq 0x38(%rcx), %rax
orl %ebx, %ebp
movzwl 0x12(%rcx), %ebx
addq %rax, %rbx
testb $0x10, 0xc(%rsp)
jne 0x243e5
xorl %r15d, %r15d
testl %r13d, %r13d
movq %r13, %rax
movl $0x0, %r13d
cmovgl %eax, %r13d
xorl %r12d, %r12d
cmpl %r12d, %r13d
je 0x24428
movl %r12d, %eax
shrl %eax
movzbl (%rbx,%rax), %eax
movl %r15d, %ecx
notb %cl
andb $0x4, %cl
shrl %cl, %eax
andl $0xf, %eax
leaq 0x5364d(%rip), %rcx     # 0x77a10
movsbl (%rcx,%rax), %edi
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %ebp
incl %r12d
addl $0x4, %r15d
jmp 0x2439d
pushq $-0x1
popq %rbx
jmp 0x24517
leal (,%r13,4), %r15d
leaq 0x557cf(%rip), %r12     # 0x79bc3
testl %r13d, %r13d
jle 0x24428
decl %r13d
movl %r13d, %eax
shrl %eax
movzbl (%rbx,%rax), %eax
movl %r15d, %ecx
andb $0x4, %cl
shrl %cl, %eax
andl $0xf, %eax
movsbl (%rax,%r12), %edi
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %ebp
addl $-0x4, %r15d
jmp 0x243f4
movq 0x18(%rsp), %rax
cmpb $0x40, 0x78(%rax)
movq 0x20(%rsp), %r12
movq 0x10(%rsp), %rbx
jne 0x244ff
leaq 0x5578c(%rip), %rdi     # 0x79bd4
pushq $0x3
popq %rsi
movq %r14, %rdx
callq 0x21461
movq 0x38(%rbx), %rax
movl 0x14(%rbx), %ecx
movl 0x18(%rbx), %esi
shll $0x2, %ecx
movzwl 0x12(%rbx), %edx
leaq (%rax,%rdx), %rbx
addq %rcx, %rbx
incl %esi
sarl %esi
movslq %esi, %rsi
cmpb $-0x1, (%rsi,%rbx)
je 0x244ab
testb $0x10, 0xc(%rsp)
jne 0x244cf
addq %rsi, %rbx
xorl %r15d, %r15d
testl %r12d, %r12d
cmovlel %r15d, %r12d
cmpq %r15, %r12
je 0x244ff
movzbl (%rbx,%r15), %edi
addl $0x21, %edi
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %ebp
incq %r15
jmp 0x2448c
xorl %r15d, %r15d
testl %r12d, %r12d
cmovgl %r12d, %r15d
pushq $0x42
popq %rbx
subl $0x1, %r15d
jb 0x244ff
movl %ebx, %edi
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %ebp
jmp 0x244b8
addq %rdx, %rsi
addq %r12, %rcx
addq %rsi, %rcx
leaq (%rax,%rcx), %rbx
decq %rbx
testl %r12d, %r12d
jle 0x244ff
movzbl (%rbx), %edi
addl $0x21, %edi
movq %r14, %rsi
callq 0x24655
shrl $0x1f, %eax
orl %eax, %ebp
decl %r12d
decq %rbx
jmp 0x244df
pushq $-0x1
popq %rbx
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x21551
shrl $0x1f, %eax
orl %ebp, %eax
jne 0x24517
movl (%r14), %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq