// File: RasmusFonseca[P]PDBCluster/main.cpp
// Function: fillMatrices(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, int, int, std::vector<Matrix*, std::allocator<Matrix*>>&)
void fillMatrices(vector<string> &files, vector<string> &atomTypes, int firstRes, int lastRes, vector<Matrix*> &ret)
{
	//for( string fName: files ){
	for(unsigned int i=0;i<files.size(); i++){
		string fName = files[i];
		//cout<<fName<<endl;
		int atomCount = 0;
		ifstream fs(fName.c_str(), ifstream::in);
		string token;
		while (fs>>token) {
			if(token=="ATOM"){
				string name, tmp, resiStr;
				fs>>tmp>>name>>tmp>>tmp>>resiStr;
				int resi = atoi(resiStr.c_str());
				if(find(atomTypes.begin(), atomTypes.end(), name) != atomTypes.end() && resi>=firstRes && resi<=lastRes)
					atomCount++;
			}
		}
		fs.close();

		Matrix* coords = new Matrix(atomCount,3);
		atomCount=0;
		ifstream fs2(fName.c_str(), ifstream::in);
		string line;
		while (std::getline(fs2, line)){
			if(line.find("ATOM")==0){
				string name = line.substr(12,5);
				name = trim(name);
				string resiStr = line.substr(22,5);
				resiStr = trim(resiStr);
				int resi = atoi(resiStr.c_str());
				if(find(atomTypes.begin(), atomTypes.end(), name) != atomTypes.end() && resi>=firstRes && resi<=lastRes){
					string x = line.substr(30,8);
					string y = line.substr(38,8);
					string z = line.substr(46,8);
					coords->set(atomCount,0, atof(x.c_str()));
					coords->set(atomCount,1, atof(y.c_str()));
					coords->set(atomCount,2, atof(z.c_str()));
					atomCount++;
				}
			}
		}
		fs2.close();

		Matrix* d = new Matrix(atomCount, atomCount);
		for(int i=0;i<atomCount;i++){
			for(int j=i+1;j<atomCount;j++){
				double dx = coords->get(i,0)-coords->get(j,0);
				double dy = coords->get(i,1)-coords->get(j,1);
				double dz = coords->get(i,2)-coords->get(j,2);
				double dist = sqrt(dx*dx+dy*dy+dz*dz);
				d->set( i,j,dist );
				d->set( j,i,dist );
			}
		}
		ret.push_back(d);
		delete coords;
		//delete cTrans;
	}
}

