// File: 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
subq $0xac0, %rsp            # imm = 0xAC0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x980(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10720
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x4140
movq -0x10(%rbp), %rdi
callq 0x10740
movq %rax, -0x978(%rbp)
jmp 0xbc99
movq -0x978(%rbp), %rdx
movq -0x980(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x10220
jmp 0xbcb2
leaq -0x38(%rbp), %rdi
callq 0x41c0
movq -0x980(%rbp), %rdi
leaq 0x25e0f(%rip), %rax     # 0x31ad8
movq %rax, (%rdi)
addq $0x48, %rdi
movq %rdi, -0x998(%rbp)
callq 0x10760
movq -0x980(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x990(%rbp)
callq 0x10780
movq -0x980(%rbp), %rax
movq $0x0, 0x78(%rax)
movq -0x10(%rbp), %rdi
callq 0x10740
movq %rax, -0x988(%rbp)
jmp 0xbd14
movq -0x988(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x7020
movq %rax, -0x9a0(%rbp)
jmp 0xbd31
movq -0x50(%rbp), %rdi
callq 0x20450
movq %rax, -0x9a8(%rbp)
jmp 0xbd43
movq -0x9a8(%rbp), %rcx
movq -0x9a0(%rbp), %rax
subq %rcx, %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x18(%rbp)
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0xbd9c
movq $0x1, -0x58(%rbp)
jmp 0xbd9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x41c0
jmp 0xc3e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xc3c0
movq -0x50(%rbp), %rdi
callq 0x7020
movq %rax, -0x9b0(%rbp)
jmp 0xbdae
movq -0x50(%rbp), %rdi
callq 0x20450
movq %rax, -0x9b8(%rbp)
jmp 0xbdc0
movq -0x9b8(%rbp), %rcx
movq -0x9b0(%rbp), %rax
subq %rcx, %rax
movq -0x58(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0x9c0(%rbp)
jmp 0xbdf8
movq -0x9c0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0x9c8(%rbp)
jmp 0xbe15
movq -0x9c8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rdi
callq 0x10810
movq %rax, -0x9d0(%rbp)
jmp 0xbe32
movq -0x9d0(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x107d0
testb $0x1, %al
jne 0xbe53
jmp 0xc3b7
leaq -0x70(%rbp), %rdi
callq 0x6700
movsbl (%rax), %eax
cmpl $0x4e, %eax
je 0xbe70
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jne 0xc39e
movq -0x50(%rbp), %rdi
movq %rdi, -0x9e0(%rbp)
callq 0x107a0
movq %rax, -0x9d8(%rbp)
jmp 0xbe97
movq -0x9d8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x108f0
movq %rax, -0x9f0(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0x9e8(%rbp)
jmp 0xbece
movq -0x9e8(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x108f0
movq -0x9e0(%rbp), %rsi
movq -0x9f0(%rbp), %rdx
movq %rax, %rcx
leaq -0xa0(%rbp), %rdi
callq 0x10840
jmp 0xbf0b
movq -0x980(%rbp), %rax
addq $0x48, %rax
movq %rax, -0xa00(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0x9f8(%rbp)
jmp 0xbf2f
movq -0x9f8(%rbp), %rax
movq %rax, -0x8d0(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x8d0(%rbp), %rsi
callq 0x108f0
incq %rax
movq %rax, -0x8c8(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0xa08(%rbp)
jmp 0xbf69
movq -0xa08(%rbp), %rax
movq %rax, -0x8e0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x8e0(%rbp), %rsi
callq 0x108f0
incq %rax
movq %rax, -0x8d8(%rbp)
leaq -0x8c0(%rbp), %rdi
leaq -0x8c8(%rbp), %rsi
leaq -0x8d8(%rbp), %rdx
callq 0x10960
jmp 0xbfad
movq -0xa00(%rbp), %rdi
leaq -0x8c0(%rbp), %rsi
callq 0x10930
jmp 0xbfc2
leaq -0x4b0(%rbp), %rax
movq %rax, -0xa18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10720
movq %rax, -0xa10(%rbp)
jmp 0xbfe2
movq -0xa10(%rbp), %rdi
callq 0x4130
movq -0x980(%rbp), %rdi
movq %rax, -0xa30(%rbp)
addq $0x48, %rdi
callq 0x10990
movq -0xa18(%rbp), %rdi
movq -0xa30(%rbp), %rdx
movq %rax, %rcx
leaq 0x1661a(%rip), %rsi     # 0x22637
xorl %eax, %eax
callq 0x4080
leaq -0x8b0(%rbp), %rax
movq %rax, -0xa28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10720
movq %rax, -0xa20(%rbp)
jmp 0xc044
movq -0xa20(%rbp), %rdi
callq 0x4130
movq %rax, -0xa40(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0xa38(%rbp)
jmp 0xc069
movq -0xa38(%rbp), %rax
movq %rax, -0x8e8(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x8e8(%rbp), %rsi
callq 0x108f0
incq %rax
movq %rax, -0xa50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0xa48(%rbp)
jmp 0xc0a3
movq -0xa48(%rbp), %rax
movq %rax, -0x8f0(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x8f0(%rbp), %rsi
callq 0x108f0
incq %rax
movq %rax, -0xa60(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7020
movq %rax, -0xa58(%rbp)
jmp 0xc0e0
leaq -0xa0(%rbp), %rdi
callq 0x20450
movq %rax, -0xa68(%rbp)
jmp 0xc0f5
movq -0xa68(%rbp), %rcx
movq -0xa58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xa78(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7020
movq %rax, -0xa70(%rbp)
jmp 0xc122
movq -0xa78(%rbp), %r9
movq -0xa60(%rbp), %r8
movq -0xa50(%rbp), %rcx
movq -0xa40(%rbp), %rdx
movq -0xa28(%rbp), %rdi
movq -0xa70(%rbp), %rsi
movq %rsp, %rax
movq %rsi, (%rax)
leaq 0x164e5(%rip), %rsi     # 0x2263e
xorl %eax, %eax
callq 0x4080
movq -0x980(%rbp), %rax
addq $0x60, %rax
movq %rax, -0xa88(%rbp)
movl $0x90, %edi
callq 0x4310
movq %rax, -0xa80(%rbp)
jmp 0xc185
movb $0x1, -0x959(%rbp)
leaq -0x919(%rbp), %rdi
movq %rdi, -0xa90(%rbp)
callq 0x45d0
movq -0xa90(%rbp), %rdx
leaq -0x918(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x4470
jmp 0xc1bb
leaq -0x941(%rbp), %rdi
movq %rdi, -0xa98(%rbp)
callq 0x45d0
movq -0xa98(%rbp), %rdx
leaq -0x940(%rbp), %rdi
leaq -0x8b0(%rbp), %rsi
callq 0x4470
jmp 0xc1ea
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0xaa0(%rbp)
jmp 0xc1fc
movq -0xaa0(%rbp), %rax
movq %rax, -0x950(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x950(%rbp), %rsi
callq 0x108f0
incq %rax
movq %rax, -0xab0(%rbp)
movq -0x50(%rbp), %rdi
callq 0x107a0
movq %rax, -0xaa8(%rbp)
jmp 0xc236
movq -0xaa8(%rbp), %rax
movq %rax, -0x958(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x958(%rbp), %rsi
callq 0x108f0
movq -0xa80(%rbp), %rdi
movq -0xab0(%rbp), %rcx
movq %rax, %r8
incq %r8
leaq -0x918(%rbp), %rsi
leaq -0x940(%rbp), %rdx
leaq -0xa0(%rbp), %r9
callq 0xb250
jmp 0xc284
movq -0xa88(%rbp), %rdi
movq -0xa80(%rbp), %rax
movb $0x0, -0x959(%rbp)
movq %rax, -0x8f8(%rbp)
leaq -0x8f8(%rbp), %rsi
callq 0x109b0
jmp 0xc2ae
leaq -0x940(%rbp), %rdi
callq 0x41c0
leaq -0x941(%rbp), %rdi
callq 0x4370
leaq -0x918(%rbp), %rdi
callq 0x41c0
leaq -0x919(%rbp), %rdi
callq 0x4370
movq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
callq 0x6cf0
movq %rax, -0x968(%rbp)
movq $0x0, -0x68(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x6590
jmp 0xc39e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xc390
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xc36b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xc353
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x940(%rbp), %rdi
callq 0x41c0
leaq -0x941(%rbp), %rdi
callq 0x4370
leaq -0x918(%rbp), %rdi
callq 0x41c0
leaq -0x919(%rbp), %rdi
callq 0x4370
testb $0x1, -0x959(%rbp)
jne 0xc382
jmp 0xc38e
movq -0xa80(%rbp), %rdi
callq 0x42c0
jmp 0xc390
leaq -0xa0(%rbp), %rdi
callq 0x6590
jmp 0xc3c0
jmp 0xc3a0
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
callq 0x6cf0
movq %rax, -0x970(%rbp)
jmp 0xbe20
addq $0xac0, %rsp            # imm = 0xAC0
popq %rbp
retq
movq -0x990(%rbp), %rdi
callq 0x109e0
movq -0x998(%rbp), %rdi
callq 0x10a40
movq -0x980(%rbp), %rdi
callq 0x130e0
movq -0x40(%rbp), %rdi
callq 0x45c0
nopl (%rax)