// File: /workspace/github_cpp_makefile_star2_O3/RasmusFonseca[P]PDBCluster/main.cpp
// Function: main
int main(int argc, char** argv)
{
	//Print usage
	if( argc==1 ){
		cout<<"Usage: "<<endl<<argv[0]<<" -name <atomtype1> [-name <atomtype2> ..] -clusteringType <distSum|maxDistSum|maxDist> -firstRes <int> -lastRes <int> -clusters <integer> [list of pdb-files]"<<endl;
		cout<<"or: "<<endl<<argv[0]<<" -name <atomtype1> [-name <atomtype2> ..] -dumpDistances <filename>"<<endl;
		cout<<"Example of running k-centers for k=10:"<<endl;
		cout<<argv[0]<<" -name CA -name CB -clusteringType maxDist -clusters 10 sample1.pdb sample2.pdb sample3.pdb ..."<<endl;
		cout<<endl;
		cout<<"Standard value for -name is C4' and CA"<<endl;
		cout<<"Standard value for -clusteringType is distSum"<<endl;
		cout<<"Standard value for -clusters is 10"<<endl;
		cout<<"Standard value for -firstRes is -10000000"<<endl;
		cout<<"Standard value for -lastRes is 10000000"<<endl;
		cout<<endl;
		cout<<"\"-clusteringType distSum\" will perform standard k-medoids clustering where the cost associated with a set of medoids is the average distance from each member to its nearest medoid."<<endl;
		cout<<"\"-clusteringType maxDistSum\" will perform a variant of k-centers clustering where the cost associated with a set of medoids is the average distance from each medoid to its furthest associated member."<<endl;
		cout<<"\"-clusteringType maxDist\" will perform k-centers clustering where the cost associated with a set of medoids is the largest distance from any site to the nearest medoid."<<endl;
		cout<<"For all clustering types, the dRMSD metric is used to indicate the distance between two structures. If -dumpDistances is specified no clustering is performed, the structure dRMSD distance matrix is just written to the specified file."<<endl;
		exit(0);
	}

	//Parse arguments
	vector<string> atomTypes;
	vector<string> files;
	string distFileName;
	int clusters = 10;
	int clusteringType = 0;
	int firstRes = -10000000;
	int lastRes = 10000000;
	for(int i=1;i<argc;i++){
		string arg(argv[i]);
		if( arg=="-name" ){
			string nextArg(argv[++i]);
			atomTypes.push_back(nextArg);
		}else if( arg=="-clusteringType" ){
			string nextArg(argv[++i]);
			if(nextArg=="distSum") clusteringType = 0;
			if(nextArg=="maxDistSum") clusteringType = 1;
			if(nextArg=="maxDist") clusteringType = 2;
		}else if( arg=="-dumpDistances" ){
			string nextArg(argv[++i]);
			distFileName = nextArg;
		}else if( arg=="-clusters" ){
			clusters = atoi(argv[++i]);
		}else if( arg=="-firstRes" ){
			firstRes = atoi(argv[++i]);
		}else if( arg=="-lastRes" ){
			lastRes = atoi(argv[++i]);
		}else if( arg[0]=='-' ){
			cerr<<"Unknown argument: "<<arg<<endl;
			exit(-1);
		}else{
			files.push_back(arg);
		}
	}
	if(atomTypes.empty()){
		atomTypes.push_back("C4'");
		atomTypes.push_back("CA");
	}


	double start_cpu = get_cpu_time();
	double start_wall = get_wall_time();

	vector<Matrix*> strucMatrices;
	cout<<"Reading pdb-files"<<endl;
	fillMatrices(files, atomTypes, firstRes, lastRes, strucMatrices);

	cout<<"Filling matrix"<<endl;
	int s = strucMatrices.size();
	Matrix allDists(s,s);
	for(int i=0; i<s; i++){
		for(int j=i+1; j<s; j++){
			double d = strucMatrices[i]->getDifferenceSum(strucMatrices[j]);
			allDists.set(i,j,d);
			allDists.set(j,i,d);
		}
	}

	//If -dumpDistances was specified distFileName will be nonempty and we only print the distances and exit
	if(!distFileName.empty()){
		cout<<"Writing distances to "<<distFileName<<endl;
		//Check if all files are of the format "newpdb_.*.pdb"
		bool newpdbFiles = true;
		for(unsigned int i=0;i<files.size();i++){
			size_t pos1 = files[i].find("newpdb_");
			size_t pos2 = files[i].find(".pdb", pos1);
			if(pos1==string::npos || pos2==string::npos || pos2<pos1){
				newpdbFiles = false;
				break;
			}
		}

		
		ofstream distFile;
		distFile.open(distFileName);
		if(newpdbFiles){
			for(int i=0; i<s; i++){
				size_t pos1 = files[i].find("newpdb_");
				size_t pos2 = files[i].find(".pdb",pos1);
				string id_i = files[i].substr(pos1+7, pos2-pos1-7); 
				for(int j=i+1; j<s; j++){
					pos1 = files[j].find("newpdb_");
					pos2 = files[j].find(".pdb",pos1);
					string id_j = files[j].substr(pos1+7, pos2-pos1-7); 
					distFile<<id_i<<" "<<id_j<<" "<<allDists.get(i,j)<<endl;
				}
			}
		}else{
			for(int i=0; i<s; i++){
				for(int j=i+1; j<s; j++){
					distFile<<files[i]<<" "<<files[j]<<" "<<allDists.get(i,j)<<endl;
				}
			}
		}
		distFile.close();

		//ofstream distFile;
		//distFile.open(distFileName);
		//for(int i=0; i<s; i++){
		//	for(int j=i+1; j<s; j++){
		//		distFile<<i<<" "<<j<<" "<<allDists.get(i,j)<<endl;
		//	}
		//}
		//distFile.close();
		exit(0);
	}

	if(clusters>s){
		cerr<<"Cannot find "<<clusters<<" clusters in "<<s<<" structures"<<endl;
		exit(-1);
	}

	cout<<"Clustering"<<endl;
	vector<int> medoids;
	for(int i=0;i<clusters;i++){
		int val = rand()%s;
		while(contains(medoids, val)) val=rand()%s;
		medoids.push_back(val);
		//medoids.push_back(rand()%s);
		//medoids.push_back(i);
	}

	//Partitioning around medoids: http://en.wikipedia.org/wiki/K-medoids
	double oldCost = -1, cost = medoidCosts(medoids, allDists, clusteringType);
	while(cost!=oldCost){
		oldCost = cost;
		for(int i=0;i<clusters;i++){
			int medoid = medoids[i];
			for(int j=0;j<s;j++){
				if( contains(medoids,j) ) continue;
				medoids[i] = j;
				double newCost = medoidCosts(medoids, allDists, clusteringType );
				if(newCost<cost){
					cost=newCost;
					medoid = j;
					cout<<"Improved cost: "<<newCost<<endl;
				}
			}
			medoids[i] = medoid;
		}
	}
	sort(medoids.begin(), medoids.end());
	double end_cpu = get_cpu_time();
	double end_wall = get_wall_time();
	cout<<"CPU-time : "<<(end_cpu-start_cpu)<<" seconds"<<endl;
	cout<<"Wall-time: "<<(end_wall-start_wall)<<" seconds"<<endl;

	cout<<"Clusters:"<<endl;
	for(unsigned int i=0;i<files.size();i++){
		double min = 1000000000.0;
		int minMed = -1;

		for(unsigned int j=0;j<medoids.size();j++){
			int m = medoids[j];
			double d = allDists.get(m,i);
			if( d<min ) { min = d; minMed = j; }
		}
		cout<<files[i]<<" "<<minMed<<endl;

	}
	cout<<"Medoids:"<<endl;
	for( int m=0;m<clusters;m++)
		cout<<files[medoids[m]]<<endl;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq %rsi, %r12
cmpl $0x1, %edi
je 0x426a
movl %edi, %r13d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x80(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x90(%rsp)
movq %rcx, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, 0x28(%rsp)
movq %rcx, -0x8(%rax)
movb $0x0, (%rax)
cmpl $0x2, %edi
jl 0x39bc
movl $0x989680, 0x20(%rsp)   # imm = 0x989680
movl $0xff676980, 0x10(%rsp) # imm = 0xFF676980
movq $0x0, 0x28(%rsp)
movl $0xa, 0xc(%rsp)
leaq 0x110(%rsp), %rbp
leaq 0x48(%rsp), %r14
movl $0x1, %ebx
movslq %ebx, %r15
movq (%r12,%r15,8), %rsi
movq %rbp, %rdi
movq %r14, %rdx
callq 0x20c0
movq %rbp, %rdi
leaq 0x2e50(%rip), %rsi      # 0x6637
callq 0x20a0
testl %eax, %eax
je 0x388a
movq %rbp, %rdi
leaq 0x2e3f(%rip), %rsi      # 0x663d
callq 0x20a0
testl %eax, %eax
je 0x38b4
movq %rbp, %rdi
leaq 0x2e4b(%rip), %rsi      # 0x6660
callq 0x20a0
testl %eax, %eax
je 0x391e
movq %rbp, %rdi
leaq 0x2e43(%rip), %rsi      # 0x666f
callq 0x20a0
testl %eax, %eax
je 0x3980
movq %rbp, %rdi
leaq 0x2e36(%rip), %rsi      # 0x6679
callq 0x20a0
testl %eax, %eax
je 0x3994
movq %rbp, %rdi
leaq 0x2e29(%rip), %rsi      # 0x6683
callq 0x20a0
testl %eax, %eax
je 0x39a8
movq 0x110(%rsp), %rax
cmpb $0x2d, (%rax)
je 0x4753
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x49de
jmp 0x3959
movq 0x8(%r12,%r15,8), %rsi
movq %r14, %rdi
leaq 0xe0(%rsp), %rdx
callq 0x20c0
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x49de
jmp 0x3943
movq 0x8(%r12,%r15,8), %rsi
movq %r14, %rdi
leaq 0xe0(%rsp), %rdx
callq 0x20c0
movq %r14, %rdi
leaq 0x29d7(%rip), %rsi      # 0x62aa
callq 0x20a0
testl %eax, %eax
movq 0x28(%rsp), %r15
cmovel %eax, %r15d
movq %r14, %rdi
leaq 0x2d60(%rip), %rsi      # 0x664d
callq 0x20a0
testl %eax, %eax
movl $0x1, %eax
cmovel %eax, %r15d
movq %r14, %rdi
leaq 0x2d51(%rip), %rsi      # 0x6658
callq 0x20a0
testl %eax, %eax
movl $0x2, %eax
cmovel %eax, %r15d
movq %r15, 0x28(%rsp)
jmp 0x3943
movq 0x8(%r12,%r15,8), %rsi
movq %r14, %rdi
leaq 0xe0(%rsp), %rdx
callq 0x20c0
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
callq 0x2110
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3957
callq 0x21b0
incl %ebx
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x3973
callq 0x21b0
incl %ebx
cmpl %r13d, %ebx
jl 0x37cb
jmp 0x39d1
leal 0x1(%r15), %ebx
movq 0x8(%r12,%r15,8), %rdi
callq 0x22b0
movl %eax, 0xc(%rsp)
jmp 0x3959
leal 0x1(%r15), %ebx
movq 0x8(%r12,%r15,8), %rdi
callq 0x22b0
movl %eax, 0x10(%rsp)
jmp 0x3959
leal 0x1(%r15), %ebx
movq 0x8(%r12,%r15,8), %rdi
callq 0x22b0
movl %eax, 0x20(%rsp)
jmp 0x3959
movl $0x989680, %ebp         # imm = 0x989680
movl $0xff676980, %r15d      # imm = 0xFF676980
movl $0xa, 0xc(%rsp)
jmp 0x39f0
movq 0x80(%rsp), %rax
cmpq 0x88(%rsp), %rax
movl 0x20(%rsp), %ebp
movl 0x10(%rsp), %r15d
jne 0x3a83
leaq 0x120(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x2c9c(%rip), %rsi      # 0x669f
leaq 0x2c98(%rip), %rdx      # 0x66a2
leaq 0x110(%rsp), %rdi
callq 0x4c2c
leaq 0x80(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x4ff8
movq 0x110(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3a3e
callq 0x21b0
leaq 0x110(%rsp), %rdi
movq %rbx, (%rdi)
leaq 0x2831(%rip), %rsi      # 0x6281
leaq 0x282c(%rip), %rdx      # 0x6283
callq 0x4c2c
leaq 0x80(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x4ff8
movq 0x110(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3a83
callq 0x21b0
callq 0x2140
movq %rax, %r14
callq 0x36e1
movsd %xmm0, 0x108(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movq 0x5517(%rip), %rbx      # 0x8fd0
leaq 0x2be3(%rip), %rsi      # 0x66a3
movl $0x11, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x54e5(%rip), %rdi      # 0x8fd0
callq 0x2040
movq %rax, %rdi
callq 0x2150
leaq 0x30(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0xa0(%rsp), %r8
movl %r15d, %edx
movl %ebp, %ecx
callq 0x2864
movq 0x54b2(%rip), %rbx      # 0x8fd0
leaq 0x2b90(%rip), %rsi      # 0x66b5
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x5480(%rip), %rdi      # 0x8fd0
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq %r14, 0x100(%rsp)
movq 0xa8(%rsp), %rbx
subq 0xa0(%rsp), %rbx
shrq $0x3, %rbx
leaq 0x70(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x24fc
movq %rbx, 0x18(%rsp)
testl %ebx, %ebx
jle 0x3c0a
movq 0x18(%rsp), %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
movl $0x1, %r15d
xorl %ebp, %ebp
leaq 0x70(%rsp), %rbx
movq %rbp, %r12
incq %rbp
cmpq %r14, %rbp
jae 0x3c02
movq %r15, %r13
movq 0xa0(%rsp), %rax
movq (%rax,%r12,8), %rdi
movq (%rax,%r13,8), %rsi
callq 0x2706
movq %rbx, %rdi
movl %r12d, %esi
movl %r13d, %edx
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x2666
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x2666
incq %r13
cmpq %r13, %r14
jne 0x3bb7
incq %r15
cmpq %r14, %rbp
jne 0x3ba9
cmpq $0x0, 0xc8(%rsp)
jne 0x4405
movq 0x18(%rsp), %r15
cmpl %r15d, 0xc(%rsp)
jg 0x46e8
movq 0x53a0(%rip), %rbx      # 0x8fd0
leaq 0x2ad7(%rip), %rsi      # 0x670e
movl $0xa, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x536e(%rip), %rdi      # 0x8fd0
callq 0x2040
movq %rax, %rdi
callq 0x2150
xorpd %xmm0, %xmm0
movapd %xmm0, 0x110(%rsp)
movq $0x0, 0x120(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x3d13
xorl %r14d, %r14d
leaq 0x110(%rsp), %rbx
leaq 0x48(%rsp), %r12
callq 0x2080
cltd
idivl %r15d
movl %edx, 0x48(%rsp)
movq 0x110(%rsp), %rax
movq 0x118(%rsp), %rsi
movq %rsi, %rcx
subq %rax, %rcx
je 0x3ce4
sarq $0x2, %rcx
movl $0x1, %edi
xorl %r8d, %r8d
cmpl %edx, (%rax,%r8,4)
je 0x3ca3
movl %edi, %r8d
incl %edi
cmpq %r8, %rcx
ja 0x3cd4
cmpq 0x120(%rsp), %rsi
je 0x3cfe
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x118(%rsp)
jmp 0x3d09
movq %rbx, %rdi
movq %r12, %rdx
callq 0x51fa
incl %r14d
cmpl 0xc(%rsp), %r14d
jne 0x3ca3
leaq 0x110(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq 0x368f
movsd %xmm0, 0x68(%rsp)
ucomisd 0x2388(%rip), %xmm0     # 0x60c0
movl 0xc(%rsp), %eax
movq %rax, 0x98(%rsp)
jne 0x3d4c
jnp 0x3e93
leaq 0x110(%rsp), %r13
leaq 0x70(%rsp), %rbp
movq 0x5270(%rip), %r12      # 0x8fd0
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x3e75
movq 0x110(%rsp), %rax
xorl %ebx, %ebx
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl (%rax,%rbx,4), %r15d
xorl %r14d, %r14d
movq 0x110(%rsp), %rax
movq 0x118(%rsp), %rcx
subq %rax, %rcx
je 0x3dc7
sarq $0x2, %rcx
movl $0x1, %edx
xorl %esi, %esi
cmpl %r14d, (%rax,%rsi,4)
je 0x3e4a
movl %edx, %esi
incl %edx
cmpq %rsi, %rcx
ja 0x3db4
movl %r14d, (%rax,%rbx,4)
movq %r13, %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rdx
callq 0x368f
movsd %xmm0, 0x10(%rsp)
movsd 0x20(%rsp), %xmm0
ucomisd 0x10(%rsp), %xmm0
jbe 0x3e4a
movl $0xf, %edx
movq %r12, %rdi
leaq 0x291b(%rip), %rsi      # 0x6719
callq 0x2210
movq %r12, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x22c0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl %r14d, %r15d
incl %r14d
cmpl 0x18(%rsp), %r14d
jne 0x3d94
movq 0x110(%rsp), %rax
movl %r15d, (%rax,%rbx,4)
incq %rbx
cmpq 0x98(%rsp), %rbx
jne 0x3d8d
movsd 0x20(%rsp), %xmm0
ucomisd 0x68(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
jne 0x3d6c
jp 0x3d6c
movq 0x110(%rsp), %rbx
movq 0x118(%rsp), %r14
cmpq %r14, %rbx
je 0x3ed5
movq %r14, %rax
subq %rbx, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x532d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5410
callq 0x2140
movq %rax, %rbx
callq 0x36e1
movsd %xmm0, 0x10(%rsp)
movq 0x50e1(%rip), %rdi      # 0x8fd0
leaq 0x2833(%rip), %rsi      # 0x6729
movl $0xb, %edx
callq 0x2210
cvtsi2sdq 0x100(%rsp), %xmm1
divsd 0x21a6(%rip), %xmm1     # 0x60b8
xorps %xmm0, %xmm0
cvtsi2sd %rbx, %xmm0
divsd 0x2196(%rip), %xmm0     # 0x60b8
subsd %xmm1, %xmm0
movq 0x50a3(%rip), %rdi      # 0x8fd0
callq 0x22c0
movq %rax, %rbx
leaq 0x27f9(%rip), %rsi      # 0x6735
movl $0x8, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x5059(%rip), %rdi      # 0x8fd0
leaq 0x27c0(%rip), %rsi      # 0x673e
movl $0xb, %edx
callq 0x2210
movsd 0x10(%rsp), %xmm0
subsd 0x108(%rsp), %xmm0
movq 0x5032(%rip), %rdi      # 0x8fd0
callq 0x22c0
movq %rax, %rbx
leaq 0x2788(%rip), %rsi      # 0x6735
movl $0x8, %edx
movq %rax, %rdi
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x4fe8(%rip), %rbx      # 0x8fd0
leaq 0x275b(%rip), %rsi      # 0x674a
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x4fb6(%rip), %rdi      # 0x8fd0
callq 0x2040
movq %rax, %rdi
callq 0x2150
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x4143
xorl %r13d, %r13d
leaq 0x26f2(%rip), %r14      # 0x6733
leaq 0x70(%rsp), %r15
xorl %r12d, %r12d
movq 0x110(%rsp), %rcx
cmpq %rcx, 0x118(%rsp)
je 0x40be
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0x1, %ebx
xorl %eax, %eax
movsd 0x2039(%rip), %xmm0     # 0x60a8
movsd %xmm0, 0x10(%rsp)
movl (%rcx,%rax,4), %esi
movq %r15, %rdi
movl %r12d, %edx
callq 0x25c6
leal -0x1(%rbx), %eax
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
minsd %xmm1, %xmm0
cmoval %eax, %ebp
movl %ebx, %eax
movq 0x110(%rsp), %rcx
movq 0x118(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
incl %ebx
cmpq %rax, %rdx
ja 0x406f
movq 0x30(%rsp), %rax
jmp 0x40c3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq 0x4ef9(%rip), %rdi      # 0x8fd0
callq 0x2210
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movq %r13, %rdi
movl %ebp, %esi
callq 0x2310
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
incl %r12d
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq %r12, %r13
cmpq %r12, %rcx
ja 0x4049
movq 0x4e86(%rip), %rbx      # 0x8fd0
leaq 0x2603(%rip), %rsi      # 0x6754
movl $0x8, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x4e54(%rip), %rdi      # 0x8fd0
callq 0x2040
movq %rax, %rdi
callq 0x2150
cmpl $0x0, 0xc(%rsp)
jle 0x41f7
xorl %r15d, %r15d
movq 0x4e36(%rip), %rbx      # 0x8fd0
movq 0x110(%rsp), %rax
movslq (%rax,%r15,4), %rax
movq 0x30(%rsp), %rcx
shlq $0x5, %rax
movq (%rcx,%rax), %rsi
movq 0x8(%rcx,%rax), %rdx
movq %rbx, %rdi
callq 0x2210
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2150
incq %r15
cmpq %r15, 0x98(%rsp)
jne 0x419a
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x4209
callq 0x21b0
leaq 0x70(%rsp), %rdi
callq 0x25b0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x4225
callq 0x21b0
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x423f
callq 0x21b0
leaq 0x30(%rsp), %rdi
callq 0x4a1c
leaq 0x80(%rsp), %rdi
callq 0x4a1c
xorl %eax, %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4d5f(%rip), %rbx      # 0x8fd0
leaq 0x1e6f(%rip), %rsi      # 0x60e7
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq (%r12), %rsi
movq %rax, %rdi
callq 0x21d0
leaq 0x1e54(%rip), %rsi      # 0x60ef
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x1edb(%rip), %rsi      # 0x618d
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq (%r12), %rsi
movq %rax, %rdi
callq 0x21d0
leaq 0x1ebd(%rip), %rsi      # 0x6192
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x1eea(%rip), %rsi      # 0x61d6
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x21d0
leaq 0x1eee(%rip), %rsi      # 0x61fd
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
leaq 0x1f2f(%rip), %rsi      # 0x625d
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x1f3f(%rip), %rsi      # 0x6284
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x1f56(%rip), %rsi      # 0x62b2
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x1f62(%rip), %rsi      # 0x62d5
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x1f75(%rip), %rsi      # 0x62ff
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
leaq 0x1f7e(%rip), %rsi      # 0x6327
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x201c(%rip), %rsi      # 0x63dc
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x20cd(%rip), %rsi      # 0x64a4
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
leaq 0x215f(%rip), %rsi      # 0x654d
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
xorl %edi, %edi
callq 0x2230
movq 0x4bc4(%rip), %rdi      # 0x8fd0
leaq 0x22b1(%rip), %rsi      # 0x66c4
movl $0x15, %edx
callq 0x2210
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
movq 0x4b9c(%rip), %rdi      # 0x8fd0
callq 0x2210
movq %rax, %rdi
callq 0x20f0
movq 0x30(%rsp), %rdi
movb $0x1, %r14b
cmpq %rdi, 0x38(%rsp)
je 0x44ce
movl $0x1, %ebp
xorl %r12d, %r12d
leaq 0x227b(%rip), %rbx      # 0x66da
leaq 0x227c(%rip), %r15      # 0x66e2
shlq $0x5, %r12
addq %r12, %rdi
movl $0x7, %ecx
movq %rbx, %rsi
xorl %edx, %edx
callq 0x2320
movq %rax, %r13
addq 0x30(%rsp), %r12
movl $0x4, %ecx
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x2320
cmpq $-0x1, %r13
setne %cl
cmpq $-0x1, %rax
setne %dl
andb %cl, %dl
cmpq %r13, %rax
setae %r14b
andb %dl, %r14b
je 0x44ce
movl %ebp, %r12d
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
incl %ebp
cmpq %r12, %rax
ja 0x4466
leaq 0x110(%rsp), %rdi
callq 0x2300
leaq 0x110(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
movl $0x10, %edx
callq 0x20e0
testb %r14b, %r14b
je 0x4799
cmpl $0x0, 0x18(%rsp)
jle 0x4899
movq 0x18(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movl $0x20, %eax
movq %rax, 0x28(%rsp)
xorl %ebp, %ebp
leaq 0x21fe(%rip), %r12      # 0x6733
movq %rbp, %r13
shlq $0x5, %r13
movq 0x30(%rsp), %rdi
addq %r13, %rdi
movl $0x7, %ecx
leaq 0x218a(%rip), %rsi      # 0x66da
xorl %edx, %edx
callq 0x2320
movq %rax, %rbx
movq 0x30(%rsp), %rdi
addq %r13, %rdi
movl $0x4, %ecx
leaq 0x2174(%rip), %rsi      # 0x66e2
movq %rax, %rdx
callq 0x2320
addq 0x30(%rsp), %r13
subq %rbx, %rax
addq $0x7, %rbx
leaq -0x7(%rax), %rcx
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2200
leaq 0x1(%rbp), %rax
movq %rax, 0x10(%rsp)
cmpq 0x18(%rsp), %rax
leaq 0xf0(%rsp), %r14
jae 0x46b1
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x30(%rsp), %rdi
addq %r15, %rdi
movl $0x7, %ecx
leaq 0x210a(%rip), %rsi      # 0x66da
xorl %edx, %edx
callq 0x2320
movq %rax, %rbx
movq 0x30(%rsp), %rdi
addq %r15, %rdi
movl $0x4, %ecx
leaq 0x20f4(%rip), %rsi      # 0x66e2
movq %rax, %rdx
callq 0x2320
movq 0x30(%rsp), %rsi
addq %r15, %rsi
subq %rbx, %rax
addq $0x7, %rbx
leaq -0x7(%rax), %rcx
leaq 0xe0(%rsp), %rdi
movq %rbx, %rdx
callq 0x2200
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0x110(%rsp), %rdi
callq 0x2210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2210
leaq 0x70(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x25c6
movq %rbx, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20f0
movq 0xe0(%rsp), %rdi
cmpq %r14, %rdi
je 0x469f
callq 0x21b0
incq %r13
addq $0x20, %r15
cmpq %r13, 0x18(%rsp)
jne 0x45bc
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x46c5
callq 0x21b0
incq 0x20(%rsp)
addq $0x20, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq %rax, %rbp
cmpq 0x18(%rsp), %rax
jne 0x4535
jmp 0x4899
movq 0x4901(%rip), %rdi      # 0x8ff0
leaq 0x1ff1(%rip), %rsi      # 0x66e7
movl $0xc, %edx
callq 0x2210
movq 0x48e9(%rip), %rdi      # 0x8ff0
movl 0xc(%rsp), %esi
callq 0x2310
movq %rax, %rbx
leaq 0x1fda(%rip), %rsi      # 0x66f4
movl $0xd, %edx
movq %rax, %rdi
callq 0x2210
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2310
movq %rax, %rbx
leaq 0x1fc6(%rip), %rsi      # 0x6702
movl $0xb, %edx
movq %rax, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x20f0
jmp 0x478f
movq 0x4896(%rip), %rdi      # 0x8ff0
leaq 0x1f2b(%rip), %rsi      # 0x668c
movl $0x12, %edx
callq 0x2210
movq 0x110(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x486e(%rip), %rdi      # 0x8ff0
callq 0x2210
movq %rax, %rdi
callq 0x20f0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2230
cmpl $0x0, 0x18(%rsp)
jle 0x4899
movq 0x18(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movl $0x28, %eax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
leaq 0x1f62(%rip), %r15      # 0x6733
leaq 0x1(%r13), %rax
movq %rax, 0x10(%rsp)
cmpq 0x18(%rsp), %rax
jae 0x487e
movq %r13, %r14
shlq $0x5, %r14
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %rbp
movq 0x30(%rsp), %rax
movq (%rax,%r14), %rsi
movq 0x8(%rax,%r14), %rdx
leaq 0x110(%rsp), %rdi
callq 0x2210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2210
movq 0x30(%rsp), %rax
movq -0x8(%rax,%r12), %rsi
movq (%rax,%r12), %rdx
movq %rbx, %rdi
callq 0x2210
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x2210
leaq 0x70(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x25c6
movq %rbx, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20f0
incq %rbp
addq $0x20, %r12
cmpq %rbp, 0x18(%rsp)
jne 0x47f6
incq 0x20(%rsp)
addq $0x20, 0x28(%rsp)
movq 0x10(%rsp), %r13
cmpq 0x18(%rsp), %r13
jne 0x47d1
leaq 0x110(%rsp), %rdi
callq 0x2270
jmp 0x43fe
jmp 0x48e2
movq %rax, %r14
jmp 0x48ca
movq %r14, %rcx
movq %rax, %r14
movq 0xe0(%rsp), %rdi
cmpq %rcx, %rdi
je 0x48ca
callq 0x21b0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x48e5
callq 0x21b0
jmp 0x48e5
jmp 0x48e2
movq %rax, %r14
leaq 0x110(%rsp), %rdi
callq 0x2290
jmp 0x4989
jmp 0x496f
jmp 0x48fd
jmp 0x4962
movq %rax, %r14
movq 0x110(%rsp), %rdi
cmpq %rbx, %rdi
jne 0x49a0
jmp 0x49a5
jmp 0x4962
jmp 0x4928
jmp 0x4928
jmp 0x495d
jmp 0x4974
jmp 0x492d
jmp 0x4928
jmp 0x4928
jmp 0x496f
movq %rax, %r14
jmp 0x4944
movq %rax, %r14
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x4944
callq 0x21b0
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
jne 0x49a0
jmp 0x49a5
jmp 0x4974
movq %rax, %r14
jmp 0x4993
movq %rax, %r14
jmp 0x49a5
jmp 0x4974
jmp 0x4974
jmp 0x4974
jmp 0x4974
movq %rax, %r14
jmp 0x4989
movq %rax, %r14
movq 0x110(%rsp), %rdi
testq %rdi, %rdi
je 0x4989
callq 0x21b0
leaq 0x70(%rsp), %rdi
callq 0x25b0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x49a5
callq 0x21b0
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x49bf
callq 0x21b0
leaq 0x30(%rsp), %rdi
callq 0x4a1c
leaq 0x80(%rsp), %rdi
callq 0x4a1c
movq %r14, %rdi
callq 0x2330