// File: /workspace/github_cpp_makefile_star2_O2/CK7[P]abawaca/src/abawaca-build.cpp
// Function: Scaf::Scaf(Bio::Sequence<Bio::DNAString> const&, unsigned long)
Scaf::Scaf(const Bio::DNASequence& s, size_t window_size) : Sequence(s.display_id(), s.seq())
{
	// Split the scaffold into segments
	const Bio::DNAString& seq = s.seq();
	size_t			nsegments = (seq.size() - Bio::Ns(seq)) / window_size;

	if(nsegments == 0)
		nsegments = 1;
	size_t	nbps = (seq.size() - Bio::Ns(seq)) / nsegments;

	size_t	nbps_segment = 0;
	for(auto it=seq.begin(), sit=seq.begin(); it!=seq.end(); it++) {
		if(*it != 'N')
			nbps_segment++;
		if(nbps_segment == nbps) {
			Bio::DNAString subs = seq.subseq(sit-seq.begin(), it-seq.begin());
			char display_id[1024], desc[1024];

			segment_coords.push_back(pair<size_t, size_t>(sit-seq.begin()+1, it-seq.begin()+1));
			sprintf(display_id, "%s_%lu", s.display_id().c_str(), segment_coords.size());
			// SCNpilot_BF_INOC_scaffold_3677:(1,2811), 0 segment(s), 2811/2811 non-N bps
			sprintf(desc, "%s:(%lu, %lu), %lu/%lu non-Ns bps", s.display_id().c_str(), (sit-seq.begin()+1), (it-seq.begin()+1), subs.size()-Bio::Ns(subs), subs.size());
			segments.push_back(new Scaf_segment(display_id, desc, (sit-seq.begin()+1), (it-seq.begin()+1), subs));
			sit = it;
			sit++;
			nbps_segment = 0;
		}
	}

	// Last few bps may be nglected 
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8f8, %rsp            # imm = 0x8F8
movq %rdx, -0x38(%rbp)
movq %rsi, %r12
movq %rdi, %r14
addq $0x8, %rsi
leaq -0xe8(%rbp), %r15
movq %r15, %rdi
movq %rsi, -0x80(%rbp)
callq 0x43a0
leaq 0x48(%r12), %rbx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x9562
leaq -0xe8(%rbp), %rdi
callq 0x4130
leaq 0xd5f7(%rip), %rax      # 0x14b20
movq %rax, (%r14)
leaq 0x48(%r14), %rax
movq %rax, -0x50(%rbp)
leaq 0x60(%r14), %rax
movq %rax, -0x40(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%r14)
movups %xmm0, 0x58(%r14)
movups %xmm0, 0x68(%r14)
andq $0x0, 0x78(%r14)
movq 0x50(%r12), %r15
movq %rbx, %rdi
movq %r14, -0x48(%rbp)
callq 0xd5ec
movq %rax, %r13
movq %r12, -0x58(%rbp)
movq 0x50(%r12), %r12
movq %rbx, %rdi
callq 0xd5ec
movq %rax, %rcx
subq %r13, %r15
movq %r15, %rax
xorl %edx, %edx
movq -0x38(%rbp), %rsi
divq %rsi
cmpq %rsi, %r15
pushq $0x1
popq %rsi
cmovaeq %rax, %rsi
subq %rcx, %r12
movq %r12, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %r15
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
leaq -0x108(%rbp), %r14
movq %rcx, %r13
movq %rcx, %rdi
xorl %eax, %eax
movq -0x58(%rbp), %rsi
movq %rbx, %r12
movq %rdx, %rbx
movq %r12, -0x60(%rbp)
movq %r15, -0x78(%rbp)
movq 0x50(%rsi), %rdx
addq %rcx, %rdx
cmpq %rdx, %rdi
je 0x7781
xorl %edx, %edx
cmpb $0x4e, (%rdi)
setne %dl
addq %rdx, %rax
cmpq %r15, %rax
jne 0x7776
movq %rdi, -0x88(%rbp)
movq %r13, %rdx
subq %rcx, %rdx
notq %rcx
addq %rbx, %rcx
leaq -0xa8(%rbp), %rdi
movq %r12, %rsi
callq 0x95ee
movq (%r12), %rax
incq %r13
movq %r13, %rcx
subq %rax, %rcx
movq %rbx, -0x38(%rbp)
movq %rbx, %rdx
subq %rax, %rdx
movq %rcx, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xb114
movq -0x80(%rbp), %rbx
movq (%rbx), %rdx
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rcx
subq 0x48(%rax), %rcx
sarq $0x4, %rcx
leaq -0x910(%rbp), %rdi
leaq 0x6f1d(%rip), %rsi      # 0xe57e
xorl %eax, %eax
callq 0x4060
movq (%rbx), %r15
movq (%r12), %rbx
movq -0xa0(%rbp), %r12
leaq -0xa8(%rbp), %rdi
callq 0xd5ec
movq -0x38(%rbp), %r8
subq %rbx, %r8
movq %r13, %rcx
subq %rbx, %rcx
subq %rax, %r12
movq -0xa0(%rbp), %rax
movq %rax, (%rsp)
leaq -0x510(%rbp), %rdi
leaq 0x6eda(%rip), %rsi      # 0xe585
movq %r15, %rdx
movq %r12, %r9
xorl %eax, %eax
callq 0x4060
movl $0x90, %edi
callq 0x4280
movq %rax, %r12
leaq -0xc8(%rbp), %rdi
leaq -0x910(%rbp), %rsi
leaq -0x2a(%rbp), %rdx
callq 0x40f0
movq %r14, %rdi
leaq -0x510(%rbp), %rsi
leaq -0x29(%rbp), %rdx
callq 0x40f0
movq -0x38(%rbp), %rbx
movq -0x60(%rbp), %rax
movq (%rax), %rax
subq %rax, %r13
movq %rbx, %r8
subq %rax, %r8
movb $0x1, %r15b
movq %r12, %rdi
leaq -0xc8(%rbp), %rsi
movq %r14, %rdx
movq %r13, %rcx
leaq -0xa8(%rbp), %r9
callq 0x6fda
movq %r12, -0x70(%rbp)
xorl %r15d, %r15d
movq -0x40(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xb286
movq %r14, %rdi
callq 0x4130
leaq -0xc8(%rbp), %rdi
callq 0x4130
movq -0x88(%rbp), %r15
leaq 0x1(%r15), %r13
leaq -0xa8(%rbp), %rdi
callq 0x4130
movq %r15, %rdi
movq -0x60(%rbp), %r12
movq (%r12), %rcx
xorl %eax, %eax
movq -0x58(%rbp), %rsi
movq -0x78(%rbp), %r15
incq %rdi
incq %rbx
jmp 0x75ca
addq $0x8f8, %rsp            # imm = 0x8F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x77a8
jmp 0x77a8
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x4130
jmp 0x7812
movq %rax, %rbx
jmp 0x77f7
jmp 0x77b6
movq %rax, %rbx
jmp 0x77e3
jmp 0x77b6
movq %rax, %rbx
jmp 0x77eb
movq %rax, %rbx
movb $0x1, %r15b
jmp 0x77d2
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x4130
leaq -0xc8(%rbp), %rdi
callq 0x4130
testb %r15b, %r15b
je 0x77eb
movq %r12, %rdi
callq 0x4250
leaq -0xa8(%rbp), %rdi
callq 0x4130
movq -0x40(%rbp), %rdi
callq 0xa6ee
movq -0x50(%rbp), %rdi
callq 0xa6da
movq -0x48(%rbp), %rdi
callq 0x9dd4
movq %rbx, %rdi
callq 0x44b0