// File: /workspace/github_cpp_makefile_star2_O1/CominLab[P]QCluster/qcluster.cc
// Function: main
int main(int argc, char **argv)
{
	int num_clusters = 5;  // target number of clusters
	char dist_type = 'e'; // default to L2
	int K = 2;  // k-mer size
	bool normalize_matrix_flag = false; // make columns univariant ("whiten");
		// off by default
	int normalize = 2; // normalize each row. Deafult: method 2
	bool redistribute = true; //Redistribute missing quality by default
	int e_method = 1;
	int p_method = 1;
	double pseudocount = PC; // pseudocount for k-mers
	bool rc_flag = false; // append reverse complement to each sequence;
		// off by default
	unsigned int random_seed = time(NULL); // initial seed
	int num_trials = 0; // later we check if it was specified using "-t" arg
		// and set the correct default if it was not; note that the default 
		// depends on whether consensus clustering is performed
	int verbose_level = 0;
	bool write_flag = false; // write sequences by cluster; off by default
	int default_max_iterations = 1000;

	int opt;
	while((opt = getopt(argc, argv, "c:d:e:k:m:N:nP:p:q:rRsS:t:vwh")) != -1 ){
		switch(opt){
            case 'c':
                num_clusters = atoi(optarg);
                break;
			case 'd':
                dist_type = *optarg;
                break;
			case 'e':
				e_method = atoi(optarg);
				break;
            case 'k':
                K = atoi(optarg);
                break;
			case 'm':
				max_iterations = atoi(optarg);
				//If max_iterations < 2 the default value will be restored
				if (max_iterations<2) max_iterations = default_max_iterations;
				break;
			case 'N':
				normalize = atoi(optarg);
				break;
            case 'n':
                normalize_matrix_flag = true;
                break;
			case 'P':
				p_method = atoi(optarg);
				if (p_method<1 || p_method>3) p_method = 2;
				break;				
			case 'p':
				pseudocount = atof(optarg);
				break;
			case 'R':
				//Do not redistribute quality
				redistribute = false;
				break;
            case 'r':
                rc_flag = true;
                break;
			case 'S':
				random_seed = atoi(optarg);
				break;
            case 't':
                num_trials = atoi(optarg);
                break;
            case 'v':
                ++verbose_level;
                break;
            case 'w':
                write_flag = true;
                break;
            case 'h':
				print_usage(argv[0]);
				return EXIT_SUCCESS;
            case '?':
                print_usage(argv[0]);
                return EXIT_FAILURE;
            default:
                // You won't actually get here
                break;
        }
	}

	if (dist_type != 'a'){
		p_method = 0;//No calculation of expected freq and expected quality
		e_method = 0;
	}

	// if "-t" argument was absent, use the appropriate default
	if (!num_trials) {
		num_trials = 1;
	}

	if(argc != optind + 1){
		cout<<"Missing/extra input file name"<<endl;
		print_usage(argv[0]);
		return EXIT_FAILURE;
	}
	char* fastq_file_name = *(argv + optind );

	// initialize random number generator
	srand(random_seed);

	// initialize constants
	int L = 1; // length of the freq. vector L = NUM_NT**K
	for(int k=0; k<K; ++k){
		L *= NUM_NT;
	}

	// count sequences
	int N = CountReads(fastq_file_name);  // number of sequences
	if (verbose_level>0){
		cerr<<"Found "<<N<<" sequences\n";
	}

	// read sequences and build count matrix
	RecordGenerator rec_gen(fastq_file_name);
	double **freq = new double*[N];
	freq[0] = new double[N * L];
	double **quality = new double*[N];
	for (int i=0; i<N; i++) quality[i] = new double[L];
	
	double **freq_1  = new double*[N];
	freq_1[0] = new double[N * NUM_NT];
	double **quality_1 = new double*[N];
	for (int i=0; i<N; i++) quality_1[i] = new double[NUM_NT];
	
	//Vector for calculus of E(Pxi)2
	double *avg_quality_1 = new double[NUM_NT];
	for(int i=0; i<NUM_NT; i++) avg_quality_1[i] = 0;
	
	//Vector for calculus of E(Pxi)3
	double **avg_quality = new double*[L];
	for (int i=0; i<L; i++) {
		avg_quality[i] = new double[NUM_NT];
		for (int j=0; j<NUM_NT; j++) avg_quality[i][j] = 0;
	}
	
	//For each read we count the number of kmers
	for(int i=0; i<N; ++i){
		SeqRecord rec = rec_gen.next();
		string seq = rc_flag ? rec.seq() + rec.rc().seq() : rec.seq();
		freq[i] = freq[0] + i*L;

		//Calculate frequencies of individual bases
		freq_1[i] = freq_1[0] + i*NUM_NT;
		fill_overlap_count_vector(seq, rec.qual(), 1, freq_1[i], 
								  quality_1[i], false, pseudocount, 
								  avg_quality_1, NULL, NULL, false);
		
		//Calculate frequencies of kmers
		fill_overlap_count_vector(seq, rec.qual(), K, freq[i], quality[i],
								normalize, pseudocount, NULL, avg_quality, 
								freq_1[i], redistribute);
	}
	
	if (verbose_level>0){
		cerr<<"Read counts calculated\n";
	}

	
	//Compute the expected quality of each kmer
	double *expected_qual = NULL;
	if (e_method != 0) {
		expected_qual = new double[L];
		calculate_quality_expected_value(e_method, N, K, L, freq, quality,
						freq_1, avg_quality_1, avg_quality, expected_qual);
	}
	
	//Expected frequancy of each kmer
	double *expected_freq = NULL;
	//Instantiate the vector only if p_method is global (P1G or P2G)
	if (p_method==2 || p_method==3) expected_freq = new double[L];
	
	//P1G Average frequency of every word over the entire dataset
	if (p_method==2)
		expected_frequency_p1global(N, K, L, expected_freq, freq);
	
	//P2G Markovian model based on average frequency of single bases
	if (p_method==3)
		expected_frequency_p2global(N, K, L, expected_freq, freq_1);
	

	
	
	// whiten if requested; in this case reset the distance to euclidean L2
	if (normalize_matrix_flag){
		dist_type = 'e';
		normalize_freq_matrix(freq, quality, N, L);
	}
	if (verbose_level > 0){
		cerr<<"Word frequencies calculated\n";
	}


	// hard EM clustering
	int* assignment = new int[N];
	double* Z = new double[num_clusters * N];
		if (verbose_level > 0) {
			cerr<<"Running regular EM clustering "<<num_trials<<" times "
			"to chose the best partitioning"<<endl;
		}
		num_clusters = hard_em(num_clusters, N, L, freq, quality, expected_qual, 
			quality_1, expected_freq, NUM_NT, freq_1, assignment, Z, num_trials, 
			dist_type, verbose_level);
		
	if (verbose_level > 0){
		cerr<<"Clustering done\n";
	}

	// release memory previously allocated for frequency data
	delete[] freq[0];
	delete[] freq;
	delete[] freq_1[0];
	delete[] freq_1;
	
	for(int i=0; i<N; i++) {
		delete[] quality[i];
		delete[] quality_1[i];
	}
	for(int i=0; i<L; i++)
		delete[] avg_quality[i];
	delete[] quality;
	delete[] quality_1;
	delete[] avg_quality_1;
	delete[] avg_quality;
	if (p_method==2 || p_method==3) delete [] expected_freq;
	if (e_method != 0) delete[] expected_qual;

	// reassign cluster names so that they are sorted 
	// in the descending order of the number of members
	int* num_members = new int[num_clusters];
	int* ix = new int[num_clusters];
	int* rix = new int[num_clusters];
	for (int i=0; i<num_clusters; ++i){
		*(num_members + i) = 0;
		*(ix + i) = i;
	}
	for (int i=0; i<N; ++i){
		num_members[assignment[i]]++;
	}
	for (int i=0; i<num_clusters; ++i){
		int max_pos = i;
		for (int j=i+1; j<num_clusters; ++j){
			if (num_members[ix[j]] > num_members[ix[max_pos]]) {
				max_pos = j;
			}
		}
		int tmp = ix[i];
		ix[i] = ix[max_pos];
		ix[max_pos] = tmp;
	}
	for (int i=0; i<num_clusters; ++i){
		rix[ix[i]] = i;
	}
	for (int i=0; i<N; ++i) {
		*(assignment + i) = *(rix + *(assignment + i));
	}
	delete[] num_members;
	//delete[] ix and rix later

	cout.setf(ios_base::fixed);
	cout.precision(4);

	// output assignment to stdout
	RecordGenerator rec_gen_2(fastq_file_name);
	for(int n=0; n<N; ++n){
		cout<<rec_gen_2.next().id()<<"\t"<<*(assignment+n);
		cout<<endl;
	}
	delete[] ix;
	delete[] rix;

	// write sequences to individual files if requested
	if (write_flag) {
		vector<SeqRecord> rec_vec;
		FastqRead(fastq_file_name, rec_vec);
		int N = rec_vec.size();
		char fname[256];
		for (int i=0; i<num_clusters; ++i){
			sprintf(fname, "part_%i.fastq", i+1);
			ofstream ofs(fname);
			for (int j=0; j<N; ++j) {
				if (*(assignment + j) == i) {
					ofs<<"@"<<rec_vec[j].desc()<<endl;
					ofs<<rec_vec[j].seq()<<endl;
					ofs<<"+"<<endl;
					ofs<<rec_vec[j].qual()<<endl;
				}
			}
		}
	}

	// free allocated memory
	delete[] Z;
	delete[] assignment;
	return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa78, %rsp            # imm = 0xA78
movq %rsi, %rbx
movl %edi, %ebp
movq $0x0, 0x138(%rsp)
xorl %edi, %edi
callq 0x21c0
movq %rax, 0x40(%rsp)
movl $0x5, 0x6c(%rsp)
movb $0x65, 0xb(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl $0x1, %eax
movq %rax, 0x48(%rsp)
movsd 0x5961(%rip), %xmm0     # 0x8008
movsd %xmm0, 0x60(%rsp)
leaq 0x6337(%rip), %r14      # 0x89eb
leaq 0x5965(%rip), %r12      # 0x8020
movq 0x98ee(%rip), %r15      # 0xbfb0
leaq 0x596f(%rip), %r13      # 0x8038
movl $0x0, %eax
movq %rax, 0x20(%rsp)
movl $0x0, %eax
movq %rax, 0xa0(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x1, 0x2c(%rsp)
movl $0x2, 0xb0(%rsp)
movq $0x0, 0x98(%rsp)
movl $0x2, 0x50(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2070
cmpl $0x62, %eax
jle 0x2742
addl $-0x63, %eax
cmpl $0x14, %eax
ja 0x2710
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0x6c(%rsp)
jmp 0x2710
leal -0x4e(%rax), %ecx
cmpl $0x5, %ecx
ja 0x2855
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0xb0(%rsp)
jmp 0x2710
movl $0x0, 0xc(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x22c0
movq %rax, 0x40(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x22c0
leal -0x4(%rax), %ecx
cmpl $-0x3, %ecx
movl $0x2, %ecx
cmovbl %ecx, %eax
movq %rax, 0x48(%rsp)
jmp 0x2710
movb $0x1, %al
movq %rax, 0x138(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0x50(%rsp)
jmp 0x2710
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0x2c(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x22c0
cmpl $0x2, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cmovll %ecx, %eax
leaq 0x99e3(%rip), %rcx      # 0xc1e0
movl %eax, (%rcx)
jmp 0x2710
movq (%r15), %rax
movb (%rax), %al
movb %al, 0xb(%rsp)
jmp 0x2710
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x2710
movb $0x1, %al
movq %rax, 0x98(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x2260
movsd %xmm0, 0x60(%rsp)
jmp 0x2710
movq (%r15), %rdi
callq 0x22c0
movq %rax, 0xa0(%rsp)
jmp 0x2710
cmpl $-0x1, %eax
je 0x2875
cmpl $0x3f, %eax
jne 0x2710
jmp 0x30b6
movq (%rbx), %rdi
callq 0x258c
jmp 0x39be
xorl %eax, %eax
cmpb $0x61, 0xb(%rsp)
movq 0x48(%rsp), %rcx
cmovnel %eax, %ecx
movq %rcx, 0x48(%rsp)
movl 0x2c(%rsp), %ecx
cmovnel %eax, %ecx
movl %ecx, 0x2c(%rsp)
movq 0xa0(%rsp), %rdx
cmpl $0x1, %edx
adcl $0x0, %edx
movq 0x9727(%rip), %rax      # 0xbfd0
movslq (%rax), %rax
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jne 0x3074
movq %rdx, 0xa0(%rsp)
movq (%rbx,%rax,8), %r15
movq 0x40(%rsp), %rdi
callq 0x21d0
movl 0x50(%rsp), %eax
movl $0x1, %ebx
testl %eax, %eax
jle 0x28e1
shll $0x2, %ebx
decl %eax
jne 0x28da
leaq 0x230(%rsp), %rdi
leaq 0x828(%rsp), %rdx
movq %r15, %rsi
callq 0x3d14
leaq 0x230(%rsp), %rdi
callq 0x72a7
movq %rax, 0x18(%rsp)
leaq 0x240(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x292c
movq 0x240(%rsp), %rsi
incq %rsi
callq 0x2200
cmpl $0x0, 0x20(%rsp)
jle 0x296f
movq 0x96b6(%rip), %r14      # 0xbff0
leaq 0x60e6(%rip), %rsi      # 0x8a27
movl $0x6, %edx
movq %r14, %rdi
callq 0x2240
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x2310
leaq 0x60cc(%rip), %rsi      # 0x8a2e
movl $0xb, %edx
movq %rax, %rdi
callq 0x2240
leaq 0x210(%rsp), %rdi
leaq 0x5d8(%rsp), %rdx
movq %r15, %rsi
callq 0x3d14
leaq 0x828(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x6ac2
movq %r15, 0x128(%rsp)
leaq 0x220(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29c5
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x18(%rsp), %r12
movslq %r12d, %rax
movq %rax, 0x1c0(%rsp)
leaq (,%rax,8), %r14
testl %r12d, %r12d
movq $-0x1, %r15
cmovsq %r15, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movl %r12d, %eax
imull %ebx, %eax
cltq
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r15, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x58(%rsp)
movl %ebx, %eax
movq %rax, 0xa8(%rsp)
movq 0x18(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0x40(%rsp)
testl %eax, %eax
jle 0x2a70
movq 0xa8(%rsp), %rax
leaq (,%rax,8), %r15
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x2030
movq 0x58(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
cmpq %r12, 0x40(%rsp)
jne 0x2a55
movq %r14, %rdi
callq 0x2030
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %rcx
leal (,%rcx,4), %eax
cltq
shlq $0x3, %rax
testl %ecx, %ecx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq 0x38(%rsp), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x2030
movq %rax, 0x90(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x2ae3
xorl %r14d, %r14d
movl $0x20, %edi
callq 0x2030
movq 0x90(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, 0x40(%rsp)
jne 0x2ac3
movl $0x20, %edi
callq 0x2030
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, 0xb8(%rsp)
movups %xmm0, (%rax)
movq 0xa8(%rsp), %rax
leaq (,%rax,8), %rdi
movq %rdi, 0x120(%rsp)
callq 0x2030
movq %rax, %r15
cmpl $0x1, %ebx
movl %ebx, %eax
adcl $0x0, %eax
movq %rax, 0x130(%rsp)
xorl %r14d, %r14d
movl $0x20, %edi
callq 0x2030
movq %rax, (%r15,%r14,8)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
incq %r14
cmpq %r14, 0x130(%rsp)
jne 0x2b32
cmpl $0x0, 0x18(%rsp)
jle 0x3008
shlq $0x3, 0xa8(%rsp)
movq 0x40(%rsp), %rax
shlq $0x5, %rax
movq %rax, 0x1c8(%rsp)
xorl %r13d, %r13d
leaq 0x5d8(%rsp), %rbp
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rbp, %rdi
leaq 0x828(%rsp), %rsi
callq 0x6bae
testb $0x1, 0x10(%rsp)
je 0x2c93
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x618(%rsp), %rsi
movq 0x620(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x3d94
leaq 0x558(%rsp), %rdi
leaq 0x5d8(%rsp), %rsi
callq 0x686c
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x598(%rsp), %rsi
movq 0x5a0(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x3d94
movq 0xe0(%rsp), %rcx
movl $0xf, %esi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rcx
je 0x2c3f
movq 0xf0(%rsp), %rsi
movq 0xe8(%rsp), %r8
movq 0xc8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x2c7c
movl $0xf, %esi
leaq 0xd0(%rsp), %rdi
cmpq %rdi, 0xc0(%rsp)
je 0x2c77
movq 0xd0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x2cc5
movq 0xc0(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x20d0
jmp 0x2cd6
leaq 0x260(%rsp), %rax
movq %rax, 0x250(%rsp)
movq 0x618(%rsp), %rsi
movq 0x620(%rsp), %rdx
addq %rsi, %rdx
leaq 0x250(%rsp), %rdi
callq 0x3d94
jmp 0x2d2d
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2230
leaq 0x260(%rsp), %rsi
movq %rsi, 0x250(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x2d07
movq %rdx, 0x250(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x260(%rsp)
jmp 0x2d0d
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x258(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
testb $0x1, 0x10(%rsp)
je 0x2d8b
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d59
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x558(%rsp), %rdi
callq 0x65d2
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x2d8b
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
addq %r12, %rax
movq %rax, (%rcx,%r13,4)
movq 0x38(%rsp), %rcx
movq (%rcx), %rax
addq %r14, %rax
movq %rax, (%rcx,%r13,4)
leaq 0x170(%rsp), %rax
movq %rax, 0x160(%rsp)
movq 0x250(%rsp), %rsi
movq 0x258(%rsp), %rdx
addq %rsi, %rdx
leaq 0x160(%rsp), %rdi
callq 0x3d94
movl %ebx, %ebp
movq %r15, %rbx
leaq 0x1b0(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movq 0x638(%rsp), %rsi
movq 0x640(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1a0(%rsp), %r15
movq %r15, %rdi
callq 0x3d94
movq 0x38(%rsp), %rax
movq (%rax,%r13,4), %rcx
movq 0x90(%rsp), %rax
movq (%rax,%r13,4), %r8
subq $0x20, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, (%rsp)
movl $0x0, 0x18(%rsp)
leaq 0x180(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %edx
xorl %r9d, %r9d
movsd 0x80(%rsp), %xmm0
callq 0x57a6
addq $0x20, %rsp
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
movq %rbx, %r15
je 0x2e93
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
movl %ebp, %ebx
je 0x2eba
movq 0x170(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x150(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x250(%rsp), %rsi
movq 0x258(%rsp), %rdx
addq %rsi, %rdx
leaq 0x140(%rsp), %rdi
callq 0x3d94
leaq 0x190(%rsp), %rax
movq %rax, 0x180(%rsp)
movq 0x638(%rsp), %rsi
movq 0x640(%rsp), %rdx
addq %rsi, %rdx
leaq 0x180(%rsp), %rbp
movq %rbp, %rdi
callq 0x3d94
movq 0x30(%rsp), %rax
movq (%rax,%r13,4), %rcx
movq 0x58(%rsp), %rax
movq (%rax,%r13,4), %r8
movzbl 0xc(%rsp), %eax
andl $0x1, %eax
leaq 0x140(%rsp), %rdi
movq %rbp, %rsi
movl 0x50(%rsp), %edx
movl 0xb0(%rsp), %r9d
movsd 0x60(%rsp), %xmm0
pushq %rax
movq 0x40(%rsp), %rax
pushq (%rax,%r13,4)
pushq %r15
pushq $0x0
callq 0x57a6
addq $0x20, %rsp
movq 0x180(%rsp), %rdi
leaq 0x190(%rsp), %rax
cmpq %rax, %rdi
je 0x2f90
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x2fb5
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x250(%rsp), %rdi
leaq 0x260(%rsp), %rax
cmpq %rax, %rdi
je 0x2fda
movq 0x260(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x5d8(%rsp), %rbp
movq %rbp, %rdi
callq 0x65d2
addq $0x20, %r14
addq 0xa8(%rsp), %r12
addq $0x2, %r13
cmpq %r14, 0x1c8(%rsp)
jne 0x2b8d
cmpl $0x0, 0x20(%rsp)
jle 0x3027
movq 0x8fda(%rip), %rdi      # 0xbff0
leaq 0x5a1d(%rip), %rsi      # 0x8a3a
movl $0x17, %edx
callq 0x2240
cmpl $0x0, 0x2c(%rsp)
je 0x30c8
movq 0x120(%rsp), %rdi
callq 0x2030
movq %rax, %r13
movl 0x2c(%rsp), %edi
movq 0x18(%rsp), %rsi
movl 0x50(%rsp), %edx
movl %ebx, %ecx
movq 0x30(%rsp), %r8
movq 0x58(%rsp), %r9
pushq %rax
pushq %r15
pushq 0xc8(%rsp)
pushq 0x50(%rsp)
callq 0x5e0e
addq $0x20, %rsp
jmp 0x30cb
movq 0x8f4d(%rip), %r14      # 0xbfc8
leaq 0x5987(%rip), %rsi      # 0x8a09
movl $0x1d, %edx
movq %r14, %rdi
callq 0x2240
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq (%rbx), %rdi
callq 0x258c
movl $0x1, %eax
jmp 0x39c0
xorl %r13d, %r13d
movq 0x48(%rsp), %rax
movl %eax, %ebp
andl $-0x2, %ebp
cmpl $0x2, %ebp
je 0x30df
xorl %r14d, %r14d
jmp 0x30ef
movq 0x120(%rsp), %rdi
callq 0x2030
movq %rax, %r14
cmpl $0x3, 0x48(%rsp)
je 0x311c
cmpl $0x2, 0x48(%rsp)
jne 0x3134
movq 0x18(%rsp), %rdi
movl 0x50(%rsp), %esi
movl %ebx, %edx
movq %r14, %rcx
movq 0x30(%rsp), %r8
callq 0x61cd
cmpl $0x3, 0x48(%rsp)
jne 0x3134
movq 0x18(%rsp), %rdi
movl 0x50(%rsp), %esi
movl %ebx, %edx
movq %r14, %rcx
movq 0x38(%rsp), %r8
callq 0x610c
testb $0x1, 0x98(%rsp)
je 0x3159
movb $0x65, 0xb(%rsp)
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
callq 0x6250
cmpl $0x0, 0x20(%rsp)
jle 0x3178
movq 0x8e89(%rip), %rdi      # 0xbff0
leaq 0x58e4(%rip), %rsi      # 0x8a52
movl $0x1c, %edx
callq 0x2240
movl %ebp, 0x60(%rsp)
movq %r13, %rbp
movq 0x1c0(%rsp), %rdi
shlq $0x2, %rdi
movq 0x18(%rsp), %r13
testl %r13d, %r13d
movq $-0x1, %r12
cmovsq %r12, %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movl %r13d, %eax
imull 0x6c(%rsp), %eax
cltq
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r12, %rdi
callq 0x2030
movq %rax, 0x98(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x323f
movq 0x8e15(%rip), %rdi      # 0xbff0
leaq 0x588d(%rip), %rsi      # 0x8a6f
movl $0x1e, %edx
callq 0x2240
movq 0x8dfd(%rip), %rdi      # 0xbff0
movq 0xa0(%rsp), %rsi
callq 0x2310
movq %rax, %r13
leaq 0x5884(%rip), %rsi      # 0x8a8e
movl $0x25, %edx
movq %rax, %rdi
callq 0x2240
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
subq $0x8, %rsp
movsbl 0x13(%rsp), %eax
movl 0x74(%rsp), %edi
movq 0x20(%rsp), %rsi
movl %ebx, %edx
movq 0x38(%rsp), %rcx
movq 0x60(%rsp), %r8
movq %rbp, %r9
pushq 0x28(%rsp)
pushq %rax
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq 0x38(%rsp)
pushq 0x68(%rsp)
pushq $0x4
pushq %r14
pushq 0xd8(%rsp)
callq 0x4046
addq $0x50, %rsp
movl %eax, 0xc(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x32b2
movq 0x8d4f(%rip), %rdi      # 0xbff0
leaq 0x580c(%rip), %rsi      # 0x8ab4
movl $0x10, %edx
callq 0x2240
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x32c4
callq 0x2270
movq 0x30(%rsp), %rdi
callq 0x2270
movq 0x38(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x32e0
callq 0x2270
movq 0x38(%rsp), %rdi
callq 0x2270
cmpl $0x0, 0x18(%rsp)
jle 0x3326
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x3306
callq 0x2270
movq 0x90(%rsp), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x331c
callq 0x2270
incq %rbx
cmpq %rbx, 0x40(%rsp)
jne 0x32f3
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
testq %rdi, %rdi
je 0x3336
callq 0x2270
incq %rbx
cmpq %rbx, 0x130(%rsp)
jne 0x3328
movq 0x58(%rsp), %rdi
callq 0x2270
movq 0x90(%rsp), %rdi
callq 0x2270
movq 0xb8(%rsp), %rdi
callq 0x2270
movq %r15, %rdi
callq 0x2270
cmpl $0x2, 0x60(%rsp)
jne 0x3383
testq %r14, %r14
je 0x3383
movq %r14, %rdi
callq 0x2270
cmpl $0x0, 0x2c(%rsp)
je 0x3397
testq %rbp, %rbp
je 0x3397
movq %rbp, %rdi
callq 0x2270
movslq 0xc(%rsp), %rax
leaq (,%rax,4), %rcx
testl %eax, %eax
movq $-0x1, %rbx
cmovnsq %rcx, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, %r12
movq %rbx, %rdi
callq 0x2030
movq %rax, %r15
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %r14d
testl %eax, %eax
jle 0x33ff
leaq (,%r14,4), %rdx
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2130
movl %ebx, (%r15,%rbx,4)
incq %rbx
cmpq %rbx, %r14
jne 0x33f3
cmpl $0x0, 0x18(%rsp)
movq 0x40(%rsp), %r11
movq 0x10(%rsp), %rdx
jle 0x3422
xorl %eax, %eax
movslq (%rdx,%rax,4), %rcx
incl (%r12,%rcx,4)
incq %rax
cmpq %rax, %r11
jne 0x3412
cmpl $0x0, 0xc(%rsp)
jle 0x3484
movl $0x1, %eax
xorl %ecx, %ecx
leaq 0x1(%rcx), %rdx
movl %ecx, %edi
cmpq %r14, %rdx
jae 0x3466
movq %rax, %rsi
movl %ecx, %r8d
movslq (%r15,%rsi,4), %rdi
movl (%r12,%rdi,4), %r9d
movslq %r8d, %rdi
movslq (%r15,%rdi,4), %r10
movl %esi, %edi
cmpl (%r12,%r10,4), %r9d
jg 0x345b
movl %r8d, %edi
incq %rsi
movl %edi, %r8d
cmpq %rsi, %r14
jne 0x3441
movl (%r15,%rcx,4), %esi
movslq %edi, %rdi
movl (%r15,%rdi,4), %r8d
movl %r8d, (%r15,%rcx,4)
movl %esi, (%r15,%rdi,4)
incq %rax
movq %rdx, %rcx
cmpq %r14, %rdx
jne 0x3430
cmpl $0x0, 0xc(%rsp)
movq 0x20(%rsp), %rsi
jle 0x34a1
xorl %eax, %eax
movslq (%r15,%rax,4), %rcx
movl %eax, (%rsi,%rcx,4)
incq %rax
cmpq %rax, %r14
jne 0x3492
cmpl $0x0, 0x18(%rsp)
movq 0x10(%rsp), %rdx
jle 0x34c1
xorl %eax, %eax
movslq (%rdx,%rax,4), %rcx
movl (%rsi,%rcx,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
cmpq %rax, %r11
jne 0x34af
movq %r12, %rdi
callq 0x2270
movq 0x8af8(%rip), %r12      # 0xbfc8
movq (%r12), %rax
movq -0x18(%rax), %rcx
orl $0x4, 0x18(%r12,%rcx)
movq -0x18(%rax), %rax
movq $0x4, 0x8(%r12,%rax)
leaq 0x1f0(%rsp), %rdi
leaq 0x250(%rsp), %rdx
movq 0x128(%rsp), %rsi
callq 0x3d14
leaq 0x5d8(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x6ac2
leaq 0x200(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x353e
movq 0x200(%rsp), %rsi
incq %rsi
callq 0x2200
cmpl $0x0, 0x18(%rsp)
jle 0x362d
leaq 0x460(%rsp), %r14
xorl %ebx, %ebx
leaq 0x250(%rsp), %r13
movq %r13, %rdi
leaq 0x5d8(%rsp), %rsi
callq 0x6bae
movq %r14, 0x450(%rsp)
movq 0x250(%rsp), %rsi
movq 0x258(%rsp), %rdx
addq %rsi, %rdx
leaq 0x450(%rsp), %rdi
callq 0x3d94
movq 0x450(%rsp), %rsi
movq 0x458(%rsp), %rdx
movq %r12, %rdi
callq 0x2240
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x5508(%rip), %rsi      # 0x8ac5
callq 0x2240
movq 0x10(%rsp), %rax
movl (%rax,%rbx,4), %esi
movq %rbp, %rdi
callq 0x2310
movq 0x450(%rsp), %rdi
cmpq %r14, %rdi
je 0x35ef
movq 0x460(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r13, %rdi
callq 0x65d2
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
incq %rbx
cmpq %rbx, 0x40(%rsp)
jne 0x355b
movq %r15, %rdi
callq 0x2270
movq 0x20(%rsp), %rdi
callq 0x2270
testb $0x1, 0x138(%rsp)
je 0x398d
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movq $0x0, 0x110(%rsp)
leaq 0x1d0(%rsp), %rdi
leaq 0x250(%rsp), %r15
movq 0x128(%rsp), %rsi
movq %r15, %rdx
callq 0x3d14
leaq 0x1d0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x7166
leaq 0x1e0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x36ba
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x2200
cmpl $0x0, 0xc(%rsp)
jle 0x3980
movq 0x108(%rsp), %rcx
subq 0x100(%rsp), %rcx
shrq $0x7, %rcx
leaq 0x80(%rsp), %rbx
movq 0x88d8(%rip), %rax      # 0xbfc0
movq (%rax), %rdx
movq %rdx, 0x50(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
movq %rcx, 0xb0(%rsp)
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, 0x20(%rsp)
xorl %r14d, %r14d
leal 0x1(%r14), %edx
leaq 0x450(%rsp), %r12
movq %r12, %rdi
leaq 0x53a2(%rip), %rsi      # 0x8ac7
movl %edx, 0x60(%rsp)
xorl %eax, %eax
callq 0x2060
movq %r15, %rdi
movq %r12, %rsi
movl $0x10, %edx
callq 0x2220
cmpl $0x0, 0xb0(%rsp)
jle 0x3937
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
cmpl %r14d, (%rax,%r12,4)
jne 0x3925
movl $0x1, %edx
movq %r15, %rdi
leaq 0x5363(%rip), %rsi      # 0x8ad5
callq 0x2240
movq 0x100(%rsp), %rax
movq %rbx, 0x70(%rsp)
movq 0x20(%rax,%r13), %rsi
movq 0x28(%rax,%r13), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x3d94
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq %r15, %rdi
callq 0x2240
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x37f1
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x100(%rsp), %rax
movq %rbx, 0x70(%rsp)
movq 0x40(%rax,%r13), %rsi
movq 0x48(%rax,%r13), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x3d94
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq %r15, %rdi
callq 0x2240
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x386b
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movl $0x1, %edx
movq %r15, %rdi
leaq 0x525d(%rip), %rsi      # 0x8ad7
callq 0x2240
movq 0x250(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x100(%rsp), %rax
movq %rbx, 0x70(%rsp)
movq 0x60(%rax,%r13), %rsi
movq 0x68(%rax,%r13), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x3d94
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq %r15, %rdi
callq 0x2240
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbp, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3925
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
incq %r12
subq $-0x80, %r13
cmpq %r12, 0x20(%rsp)
jne 0x3754
movq 0x50(%rsp), %rax
movq %rax, 0x250(%rsp)
movq -0x18(%rax), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x250(%rsp,%rax)
leaq 0x258(%rsp), %rdi
callq 0x21a0
leaq 0x348(%rsp), %rdi
callq 0x20e0
movl 0x60(%rsp), %eax
movl %eax, %r14d
cmpl 0xc(%rsp), %eax
jne 0x370f
leaq 0x100(%rsp), %rdi
callq 0x3d52
movq 0x98(%rsp), %rdi
callq 0x2270
movq 0x10(%rsp), %rdi
callq 0x2270
leaq 0x5d8(%rsp), %rdi
callq 0x6b64
leaq 0x828(%rsp), %rdi
callq 0x6b64
xorl %eax, %eax
addq $0xa78, %rsp            # imm = 0xA78
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq 0x1e0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3ce4
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x3ce4
jmp 0x3ad0
movq %rax, %r15
leaq 0x200(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3cfe
movq 0x200(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x3cfe
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
movq %rax, %r15
leaq 0x220(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3d0b
movq 0x220(%rsp), %rsi
jmp 0x3a9d
jmp 0x3aaa
movq %rax, %r15
leaq 0x240(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3d0b
movq 0x240(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x3d0b
movq %rax, %r15
jmp 0x3d0b
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
jmp 0x3c35
movq %rax, %r15
jmp 0x3ce4
movq %rax, %r15
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x3b5b
movq %rax, %r15
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x3b87
movq %rax, %r15
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x3b47
jmp 0x3c77
movq %rax, %r15
jmp 0x3c9c
jmp 0x3c35
movq %rax, %r15
testb $0x1, 0x10(%rsp)
je 0x3b47
movq 0xc0(%rsp), %rdi
movb $0x1, %al
movq %rax, 0x10(%rsp)
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x3b47
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2200
testb $0x1, 0x10(%rsp)
je 0x3b5b
leaq 0x558(%rsp), %rdi
callq 0x65d2
testb $0x1, 0x10(%rsp)
je 0x3b87
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x3b87
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x2200
testb $0x1, 0x10(%rsp)
jmp 0x3c65
movq %rax, %r15
jmp 0x3bbe
movq %rax, %r15
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0x3bbe
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x160(%rsp), %rdi
leaq 0x170(%rsp), %rax
cmpq %rax, %rdi
je 0x3c40
movq 0x170(%rsp), %rsi
jmp 0x3c27
movq %rax, %r15
jmp 0x3c0a
movq %rax, %r15
movq 0x180(%rsp), %rdi
leaq 0x190(%rsp), %rax
cmpq %rax, %rdi
je 0x3c0a
movq 0x190(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x3c40
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x3c40
jmp 0x3c35
jmp 0x3c35
movq %rax, %r15
jmp 0x3cfe
movq %rax, %r15
movq 0x250(%rsp), %rdi
leaq 0x260(%rsp), %rax
cmpq %rax, %rdi
je 0x3c65
movq 0x260(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x5d8(%rsp), %rdi
callq 0x65d2
jmp 0x3cfe
movq %rax, %r15
jmp 0x3cf1
movq %rax, %r15
movq 0x450(%rsp), %rdi
cmpq %r14, %rdi
je 0x3c9c
movq 0x460(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x250(%rsp), %rdi
callq 0x65d2
jmp 0x3cf1
jmp 0x3cd4
jmp 0x3cd4
jmp 0x3cd4
jmp 0x3cb5
jmp 0x3cb5
movq %rax, %r15
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3cd7
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x3cd7
movq %rax, %r15
leaq 0x250(%rsp), %rdi
callq 0x2290
leaq 0x100(%rsp), %rdi
callq 0x3d52
leaq 0x5d8(%rsp), %rdi
callq 0x6b64
leaq 0x828(%rsp), %rdi
callq 0x6b64
movq %r15, %rdi
callq 0x2330
nop