// Assembly:
subq $0x738, %rsp            # imm = 0x738
movq %rdi, 0x730(%rsp)
movq %rsi, 0x728(%rsp)
movl %edx, 0x724(%rsp)
movl %ecx, 0x720(%rsp)
movq %r8, 0x718(%rsp)
movl $0x0, 0x714(%rsp)
movl 0x714(%rsp), %eax
movq %rax, 0xf8(%rsp)
movq 0x730(%rsp), %rdi
callq 0x5bb0
movq %rax, %rcx
movq 0xf8(%rsp), %rax
cmpq %rcx, %rax
jae 0x375e
movq 0x730(%rsp), %rdi
movl 0x714(%rsp), %eax
movl %eax, %esi
callq 0x5bd0
movq %rax, %rsi
leaq 0x6f0(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
callq 0x20f0
movq 0xf0(%rsp), %rdi
movl $0x0, 0x6ec(%rsp)
callq 0x20e0
movq %rax, %rsi
leaq 0x4e0(%rsp), %rdi
movl $0x8, %edx
callq 0x23e0
jmp 0x2c25
leaq 0x4b0(%rsp), %rdi
callq 0x22f0
leaq 0x4e0(%rsp), %rdi
leaq 0x4b0(%rsp), %rsi
callq 0x22b0
movq %rax, 0xe8(%rsp)
jmp 0x2c51
movq 0xe8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x22a0
movb %al, 0xe7(%rsp)
jmp 0x2c71
movb 0xe7(%rsp), %al
testb $0x1, %al
jne 0x2c81
jmp 0x2f1b
leaq 0x8488(%rip), %rsi      # 0xb110
leaq 0x4b0(%rsp), %rdi
callq 0x5bf0
movb %al, 0xe6(%rsp)
jmp 0x2c9e
movb 0xe6(%rsp), %al
testb $0x1, %al
jne 0x2cae
jmp 0x2f16
leaq 0x490(%rsp), %rdi
callq 0x22f0
leaq 0x470(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x22f0
leaq 0x450(%rsp), %rdi
callq 0x22f0
movq 0xd0(%rsp), %rsi
leaq 0x4e0(%rsp), %rdi
callq 0x22b0
movq %rax, 0xd8(%rsp)
jmp 0x2cfc
movq 0xd8(%rsp), %rdi
leaq 0x490(%rsp), %rsi
callq 0x22b0
movq %rax, 0xc8(%rsp)
jmp 0x2d1b
movq 0xc8(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x22b0
movq %rax, 0xc0(%rsp)
jmp 0x2d3a
movq 0xc0(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x22b0
movq %rax, 0xb8(%rsp)
jmp 0x2d59
movq 0xb8(%rsp), %rdi
leaq 0x450(%rsp), %rsi
callq 0x22b0
jmp 0x2d70
leaq 0x450(%rsp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2340
movl %eax, 0x44c(%rsp)
movq 0x728(%rsp), %rdi
callq 0x5cc0
movq %rax, 0x438(%rsp)
movq 0x728(%rsp), %rdi
callq 0x5cf0
movq %rax, 0x430(%rsp)
movq 0x438(%rsp), %rdi
movq 0x430(%rsp), %rsi
leaq 0x490(%rsp), %rdx
callq 0x5c60
movq %rax, 0xb0(%rsp)
jmp 0x2ddd
movq 0xb0(%rsp), %rax
movq %rax, 0x440(%rsp)
movq 0x728(%rsp), %rdi
callq 0x5cf0
movq %rax, 0x428(%rsp)
leaq 0x440(%rsp), %rdi
leaq 0x428(%rsp), %rsi
callq 0x5c20
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xaf(%rsp)
jne 0x2e29
jmp 0x2e5a
movl 0x44c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x724(%rsp), %ecx
movb %al, 0xaf(%rsp)
jl 0x2e5a
movl 0x44c(%rsp), %eax
cmpl 0x720(%rsp), %eax
setle %al
movb %al, 0xaf(%rsp)
movb 0xaf(%rsp), %al
testb $0x1, %al
jne 0x2e6a
jmp 0x2eef
movl 0x6ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6ec(%rsp)
jmp 0x2eef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x374f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x3735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
leaq 0x450(%rsp), %rdi
callq 0x2160
leaq 0x470(%rsp), %rdi
callq 0x2160
leaq 0x490(%rsp), %rdi
callq 0x2160
jmp 0x3735
leaq 0x450(%rsp), %rdi
callq 0x2160
leaq 0x470(%rsp), %rdi
callq 0x2160
leaq 0x490(%rsp), %rdi
callq 0x2160
jmp 0x2c32
leaq 0x4e0(%rsp), %rdi
callq 0x2060
jmp 0x2f2a
movl $0x10, %edi
callq 0x2220
movq %rax, 0xa0(%rsp)
jmp 0x2f3e
movq 0xa0(%rsp), %rdi
movl 0x6ec(%rsp), %esi
movl $0x3, %edx
callq 0x25a0
jmp 0x2f59
movq 0xa0(%rsp), %rax
movq %rax, 0x420(%rsp)
movl $0x0, 0x6ec(%rsp)
leaq 0x6f0(%rsp), %rdi
callq 0x20e0
movq %rax, %rsi
leaq 0x218(%rsp), %rdi
movl $0x8, %edx
callq 0x23e0
jmp 0x2f98
leaq 0x1f8(%rsp), %rdi
callq 0x22f0
leaq 0x218(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x2050
movq %rax, 0x98(%rsp)
jmp 0x2fc4
movq 0x98(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x22a0
movb %al, 0x97(%rsp)
jmp 0x2fe4
movb 0x97(%rsp), %al
testb $0x1, %al
jne 0x2ff4
jmp 0x3419
leaq 0x1f8(%rsp), %rdi
leaq 0x810d(%rip), %rsi      # 0xb110
xorl %eax, %eax
movl %eax, %edx
callq 0x2400
cmpq $0x0, %rax
jne 0x3414
leaq 0x1d8(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movl $0xc, %edx
movl $0x5, %ecx
callq 0x2230
jmp 0x3037
leaq 0x1d8(%rsp), %rdi
callq 0x3780
movq %rax, 0x88(%rsp)
jmp 0x304e
movq 0x88(%rsp), %rsi
leaq 0x1d8(%rsp), %rdi
callq 0x2040
jmp 0x3065
leaq 0x1b8(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movl $0x16, %edx
movl $0x5, %ecx
callq 0x2230
jmp 0x3086
leaq 0x1b8(%rsp), %rdi
callq 0x3780
movq %rax, 0x80(%rsp)
jmp 0x309d
movq 0x80(%rsp), %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x2040
jmp 0x30b4
leaq 0x1b8(%rsp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2340
movl %eax, 0x1b4(%rsp)
movq 0x728(%rsp), %rdi
callq 0x5cc0
movq %rax, 0x1a0(%rsp)
movq 0x728(%rsp), %rdi
callq 0x5cf0
movq %rax, 0x198(%rsp)
movq 0x1a0(%rsp), %rdi
movq 0x198(%rsp), %rsi
leaq 0x1d8(%rsp), %rdx
callq 0x5c60
movq %rax, 0x78(%rsp)
jmp 0x311e
movq 0x78(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq 0x728(%rsp), %rdi
callq 0x5cf0
movq %rax, 0x190(%rsp)
leaq 0x1a8(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x5c20
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x77(%rsp)
jne 0x3164
jmp 0x318f
movl 0x1b4(%rsp), %ecx
xorl %eax, %eax
cmpl 0x724(%rsp), %ecx
movb %al, 0x77(%rsp)
jl 0x318f
movl 0x1b4(%rsp), %eax
cmpl 0x720(%rsp), %eax
setle %al
movb %al, 0x77(%rsp)
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x319c
jmp 0x33d9
leaq 0x170(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movl $0x1e, %edx
movl $0x8, %ecx
callq 0x2230
jmp 0x31bd
leaq 0x150(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movl $0x26, %edx
movl $0x8, %ecx
callq 0x2230
jmp 0x31de
leaq 0x130(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movl $0x2e, %edx
movl $0x8, %ecx
callq 0x2230
jmp 0x31ff
movq 0x420(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x6ec(%rsp), %eax
movl %eax, 0x70(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2290
movq 0x68(%rsp), %rdi
movl 0x70(%rsp), %esi
xorl %edx, %edx
callq 0x2820
jmp 0x323e
movq 0x420(%rsp), %rax
movq %rax, 0x58(%rsp)
movl 0x6ec(%rsp), %eax
movl %eax, 0x64(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2290
movq 0x58(%rsp), %rdi
movl 0x64(%rsp), %esi
movl $0x1, %edx
callq 0x2820
jmp 0x3280
movq 0x420(%rsp), %rax
movq %rax, 0x48(%rsp)
movl 0x6ec(%rsp), %eax
movl %eax, 0x54(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x20e0
movq %rax, %rdi
callq 0x2290
movq 0x48(%rsp), %rdi
movl 0x54(%rsp), %esi
movl $0x2, %edx
callq 0x2820
jmp 0x32c2
movl 0x6ec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6ec(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x2160
leaq 0x150(%rsp), %rdi
callq 0x2160
leaq 0x170(%rsp), %rdi
callq 0x2160
jmp 0x33d9
movq 0xa0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
callq 0x2200
jmp 0x3735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x371b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x3402
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x33f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x33ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
jmp 0x33bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x2160
leaq 0x150(%rsp), %rdi
callq 0x2160
leaq 0x170(%rsp), %rdi
callq 0x2160
jmp 0x33f5
leaq 0x1b8(%rsp), %rdi
callq 0x2160
leaq 0x1d8(%rsp), %rdi
callq 0x2160
jmp 0x3414
leaq 0x1b8(%rsp), %rdi
callq 0x2160
leaq 0x1d8(%rsp), %rdi
callq 0x2160
jmp 0x371b
jmp 0x2fa5
leaq 0x218(%rsp), %rdi
callq 0x2060
jmp 0x3428
movl $0x10, %edi
callq 0x2220
movq %rax, 0x40(%rsp)
jmp 0x3439
movq 0x40(%rsp), %rdi
movl 0x6ec(%rsp), %edx
movl %edx, %esi
callq 0x25a0
jmp 0x344e
movq 0x40(%rsp), %rax
movq %rax, 0x128(%rsp)
movl $0x0, 0x124(%rsp)
movl 0x124(%rsp), %eax
cmpl 0x6ec(%rsp), %eax
jge 0x3686
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
movl 0x120(%rsp), %eax
cmpl 0x6ec(%rsp), %eax
jge 0x366e
movq 0x420(%rsp), %rdi
movl 0x124(%rsp), %esi
xorl %edx, %edx
callq 0x2730
movsd %xmm0, 0x38(%rsp)
jmp 0x34bd
movq 0x420(%rsp), %rdi
movl 0x120(%rsp), %esi
xorl %edx, %edx
callq 0x2730
movsd %xmm0, 0x30(%rsp)
jmp 0x34db
movsd 0x30(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x118(%rsp)
movq 0x420(%rsp), %rdi
movl 0x124(%rsp), %esi
movl $0x1, %edx
callq 0x2730
movsd %xmm0, 0x28(%rsp)
jmp 0x3515
movq 0x420(%rsp), %rdi
movl 0x120(%rsp), %esi
movl $0x1, %edx
callq 0x2730
movsd %xmm0, 0x20(%rsp)
jmp 0x3536
movsd 0x20(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x110(%rsp)
movq 0x420(%rsp), %rdi
movl 0x124(%rsp), %esi
movl $0x2, %edx
callq 0x2730
movsd %xmm0, 0x18(%rsp)
jmp 0x3570
movq 0x420(%rsp), %rdi
movl 0x120(%rsp), %esi
movl $0x2, %edx
callq 0x2730
movsd %xmm0, 0x10(%rsp)
jmp 0x3591
movsd 0x10(%rsp), %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x108(%rsp)
movsd 0x118(%rsp), %xmm1
movsd 0x110(%rsp), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x108(%rsp), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
callq 0x21b0
movsd %xmm0, 0x100(%rsp)
movq 0x128(%rsp), %rdi
movl 0x124(%rsp), %esi
movl 0x120(%rsp), %edx
movsd 0x100(%rsp), %xmm0
callq 0x2820
jmp 0x360d
movq 0x128(%rsp), %rdi
movl 0x120(%rsp), %esi
movl 0x124(%rsp), %edx
movsd 0x100(%rsp), %xmm0
callq 0x2820
jmp 0x3633
jmp 0x3635
movl 0x120(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x120(%rsp)
jmp 0x348b
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4d8(%rsp)
movl %eax, 0x4d4(%rsp)
callq 0x2200
jmp 0x371b
jmp 0x3670
movl 0x124(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x124(%rsp)
jmp 0x3466
movq 0x718(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x5d20
jmp 0x369d
movq 0x420(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x36c4
movq 0x8(%rsp), %rdi
callq 0x26e0
movq 0x8(%rsp), %rdi
callq 0x2200
leaq 0x1f8(%rsp), %rdi
callq 0x2160
leaq 0x218(%rsp), %rdi
callq 0x2080
leaq 0x4b0(%rsp), %rdi
callq 0x2160
leaq 0x4e0(%rsp), %rdi
callq 0x2080
leaq 0x6f0(%rsp), %rdi
callq 0x2160
movl 0x714(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x714(%rsp)
jmp 0x2b98
leaq 0x1f8(%rsp), %rdi
callq 0x2160
leaq 0x218(%rsp), %rdi
callq 0x2080
leaq 0x4b0(%rsp), %rdi
callq 0x2160
leaq 0x4e0(%rsp), %rdi
callq 0x2080
leaq 0x6f0(%rsp), %rdi
callq 0x2160
jmp 0x3766
addq $0x738, %rsp            # imm = 0x738
retq
movq 0x4d8(%rsp), %rdi
callq 0x23c0
nopw %cs:(%rax,%rax)