// File: /workspace/github_cpp_makefile_star2_O1/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 $0x8e8, %rsp            # imm = 0x8E8
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
leaq -0xf0(%rbp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x8(%rsi), %rsi
movq 0x10(%r12), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %r14
movq %r14, %rdi
callq 0x63a2
movq %r12, -0x48(%rbp)
addq $0x48, %r12
movq %r15, -0x38(%rbp)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xbafe
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x8e30
callq 0x4280
movq %r13, -0x30(%rbp)
leaq 0xeca5(%rip), %rax      # 0x17ae0
movq -0x38(%rbp), %rcx
movq %rax, (%rcx)
leaq 0x48(%rcx), %rax
movq %rax, -0x58(%rbp)
leaq 0x60(%rcx), %rax
movq %rax, -0x50(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rcx)
movups %xmm0, 0x58(%rcx)
movups %xmm0, 0x68(%rcx)
movq $0x0, 0x78(%rcx)
movq -0x48(%rbp), %rbx
movq 0x50(%rbx), %r15
movq %r12, %rdi
callq 0x10033
movq %rax, %r14
movq 0x50(%rbx), %r13
movq %r12, -0x40(%rbp)
movq %r12, %rdi
callq 0x10033
movq %rax, %rcx
subq %r14, %r15
movq %r15, %rax
xorl %edx, %edx
movq -0x30(%rbp), %rsi
divq %rsi
cmpq %rsi, %r15
movl $0x1, %esi
cmovaeq %rax, %rsi
subq %rcx, %r13
movq %r13, %rax
xorl %edx, %edx
divq %rsi
cmpq $0x0, 0x50(%rbx)
movq -0x38(%rbp), %r13
movq -0x40(%rbp), %r14
je 0x9146
movq %rbx, %r15
movq (%r14), %rcx
leaq 0x1(%rcx), %rbx
xorl %edx, %edx
movq %rcx, %r12
movq %rcx, -0x30(%rbp)
movq %rax, -0xa0(%rbp)
xorl %edi, %edi
cmpb $0x4e, (%r12)
setne %dil
addq %rdx, %rdi
cmpq %rax, %rdi
jne 0x9129
movq %r13, %r15
movq -0x30(%rbp), %r13
movq %r13, %rdx
subq %rcx, %rdx
notq %rcx
addq %rbx, %rcx
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0xbbae
movq (%r14), %rax
subq %rax, %r13
incq %r13
movq %rbx, %rdx
subq %rax, %rdx
movq %r13, -0x78(%rbp)
movq %rdx, -0x70(%rbp)
movq 0x50(%r15), %rsi
cmpq 0x58(%r15), %rsi
je 0x8f4a
movups -0x78(%rbp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x50(%r15)
jmp 0x8f57
movq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0xd8a0
movq -0x48(%rbp), %r14
movq 0x8(%r14), %rdx
movq 0x50(%r15), %rcx
subq 0x48(%r15), %rcx
sarq $0x4, %rcx
leaq -0x900(%rbp), %rdi
leaq 0x8675(%rip), %rsi      # 0x115ee
xorl %eax, %eax
callq 0x4070
movq 0x8(%r14), %r13
movq 0x48(%r14), %r15
movq -0x90(%rbp), %r14
leaq -0x98(%rbp), %rdi
callq 0x10033
movq %rbx, -0x68(%rbp)
movq %rbx, %r8
subq %r15, %r8
movq -0x30(%rbp), %rcx
subq %r15, %rcx
incq %rcx
subq %rax, %r14
movq -0x90(%rbp), %rax
movq %rax, (%rsp)
leaq -0x500(%rbp), %rdi
leaq 0x862a(%rip), %rsi      # 0x115f5
movq %r13, %rdx
movq %r14, %r9
xorl %eax, %eax
callq 0x4070
movl $0x90, %edi
callq 0x42b0
movq %rax, -0x60(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x900(%rbp), %r15
movq %r15, %rdi
callq 0x4130
leaq (%rax,%rbp), %rdx
addq $-0x900, %rdx           # imm = 0xF700
leaq -0xc0(%rbp), %rdi
movq %r15, %rsi
callq 0x643c
movq -0x48(%rbp), %rbx
movq -0x40(%rbp), %r13
leaq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x500(%rbp), %r14
movq %r14, %rdi
callq 0x4130
leaq (%rax,%rbp), %rdx
addq $-0x500, %rdx           # imm = 0xFB00
leaq -0xe0(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x643c
movq (%r13), %rax
movq -0x30(%rbp), %rcx
subq %rax, %rcx
incq %rcx
movq -0x68(%rbp), %r8
subq %rax, %r8
movb $0x1, %r13b
movq -0x60(%rbp), %r14
movq %r14, %rdi
leaq -0xc0(%rbp), %rsi
movq %r15, %rdx
leaq -0x98(%rbp), %r9
callq 0x881e
movq %rbx, %r15
movq %r14, -0x78(%rbp)
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rsi
cmpq 0x70(%rax), %rsi
je 0x90b3
movq %r14, (%rsi)
addq $0x8, 0x68(%rax)
jmp 0x90c3
xorl %r13d, %r13d
movq -0x50(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0xd9e6
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x90db
callq 0x4280
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
movq -0x38(%rbp), %r13
movq -0x40(%rbp), %r14
movq -0x68(%rbp), %rbx
je 0x90ff
callq 0x4280
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x9117
callq 0x4280
leaq 0x1(%r12), %rax
movq %rax, -0x30(%rbp)
xorl %edi, %edi
movq -0xa0(%rbp), %rax
incq %r12
movq 0x48(%r15), %rcx
movq 0x50(%r15), %rsi
addq %rcx, %rsi
incq %rbx
movq %rdi, %rdx
cmpq %rsi, %r12
jne 0x8ee2
addq $0x8e8, %rsp            # imm = 0x8E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9192
jmp 0x9192
movq %rax, %r15
movq -0x100(%rbp), %rdi
cmpq %rbx, %rdi
je 0x921b
callq 0x4280
jmp 0x921b
jmp 0x9185
jmp 0x9185
movq %rax, %r15
movb $0x1, %r13b
jmp 0x91ca
movq %rax, %r15
jmp 0x91d8
movq %rax, %r15
movb $0x1, %r13b
jmp 0x91b2
movq %rax, %r15
jmp 0x91f0
movq %rax, %r15
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
cmpq %rax, %rdi
je 0x91b2
callq 0x4280
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x91ca
callq 0x4280
testb %r13b, %r13b
je 0x91d8
movq -0x60(%rbp), %rdi
callq 0x4280
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x91f0
callq 0x4280
movq -0x50(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x9201
callq 0x4280
movq -0x58(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x9212
callq 0x4280
movq -0x38(%rbp), %rdi
callq 0xc60c
movq %r15, %rdi
callq 0x4500
nop