// File: /workspace/github_cpp_makefile_star2_O1/CK7[P]abawaca/src/abawaca-build.cpp
// Function: Scaf_segment::Scaf_segment(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned long, unsigned long, Bio::DNAString const&)
Scaf_segment::Scaf_segment(string _display_id, string _desc, size_t s, size_t e, const Bio::DNAString& _seq) : start(s), end(e), Sequence(_display_id, _seq), desc(_desc)
{
	int k = 4;
	if(dimension2index.size() == 0) {
		prepare_mer_indexes(k, dimension2index);
	}
	dimensions.resize(dimension_order.size());

	// Compute 1,2,3 and 4-mer frequencies
	int factor = 10;
	int N_limit = 1;
	for(auto i=1; i<=k; i++, N_limit*=10, factor*=10) {
		// Shouldn't happen...
		if(seq.size() < i)
			continue;

		unordered_map<size_t, size_t>	counts;
		int 	key=0, total=0;
		auto	it_start = seq.begin(), it_end = seq.begin();

		// Add first mer
		while(it_end-it_start < i) {
			key *= 10;	// 0=00000, 2=00010, 6=00110, 19=10011
			switch(*(it_end++)) {
				case 'A':	key += 2;	break;
				case 'C':	key += 3;	break;
				case 'G':	key += 4;	break;
				case 'T':	key += 5;	break;
				default:	key = 0;
			}
		}
		if(key > N_limit) {
			counts[key]++;
 			total++;
		}
		// Rest of the mers
		while(it_end != seq.end()) {
			key *= 10;
			key = key%factor;
			switch(*(it_end++)) {
				case 'A':	key += 2;	break;
				case 'C':	key += 3;	break;
				case 'G':	key += 4;	break;
				case 'T':	key += 5;	break;
				default:	key = 0;
			}

			// The following means that there are no N's in mer)
			if(key > N_limit) {
				counts[key]++;
				total++;
			}
		}

		for(auto it=counts.begin(); it!=counts.end(); it++) {
			string mer;
			for(int i=factor; i>0; i/=10)
			switch((it->first/i)%10) {
				case 2:	mer.push_back('A');	break;
				case 3:	mer.push_back('C');	break;
				case 4:	mer.push_back('G');	break;
				case 5:	mer.push_back('T');	break;
			}
			auto sit = dimension2index.find(mer);
			if(sit == dimension2index.end()) {
				cerr << "Error: could not find index for " << mer << endl;
				exit(-1);
			}
			dimensions[sit->second] += (total != 0)? (double(it->second)/total): 0;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, %r13
movq %r8, -0x40(%rbp)
movq %rcx, %r12
movq %rdx, %r14
movq %rdi, %rbx
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0xb0(%rbp), %r15
movq %r15, %rdi
movq %rax, %rsi
callq 0x63a2
movq %rbx, -0x38(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xbafe
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x8893
callq 0x4280
leaq 0xf226(%rip), %rax      # 0x17ac0
movq -0x38(%rbp), %r13
movq %rax, (%r13)
movq %r12, 0x48(%r13)
movq -0x40(%rbp), %rax
movq %rax, 0x50(%r13)
leaq 0x58(%r13), %rdi
leaq 0x68(%r13), %rax
movq %rax, -0x80(%rbp)
movq %rax, 0x58(%r13)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %rdi, -0x88(%rbp)
callq 0x63a2
leaq 0x78(%r13), %rax
movq %rax, -0x50(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x78(%r13)
movq $0x0, 0x88(%r13)
cmpq $0x0, 0xfa5f(%rip)      # 0x18358
jne 0x890c
leaq 0xfa2e(%rip), %rsi      # 0x18330
movl $0x4, %edi
callq 0x877f
movq 0xfa55(%rip), %rsi      # 0x18368
subq 0xfa46(%rip), %rsi      # 0x18360
sarq $0x5, %rsi
movq -0x50(%rbp), %rdi
callq 0xbb76
movl $0xa, %eax
movq %rax, -0x40(%rbp)
movl $0x1, %eax
movq %rax, -0x48(%rbp)
movl $0x1, %ecx
movabsq $-0x3333333333333333, %rbx # imm = 0xCCCCCCCCCCCCCCCD
movl $0xcccccccd, %r15d      # imm = 0xCCCCCCCD
cmpq %rcx, 0x30(%r13)
jb 0x8bb9
movq %rcx, -0x58(%rbp)
leaq -0xb8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq $0x1, -0xe0(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0xc8(%rbp) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
movq 0x28(%r13), %r12
xorl %eax, %eax
xorl %r14d, %r14d
addl %r14d, %r14d
leal (%r14,%r14,4), %ecx
movzbl (%r12,%rax), %edx
cmpl $0x46, %edx
jg 0x89bc
cmpl $0x41, %edx
je 0x89d1
movl $0x0, %r14d
cmpl $0x43, %edx
jne 0x89dc
addl $0x3, %ecx
jmp 0x89d9
cmpl $0x47, %edx
je 0x89d6
movl $0x0, %r14d
cmpl $0x54, %edx
jne 0x89dc
addl $0x5, %ecx
jmp 0x89d9
addl $0x2, %ecx
jmp 0x89d9
addl $0x4, %ecx
movl %ecx, %r14d
incq %rax
cmpq -0x58(%rbp), %rax
jb 0x8996
movl $0x0, -0x2c(%rbp)
cmpl -0x48(%rbp), %r14d
jle 0x8a13
movslq %r14d, %rax
movq %rax, -0x78(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xd5b0
incq (%rax)
movl $0x1, -0x2c(%rbp)
addq -0x58(%rbp), %r12
movq 0x28(%r13), %rax
addq 0x30(%r13), %rax
cmpq %rax, %r12
je 0x8a8d
addl %r14d, %r14d
leal (%r14,%r14,4), %eax
cltd
idivl -0x40(%rbp)
movzbl (%r12), %eax
xorl %r14d, %r14d
cmpl $0x46, %eax
jg 0x8a4b
cmpl $0x41, %eax
je 0x8a5a
cmpl $0x43, %eax
jne 0x8a65
addl $0x3, %edx
jmp 0x8a62
cmpl $0x47, %eax
je 0x8a5f
cmpl $0x54, %eax
jne 0x8a65
addl $0x5, %edx
jmp 0x8a62
addl $0x2, %edx
jmp 0x8a62
addl $0x4, %edx
movl %edx, %r14d
cmpl -0x48(%rbp), %r14d
jle 0x8a88
movslq %r14d, %rax
movq %rax, -0x78(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xd5b0
incq (%rax)
incl -0x2c(%rbp)
incq %r12
jmp 0x8a17
movq -0xd8(%rbp), %r14
testq %r14, %r14
je 0x8ba9
xorps %xmm0, %xmm0
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x70(%rbp)
movb $0x0, -0x68(%rbp)
movq -0x40(%rbp), %rax
movl %eax, %r12d
movq 0x8(%r14), %rax
movl %r12d, %r13d
xorl %edx, %edx
divq %r13
movq %rax, %rcx
mulq %rbx
shrq $0x2, %rdx
andq $-0x2, %rdx
leaq (%rdx,%rdx,4), %rax
negq %rax
addq %rax, %rcx
addq $-0x2, %rcx
cmpq $0x4, %rcx
jae 0x8b0c
shll $0x3, %ecx
movl $0x54474341, %eax       # imm = 0x54474341
shrl %cl, %eax
movzbl %al, %esi
leaq -0x78(%rbp), %rdi
callq 0x4240
imulq %r15, %r13
shrq $0x23, %r13
cmpl $0xa, %r12d
movl %r13d, %r12d
jae 0x8ac8
leaq 0xf80c(%rip), %rdi      # 0x18330
leaq -0x78(%rbp), %rsi
callq 0xcf66
leaq 0xf804(%rip), %rcx      # 0x18338
cmpq %rcx, %rax
je 0x8bf2
cmpl $0x0, -0x2c(%rbp)
je 0x8b6e
movsd 0x10(%r14), %xmm1
unpcklps 0x87f0(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x87f8(%rip), %xmm1     # 0x11350
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
divsd -0x90(%rbp), %xmm0
jmp 0x8b72
xorpd %xmm0, %xmm0
movq -0x38(%rbp), %r13
movq 0x40(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
addsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x8b9d
callq 0x4280
movq (%r14), %r14
testq %r14, %r14
jne 0x8aad
leaq -0xe8(%rbp), %rdi
callq 0xc668
movq -0x58(%rbp), %rcx
incq %rcx
movq -0x48(%rbp), %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
movq %rax, -0x40(%rbp)
cmpq $0x5, %rcx
jne 0x894e
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf3f7(%rip), %rdi      # 0x17ff0
leaq 0x89cd(%rip), %rsi      # 0x115cd
movl $0x20, %edx
callq 0x4320
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq 0xf3d7(%rip), %rdi      # 0x17ff0
callq 0x4320
movq %rax, %rdi
callq 0x4140
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x4370
movq %rax, %r14
jmp 0x8cad
movq %rax, %r14
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x8cb5
callq 0x4280
jmp 0x8cb5
movq %rax, %r14
jmp 0x8c87
jmp 0x8c59
movq %rax, %r14
jmp 0x8c7b
jmp 0x8c62
jmp 0x8c62
movq %rax, %r14
movq -0x38(%rbp), %r13
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x8c7b
callq 0x4280
leaq -0xe8(%rbp), %rdi
callq 0xc668
movq -0x50(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x8c98
callq 0x4280
movq -0x88(%rbp), %rax
movq (%rax), %rdi
cmpq -0x80(%rbp), %rdi
je 0x8cad
callq 0x4280
movq %r13, %rdi
callq 0xc60c
movq %r14, %rdi
callq 0x4500
nop