// File: /workspace/github_cpp_makefile_star2_O1/ParkerLab[P]cta/src/cta.cpp
// Function: trim_pair(FASTQRecord&, FASTQRecord&, long long, long long, long long, long long, bool)
void trim_pair(FASTQRecord& rec1, FASTQRecord& rec2, long long int rc_length, long long int max_edit_distance, long long int fudge = 0, long long int trim_start = 0, bool verbose = false) {
    long long int alignment_start = -1;
    std::string rec2_rc = reverse_complement(rec2.sequence.substr(0, rc_length));
    if (verbose) {
        std::cout << rec1.sequence << '\n' << rec2.sequence << '\n' << rec2_rc << '\n';
    }

    size_t position_of_rec2_rc_in_rec1 = rec1.sequence.rfind(rec2_rc);
    long long int trim_end = rc_length - fudge;

    if (position_of_rec2_rc_in_rec1 != std::string::npos) {
        alignment_start = position_of_rec2_rc_in_rec1;

        if (verbose) {
            std::cout << "trim_pair: rec2 rc " << rec2_rc << " found at " << position_of_rec2_rc_in_rec1 << " in rec1 " << rec1.sequence  << '\n';
        }
    } else if (max_edit_distance > 0) {
        alignment_start = align(rec2_rc, rec1.sequence, max_edit_distance, verbose);

        if (verbose) {
            std::cout << "trim_pair: rec2 rc " << rec2_rc << " not found in " << rec1.sequence << "; alignment result: " << alignment_start << '\n';
        }
    }

    if (alignment_start > 0) {
        if (verbose) {
            std::cout << "trim_pair: best alignment at " << alignment_start << '\n';
        }
        if (alignment_start > 0) {
            if (verbose) {
                std::cout << "trim_pair: trimming pair " << rec1.name << '\n';
            }
            trim_fastq_record(rec1, trim_start, alignment_start + trim_end);
            trim_fastq_record(rec2, trim_start, alignment_start + trim_end);
        }
    } else if (verbose) {
        std::cout << "not touching pair " << rec1.name << '\n';
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x48(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rdi, %rbx
movq %rsi, 0x40(%rsp)
addq $0x40, %rsi
leaq 0x20(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
movq %r12, %rcx
callq 0xb4c0
movq %rsp, %rdi
movq %r14, %rsi
callq 0xc0ea
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xc9b2
movq 0x30(%rsp), %rsi
incq %rsi
callq 0xb480
cmpb $0x0, 0x90(%rsp)
je 0xca35
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
movq 0x305b5(%rip), %rdi     # 0x3cf80
callq 0xb540
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
movq 0x40(%rsp), %rcx
movq 0x40(%rcx), %rsi
movq 0x48(%rcx), %rdx
movq %rax, %rdi
callq 0xb540
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rax, %rdi
callq 0xb540
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
leaq 0x40(%rbx), %r15
movq (%rsp), %rsi
movq 0x8(%rsp), %rcx
movq $-0x1, %r14
movq %r15, %rdi
movq $-0x1, %rdx
callq 0xb630
cmpq $-0x1, %rax
je 0xcbcd
movq %rax, %rbp
cmpb $0x0, 0x90(%rsp)
je 0xcafe
movq 0x30506(%rip), %rdi     # 0x3cf80
leaq 0x1c793(%rip), %rsi     # 0x29214
movl $0x13, %edx
callq 0xb540
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x304e5(%rip), %rdi     # 0x3cf80
callq 0xb540
movq %rax, %r14
leaq 0x1c77e(%rip), %rsi     # 0x29228
movl $0xa, %edx
movq %rax, %rdi
callq 0xb540
movq %r14, %rdi
movq %rbp, %rsi
callq 0xb320
movq %rax, %r14
leaq 0x1c767(%rip), %rsi     # 0x29233
movl $0x9, %edx
movq %rax, %rdi
callq 0xb540
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
movq %r14, %rdi
callq 0xb540
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
movq %rbp, %r14
testq %r14, %r14
jle 0xcc8d
cmpb $0x0, 0x90(%rsp)
je 0xcb9e
movq 0x30461(%rip), %rdi     # 0x3cf80
leaq 0x1c73b(%rip), %rsi     # 0x29261
movl $0x1d, %edx
callq 0xb540
movq 0x30449(%rip), %rdi     # 0x3cf80
movq %r14, %rsi
callq 0xb1d0
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
cmpb $0x0, 0x90(%rsp)
je 0xcb9e
movq 0x3041b(%rip), %rdi     # 0x3cf80
leaq 0x1c713(%rip), %rsi     # 0x2927f
movl $0x19, %edx
callq 0xb540
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x303fc(%rip), %rdi     # 0x3cf80
callq 0xb540
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
subq 0x50(%rsp), %r12
addq %r12, %r14
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
callq 0xc8b5
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %r14, %rdx
callq 0xc8b5
jmp 0xccd7
testq %r13, %r13
jle 0xcb01
movzbl 0x90(%rsp), %ecx
movq %rsp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xc499
movq %rax, %r14
cmpb $0x0, 0x90(%rsp)
je 0xcb01
movq 0x3037c(%rip), %rdi     # 0x3cf80
leaq 0x1c609(%rip), %rsi     # 0x29214
movl $0x13, %edx
callq 0xb540
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x3035b(%rip), %rdi     # 0x3cf80
callq 0xb540
movq %rax, %r15
leaq 0x1c609(%rip), %rsi     # 0x2923d
movl $0xe, %edx
movq %rax, %rdi
callq 0xb540
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
movq %r15, %rdi
callq 0xb540
movq %rax, %r15
leaq 0x1c5f1(%rip), %rsi     # 0x2924c
movl $0x14, %edx
movq %rax, %rdi
callq 0xb540
movq %r15, %rdi
movq %r14, %rsi
callq 0xb1d0
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
jmp 0xcb01
cmpb $0x0, 0x90(%rsp)
je 0xccd7
movq 0x302e2(%rip), %rdi     # 0x3cf80
leaq 0x1c5f4(%rip), %rsi     # 0x29299
movl $0x12, %edx
callq 0xb540
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x302c3(%rip), %rdi     # 0x3cf80
callq 0xb540
leaq 0x20(%rsp), %rsi
movb $0xa, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0xb540
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xccf2
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xb480
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xcd39
movq 0x30(%rsp), %rsi
jmp 0xcd31
jmp 0xcd1b
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xcd39
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xb480
movq %rbx, %rdi
callq 0xb7d0