// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movsbl 0x78(%rax), %edi
movq -0x20(%rbp), %rsi
callq 0x39080
cmpl $-0x1, %eax
je 0x3dffa
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x38fa0
cmpl $-0x1, %eax
jne 0x3e006
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e751
cmpq $0x0, -0x10(%rbp)
je 0x3e086
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
je 0x3e086
movl -0x24(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3e086
movl -0x24(%rbp), %eax
andl $0xc0, %eax
movl %eax, -0x44(%rbp)
cmpl $0x40, -0x44(%rbp)
jne 0x3e056
movq -0x20(%rbp), %rsi
leaq 0xb40f8(%rip), %rdi     # 0xf2136
callq 0x38fa0
cmpl $-0x1, %eax
jne 0x3e054
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e751
jmp 0x3e084
cmpl $0x80, -0x44(%rbp)
jne 0x3e082
movq -0x20(%rbp), %rsi
leaq 0xb40cf(%rip), %rdi     # 0xf2139
callq 0x38fa0
cmpl $-0x1, %eax
jne 0x3e080
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e751
jmp 0x3e082
jmp 0x3e084
jmp 0x3e086
cmpq $0x0, -0x10(%rbp)
je 0x3e2db
movq -0x10(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x3e2db
movl -0x24(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x3e0b4
movl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x3e0cd
movl -0x24(%rbp), %edx
andl $0x80, %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x24(%rbp), %edx
andl $0x200, %edx            # imm = 0x200
movl $0x4e, %eax
movl $0x59, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, -0x49(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x6c, %rsi
callq 0x3e760
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x88(%rbp)
movsbl -0x49(%rbp), %eax
movl %eax, -0x84(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x3e13a
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x3e14a
leaq 0xb2a0b(%rip), %rax     # 0xf0b4c
movq %rax, -0x98(%rbp)
jmp 0x3e14a
movl -0x84(%rbp), %ecx
movl -0x88(%rbp), %edx
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %r8
leaq 0xb3fd1(%rip), %rsi     # 0xf213c
movb $0x0, %al
callq 0xb040
cmpl $0x0, %eax
jge 0x3e183
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e751
cmpq $0x0, -0x58(%rbp)
je 0x3e227
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x5a, %eax
jne 0x3e1be
movq -0x58(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x3e880
cmpl $0x0, %eax
jne 0x3e227
movq -0x58(%rbp), %rax
movsbl 0x1(%rax), %edi
callq 0x3e8b0
cmpl $0x0, %eax
jne 0x3e227
movl $0x3, %edi
leaq 0xb3f7e(%rip), %rsi     # 0xf2148
leaq 0xb3f85(%rip), %rdx     # 0xf2156
movb $0x0, %al
callq 0x1b030
movq -0x58(%rbp), %rdi
callq 0x41b0
movq %rax, %rdx
subq $0x2, %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
subq %rdx, %rcx
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
movb $0x30, (%rax,%rcx)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rcx
movb $0x0, (%rax,%rcx)
movq $0x0, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x3e2d9
movq -0x58(%rbp), %rdi
addq $0x1, %rdi
callq 0x41b0
movl %eax, -0x5c(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
addq (%rcx), %rax
movslq -0x5c(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x3e2d7
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x3e8e0
cmpl $0x0, %eax
jne 0x3e294
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb $0x2b, (%rax,%rcx)
jmp 0x3e2ca
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x3e8b0
cmpl $0x0, %eax
je 0x3e2c8
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %edi
callq 0x3e910
movb %al, %dl
movq -0x68(%rbp), %rax
movslq -0x28(%rbp), %rcx
movb %dl, (%rax,%rcx)
jmp 0x3e2ca
jmp 0x3e2cc
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3e268
jmp 0x3e2d9
jmp 0x3e2db
cmpq $0x0, -0x10(%rbp)
je 0x3e45e
movq -0x10(%rbp), %rax
cmpl $0x0, 0x64(%rax)
je 0x3e45e
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movslq 0x18(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x40(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x70(%rbp)
movb %al, -0x99(%rbp)
je 0x3e378
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
subq %rcx, %rax
cmpq $0x4, %rax
setge %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x3e387
jmp 0x3e439
movq -0x70(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movq -0x70(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x7c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x70(%rax)
je 0x3e3c5
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rdi
movl -0x7c(%rbp), %esi
callq 0x3e930
movq -0x10(%rbp), %rcx
movq 0x70(%rcx), %rcx
cmpl (%rcx), %eax
je 0x3e41f
movq -0x20(%rbp), %rsi
movl $0x9, %edi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x70(%rbp), %rdi
movq -0x70(%rbp), %rax
movb 0x2(%rax), %al
movq -0x70(%rbp), %rdx
addq $0x3, %rdx
movq -0x78(%rbp), %rcx
movq -0x20(%rbp), %r8
movzbl %al, %esi
callq 0x3eae0
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
jne 0x3e41d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e751
jmp 0x3e434
movq -0x70(%rbp), %rdi
addq $0x2, %rdi
movq -0x78(%rbp), %rsi
callq 0x3f5a0
movq %rax, -0x70(%rbp)
jmp 0x3e351
movq -0x20(%rbp), %rdx
leaq 0xb1b31(%rip), %rdi     # 0xeff75
xorl %eax, %eax
movl %eax, %esi
callq 0x38ef0
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
addq $0x1, %rsi
movslq -0x30(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
addq $0x2, %rsi
movslq -0x30(%rbp), %rax
addq %rax, %rsi
addq $0x1, %rsi
addq $0x1, %rsi
callq 0x3f730
cmpl $0x0, %eax
jge 0x3e4a1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e751
movq -0x20(%rbp), %rsi
movl $0xa, %edi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x3e559
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x3e557
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x28(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0xb3c58(%rip), %rax     # 0xf2186
movsbl (%rax,%rcx), %edi
movq -0x20(%rbp), %rsi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3e4fd
jmp 0x3e5be
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x3e5bc
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x28(%rbp), %ecx
xorl $-0x1, %ecx
andl $0x1, %ecx
shll $0x2, %ecx
sarl %cl, %eax
andl $0xf, %eax
movslq %eax, %rcx
leaq 0xb169d(%rip), %rax     # 0xefc30
movsbl (%rax,%rcx), %edi
movq -0x20(%rbp), %rsi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3e560
jmp 0x3e5be
movq -0x10(%rbp), %rax
movsbl 0x78(%rax), %eax
cmpl $0x40, %eax
jne 0x3e704
movq -0x20(%rbp), %rdx
leaq 0xb3bbd(%rip), %rdi     # 0xf2197
movl $0x3, %esi
callq 0x38ef0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movzwl 0x12(%rcx), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
sarl %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
jne 0x3e66b
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x3e666
movq -0x20(%rbp), %rsi
movl $0x42, %edi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3e634
jmp 0x3e702
movl -0x24(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x3e6bb
movl -0x30(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jl 0x3e6b9
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
addl $0x21, %edi
movq -0x20(%rbp), %rsi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3e67f
jmp 0x3e700
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x3e6fe
movq -0x40(%rbp), %rax
movslq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %edi
addl $0x21, %edi
movq -0x20(%rbp), %rsi
callq 0x3ea70
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3e6c2
jmp 0x3e700
jmp 0x3e702
jmp 0x3e704
movq -0x20(%rbp), %rsi
movl $0xa, %edi
callq 0x39080
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x3e739
movq $-0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x3e747
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)