// File: /workspace/github_cpp_makefile_star2_O2/brc7[P]DiversitySampling/src/io.cpp
// Function: SequenceFeatures(std::istream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool SequenceFeatures(std::istream& in, std::string& sequence, std::string& chunk, std::string fastWhat){

    int chunksize = 0; 
    char begin;
    int linesread = 0; 
    if (fastWhat == "fasta") {
        chunksize = 2;
        begin = '>';
    } else if (fastWhat == "fastq") {
        chunksize = 4;
        begin = '@';
    } else {
        std::cerr<<"Unsupported file type: "<<fastWhat<<std::endl; 
        return false; // unsupported file type
    }

    sequence = "";
    chunk = ""; 

    // read meta data
    std::string buffer;
    std::getline(in, buffer);
    linesread++;
    if (buffer.length() == 0) {
        std::cerr<<"Found empty line - probably reached the end of the input "<<fastWhat<<" file."<<std::endl; 
        std::cerr<<buffer<<std::endl; 
        return false; 
    }
    if (buffer.at(0) != begin){
        std::cerr<<"Error reading line of "<<fastWhat<<" file: Expected a line beginning with "<<begin<<" but instead found: "<<std::endl; 
        std::cerr<<buffer<<std::endl; 
        return false; 
    }

    chunk += buffer; 
    chunk += "\n"; 

    std::getline(in, sequence); 
    linesread++; 
    if (sequence.length() == 0){
        std::cerr<<"Error reading "<<fastWhat<<" file: Expected a sequence, but found empty line for read ID: "<<std::endl; 
        std::cerr<<chunk<<std::endl; 
        return false; 
    }
    chunk += sequence; 
    chunk += "\n"; 

    while((linesread < chunksize) && (in)){
        std::getline(in, buffer); 
        linesread++; 
        chunk += buffer; 
        chunk += "\n"; 
    }

    if (linesread != chunksize){
        std::cerr<<"Error reading "<<fastWhat<<" file: Expected "<<chunksize<<" lines of input, got "<<linesread<<" instead. The sequence data should still be valid. "<<std::endl; 
        return false; 
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r13
movq %rdi, %r15
leaq 0x1a9b(%rip), %rsi      # 0x4004
movq %rcx, %rdi
callq 0x2aa1
testb %al, %al
je 0x2586
movq %rbx, 0x10(%rsp)
pushq $0x2
popq %rax
movl %eax, 0xc(%rsp)
movb $0x3e, %bpl
jmp 0x25ac
leaq 0x2172(%rip), %rsi      # 0x46ff
movq %rbx, %rdi
callq 0x2aa1
testb %al, %al
je 0x26d7
movq %rbx, 0x10(%rsp)
pushq $0x4
popq %rax
movl %eax, 0xc(%rsp)
movb $0x40, %bpl
leaq 0x1b04(%rip), %rbx      # 0x40b7
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2280
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2280
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x18(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x2060
cmpq $0x0, 0x20(%rsp)
je 0x26ae
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x2290
cmpb %bpl, (%rax)
jne 0x2701
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x22a0
leaq 0x1a97(%rip), %rsi      # 0x40b6
movq %r14, %rdi
callq 0x2270
movq %r15, %rdi
movq %r13, %rsi
callq 0x2060
cmpq $0x0, 0x8(%r13)
je 0x2787
movq %r14, %rdi
movq %r13, %rsi
callq 0x22a0
leaq 0x1a67(%rip), %rsi      # 0x40b6
movq %r14, %rdi
callq 0x2270
pushq $0x2
popq %r12
leaq 0x18(%rsp), %r13
leaq 0x1a4f(%rip), %rbx      # 0x40b6
movb $0x1, %bpl
cmpl %r12d, 0xc(%rsp)
je 0x276c
movq (%r15), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x20(%r15,%rax)
jne 0x27c3
movq %r15, %rdi
movq %r13, %rsi
callq 0x2060
movq %r14, %rdi
movq %r13, %rsi
callq 0x22a0
incl %r12d
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2270
jmp 0x2667
movq 0x493b(%rip), %rdi      # 0x6ff0
leaq 0x1966(%rip), %rsi      # 0x4022
callq 0x2150
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x2140
leaq 0x1987(%rip), %rsi      # 0x405c
jmp 0x2743
movq 0x4912(%rip), %rdi      # 0x6ff0
leaq 0x1925(%rip), %rsi      # 0x400a
callq 0x2150
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2140
movq %rax, %rdi
callq 0x20c0
xorl %ebp, %ebp
jmp 0x2776
movq 0x48e8(%rip), %rdi      # 0x6ff0
leaq 0x1954(%rip), %rsi      # 0x4063
callq 0x2150
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x2140
leaq 0x1952(%rip), %rsi      # 0x407a
movq %rax, %rdi
callq 0x2150
movzbl %bpl, %esi
movq %rax, %rdi
callq 0x2190
leaq 0x195e(%rip), %rsi      # 0x40a1
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
movq 0x4896(%rip), %rdi      # 0x6ff0
movq %r12, %rsi
callq 0x2140
movq %rax, %rdi
callq 0x20c0
xorl %ebp, %ebp
leaq 0x18(%rsp), %rdi
callq 0x20b0
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4862(%rip), %rdi      # 0x6ff0
leaq 0x1923(%rip), %rsi      # 0x40b8
callq 0x2150
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x2140
leaq 0x1919(%rip), %rsi      # 0x40c7
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
movq %r14, %r12
jmp 0x2753
cmpl %r12d, 0xc(%rsp)
je 0x276c
movq 0x481f(%rip), %rdi      # 0x6ff0
leaq 0x18e0(%rip), %rsi      # 0x40b8
callq 0x2150
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x2140
leaq 0x1915(%rip), %rsi      # 0x4106
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x2240
leaq 0x190b(%rip), %rsi      # 0x4117
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
movl %r12d, %esi
callq 0x2240
leaq 0x1907(%rip), %rsi      # 0x412d
movq %rax, %rdi
callq 0x2150
jmp 0x2762
jmp 0x2835
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2250