// File: 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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rcx, -0x78(%rbp)
movq %rdi, %rax
movq -0x78(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movq %rax, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rdi, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
leaq 0x3855(%rip), %rsi      # 0x6004
callq 0x31a0
testb $0x1, %al
jne 0x27ba
jmp 0x27c7
movl $0x2, -0x2c(%rbp)
movb $0x3e, -0x2d(%rbp)
jmp 0x2823
movq -0x70(%rbp), %rdi
leaq 0x3f33(%rip), %rsi      # 0x6705
callq 0x31a0
testb $0x1, %al
jne 0x27dd
jmp 0x27ea
movl $0x4, -0x2c(%rbp)
movb $0x40, -0x2d(%rbp)
jmp 0x2821
movq 0x67ff(%rip), %rdi      # 0x8ff0
leaq 0x3812(%rip), %rsi      # 0x600a
callq 0x21b0
movq -0x70(%rbp), %rsi
movq %rax, %rdi
callq 0x2190
movq %rax, %rdi
movq 0x67a5(%rip), %rsi      # 0x8fb8
callq 0x21d0
movb $0x0, -0x1(%rbp)
jmp 0x2cd2
jmp 0x2823
movq -0x18(%rbp), %rdi
leaq 0x3889(%rip), %rsi      # 0x60b7
movq %rsi, -0x88(%rbp)
callq 0x22e0
movq -0x88(%rbp), %rsi
movq -0x20(%rbp), %rdi
callq 0x22e0
leaq -0x58(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x22f0
movq -0x80(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x2070
jmp 0x2866
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2340
cmpq $0x0, %rax
jne 0x2940
movq 0x6767(%rip), %rdi      # 0x8ff0
leaq 0x3792(%rip), %rsi      # 0x6022
callq 0x21b0
movq %rax, -0x90(%rbp)
jmp 0x289e
movq -0x70(%rbp), %rsi
movq -0x90(%rbp), %rdi
callq 0x2190
movq %rax, -0x98(%rbp)
jmp 0x28b7
movq -0x98(%rbp), %rdi
leaq 0x3797(%rip), %rsi      # 0x605c
callq 0x21b0
movq %rax, -0xa0(%rbp)
jmp 0x28d3
movq -0xa0(%rbp), %rdi
movq 0x66d7(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x28e8
movq 0x6701(%rip), %rdi      # 0x8ff0
leaq -0x58(%rbp), %rsi
callq 0x2190
movq %rax, -0xa8(%rbp)
jmp 0x2901
movq -0xa8(%rbp), %rdi
movq 0x66a9(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x2916
movb $0x0, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x2cc9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2120
jmp 0x2ce0
xorl %eax, %eax
movl %eax, %esi
leaq -0x58(%rbp), %rdi
callq 0x23d0
movq %rax, -0xb0(%rbp)
jmp 0x2956
movq -0xb0(%rbp), %rax
movsbl (%rax), %eax
movsbl -0x2d(%rbp), %ecx
cmpl %ecx, %eax
je 0x2a45
movq 0x667d(%rip), %rdi      # 0x8ff0
leaq 0x36e9(%rip), %rsi      # 0x6063
callq 0x21b0
movq %rax, -0xb8(%rbp)
jmp 0x2988
movq -0x70(%rbp), %rsi
movq -0xb8(%rbp), %rdi
callq 0x2190
movq %rax, -0xc0(%rbp)
jmp 0x29a1
movq -0xc0(%rbp), %rdi
leaq 0x36cb(%rip), %rsi      # 0x607a
callq 0x21b0
movq %rax, -0xc8(%rbp)
jmp 0x29bd
movq -0xc8(%rbp), %rdi
movsbl -0x2d(%rbp), %esi
callq 0x2250
movq %rax, -0xd0(%rbp)
jmp 0x29d6
movq -0xd0(%rbp), %rdi
leaq 0x36bd(%rip), %rsi      # 0x60a1
callq 0x21b0
movq %rax, -0xd8(%rbp)
jmp 0x29f2
movq -0xd8(%rbp), %rdi
movq 0x65b8(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x2a07
movq 0x65e2(%rip), %rdi      # 0x8ff0
leaq -0x58(%rbp), %rsi
callq 0x2190
movq %rax, -0xe0(%rbp)
jmp 0x2a20
movq -0xe0(%rbp), %rdi
movq 0x658a(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x2a35
movb $0x0, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x2cc9
movq -0x20(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x22a0
jmp 0x2a54
movq -0x20(%rbp), %rdi
leaq 0x3657(%rip), %rsi      # 0x60b6
callq 0x21a0
jmp 0x2a66
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2070
jmp 0x2a75
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2340
cmpq $0x0, %rax
jne 0x2b35
movq 0x6558(%rip), %rdi      # 0x8ff0
leaq 0x3619(%rip), %rsi      # 0x60b8
callq 0x21b0
movq %rax, -0xe8(%rbp)
jmp 0x2aad
movq -0x70(%rbp), %rsi
movq -0xe8(%rbp), %rdi
callq 0x2190
movq %rax, -0xf0(%rbp)
jmp 0x2ac6
movq -0xf0(%rbp), %rdi
leaq 0x35f3(%rip), %rsi      # 0x60c7
callq 0x21b0
movq %rax, -0xf8(%rbp)
jmp 0x2ae2
movq -0xf8(%rbp), %rdi
movq 0x64c8(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x2af7
movq -0x20(%rbp), %rsi
movq 0x64ee(%rip), %rdi      # 0x8ff0
callq 0x2190
movq %rax, -0x100(%rbp)
jmp 0x2b10
movq -0x100(%rbp), %rdi
movq 0x649a(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x2b25
movb $0x0, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x2cc9
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdi
callq 0x22a0
jmp 0x2b44
movq -0x20(%rbp), %rdi
leaq 0x3567(%rip), %rsi      # 0x60b6
callq 0x21a0
jmp 0x2b56
jmp 0x2b58
movl -0x34(%rbp), %ecx
xorl %eax, %eax
cmpl -0x2c(%rbp), %ecx
movb %al, -0x101(%rbp)
jge 0x2b91
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2280
movb %al, -0x102(%rbp)
jmp 0x2b83
movb -0x102(%rbp), %al
movb %al, -0x101(%rbp)
jmp 0x2b91
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x2b9d
jmp 0x2bd7
movq -0x10(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2070
jmp 0x2bac
movl -0x34(%rbp), %eax
incl %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x22a0
jmp 0x2bc3
movq -0x20(%rbp), %rdi
leaq 0x34e8(%rip), %rsi      # 0x60b6
callq 0x21a0
jmp 0x2bd5
jmp 0x2b58
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
je 0x2cbe
movq 0x6406(%rip), %rdi      # 0x8ff0
leaq 0x34c7(%rip), %rsi      # 0x60b8
callq 0x21b0
movq %rax, -0x110(%rbp)
jmp 0x2bff
movq -0x70(%rbp), %rsi
movq -0x110(%rbp), %rdi
callq 0x2190
movq %rax, -0x118(%rbp)
jmp 0x2c18
movq -0x118(%rbp), %rdi
leaq 0x34e0(%rip), %rsi      # 0x6106
callq 0x21b0
movq %rax, -0x120(%rbp)
jmp 0x2c34
movq -0x120(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x2380
movq %rax, -0x128(%rbp)
jmp 0x2c4c
movq -0x128(%rbp), %rdi
leaq 0x34bd(%rip), %rsi      # 0x6117
callq 0x21b0
movq %rax, -0x130(%rbp)
jmp 0x2c68
movq -0x130(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x2380
movq %rax, -0x138(%rbp)
jmp 0x2c80
movq -0x138(%rbp), %rdi
leaq 0x349f(%rip), %rsi      # 0x612d
callq 0x21b0
movq %rax, -0x140(%rbp)
jmp 0x2c9c
movq -0x140(%rbp), %rdi
movq 0x630e(%rip), %rsi      # 0x8fb8
callq 0x21d0
jmp 0x2cb1
movb $0x0, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x2cc9
movb $0x1, -0x1(%rbp)
movl $0x1, -0x68(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2120
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x2390
nopl (%rax)