// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/io.c
// Function: parasail_pack_fastq_buffer
char * parasail_pack_fastq_buffer(const char *T, off_t size, long * packed_size)
{
    char *P = NULL;
    int first = 1;
    off_t i = 0;
    off_t w = 0;
    unsigned long line = 0;
    parasail_file_stat_t *pfs = NULL;

    if (NULL == T) {
        fprintf(stderr, "parasail_pack_fastq_buffer: NULL pointer\n");
        return NULL;
    }

    if (NULL == packed_size) {
        fprintf(stderr, "parasail_pack_fastq_buffer: NULL size pointer\n");
        return NULL;
    }

    pfs = parasail_stat_fastq_buffer(T, size);
    if (NULL == pfs) {
        fprintf(stderr, "parasail_stat_fastq_buffer: fastq stat failed\n");
        return NULL;
    }

    P = (char*)malloc(sizeof(char) * (pfs->characters+pfs->sequences+1));
    if (NULL == P) {
        perror("malloc");
        fprintf(stderr, "parasail_pack_fastq_buffer: malloc failed\n");
        free(pfs);
        return NULL;
    }
    free(pfs);

    /* read file */
    while (i<size) {
        if (T[i] != '@') {
            fprintf(stderr, "parasail_pack_fastq_buffer: "
                    "poorly formatted FASTQ file, line %lu\n", line);
            free(P);
            return NULL;
        }

        /* encountered a new sequence */
        if (first) {
            first = 0;
        }
        else {
            P[w++] = '$';
        }

        i = skip_line(T, i);

        /* go to next line */
        ++i;
        ++line;

        /* rest of next line is the sequence */
        while (T[i] != '\n' && T[i] != '\r') {
            P[w++] = T[i];
            ++i;
        }

        /* for the case of "\r\n" or "\n\r" */
        if (i+1<size && (T[i+1] == '\n' || T[i+1] == '\r')) {
            ++i;
        }

        /* go to next line */
        ++i;
        ++line;

        if (T[i] != '+') {
            fprintf(stderr, "parasail_pack_fastq_buffer: "
                    "poorly formatted FASTQ file, line %lu\n", line);
            free(P);
            return NULL;
        }

        i = skip_line(T, i);

        /* go to next line */
        ++i;
        ++line;

        /* rest of next line are the quality control values */
        i = skip_line(T, i);

        /* go to next line */
        ++i;
        ++line;
    }

    P[w++] = '$';
    P[w] = '\0';
    *packed_size = w;
    return P;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x1f3d3f
movq %rdx, %r14
testq %rdx, %rdx
je 0x1f3d54
movq %rsi, %r15
movq %rdi, %r12
callq 0x1f344f
testq %rax, %rax
je 0x1f3d67
movq %rax, %r13
movq (%rax), %rax
movq 0x8(%r13), %rcx
leaq (%rcx,%rax), %rdi
incq %rdi
callq 0x1f01f0
testq %rax, %rax
je 0x1f3d85
movq %rax, %rbx
movq %r13, %rdi
callq 0x1f01c0
xorl %eax, %eax
xorl %esi, %esi
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq %r15, %rsi
jge 0x1f3d2e
cmpb $0x40, (%r12,%rsi)
jne 0x1f3db6
testb $0x1, %al
je 0x1f3cb5
movb $0x24, (%rbx,%rbp)
incq %rbp
movq %r12, %rdi
callq 0x1f36c6
addq $0x2, %rax
movzbl -0x1(%r12,%rax), %ecx
cmpl $0xa, %ecx
je 0x1f3cdc
cmpl $0xd, %ecx
je 0x1f3cdc
movb %cl, (%rbx,%rbp)
incq %rbp
incq %rax
jmp 0x1f3cc1
leaq -0x1(%rax), %rcx
cmpq %r15, %rax
jge 0x1f3cf4
movzbl (%r12,%rax), %edx
cmpl $0xa, %edx
je 0x1f3cf7
cmpl $0xd, %edx
je 0x1f3cf7
movq %rcx, %rax
cmpb $0x2b, 0x1(%r12,%rax)
jne 0x1f3db2
incq %rax
movq %r12, %rdi
movq %rax, %rsi
callq 0x1f36c6
leaq 0x1(%rax), %rsi
movq %r12, %rdi
callq 0x1f36c6
movq %rax, %rsi
incq %rsi
addq $0x4, %r13
movb $0x1, %al
jmp 0x1f3c96
movw $0x24, (%rbx,%rbp)
incq %rbp
movq %rbp, (%r14)
jmp 0x1f3ddb
movq 0x550292(%rip), %rax    # 0x743fd8
movq (%rax), %rcx
leaq 0x3f757c(%rip), %rdi    # 0x5eb2cc
pushq $0x29
jmp 0x1f3d7a
movq 0x55027d(%rip), %rax    # 0x743fd8
movq (%rax), %rcx
leaq 0x3f7591(%rip), %rdi    # 0x5eb2f6
jmp 0x1f3d78
movq 0x55026a(%rip), %rax    # 0x743fd8
movq (%rax), %rcx
leaq 0x3f75ad(%rip), %rdi    # 0x5eb325
pushq $0x2e
popq %rsi
pushq $0x1
popq %rdx
callq 0x1f02b0
jmp 0x1f3dd9
leaq 0x3f6db3(%rip), %rdi    # 0x5eab3f
callq 0x1f0140
movq 0x550240(%rip), %rax    # 0x743fd8
movq (%rax), %rcx
leaq 0x3f75b2(%rip), %rdi    # 0x5eb354
pushq $0x2a
popq %rsi
pushq $0x1
popq %rdx
callq 0x1f02b0
movq %r13, %rdi
jmp 0x1f3dd4
orq $0x2, %r13
movq 0x55021b(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x3f75b8(%rip), %rsi    # 0x5eb37f
movq %r13, %rdx
xorl %eax, %eax
callq 0x1f0220
movq %rbx, %rdi
callq 0x1f01c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq